Can somebody clarify what's the exact difference of the $real_usage
parameter for memory_get_usage()
?
The manual states:
Set this to TRUE to get the real size of memory allocated from system. If not set or FALSE only the memory used by emalloc() is reported.
But what's the difference?
Which value is comparable to the memory_limit
INI setting?
For some long running scripts I get something like 250MB real usage and just 50MB emalloc usage. How is that possible?
I'm trying to analyze some memory leak problems and memory_get_usage()
is an important indicator for me that I need to fully understand. Thanks.
The real memory is the amount of memory that's reserved for the PHP process. PHP reserves memory in large chunks, and this will be <= memory_limit, and may increase during the script's execution. Eg. If it fills up a chunk, and you then try to assign to a new variable, it will reserve another chunk.
If you set the parameter to FALSE, it only reports the amount of memory that PHP is actually using inside the reserved memory. This will increase every time you assign to a new variable, or call a function etc.
If you're interested in the amount of memory that is actually being used, then you'll want the real memory.
If you're debugging, or trying to tune a piece of code, you'll probably be more interested in the emalloc() memory. This would allow you to check the memory before and after an assignment or function call and calculate the delta.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With