ID: 48434 Updated by: scott...@php.net Reported By: busia at tiscali dot it Status: Bogus Bug Type: Feature/Change Request PHP Version: 5.3.0RC2 New Comment:
memory_get_usage(true) is the memory allocated from the system. memory_get_usage() is the memory currently in use by PHP. <?php var_dump(memory_get_usage(), memory_get_usage(true)); $x = str_repeat('a', 4096); var_dump(memory_get_usage(), memory_get_usage(true)); unset($x); var_dump(memory_get_usage(), memory_get_usage(true)); Produces int(332392) <-- Initial int(524288) <-- system int(336996) <-- After variable set int(524288) <-- system int(332916) <-- After variable unset int(524288) <-- system Previous Comments: ------------------------------------------------------------------------ [2009-05-30 10:08:12] busia at tiscali dot it I know memory_get_usage() and memory_get_usage(true). But they don't resolve the problem because the memory is not freed always when I unset a variable than memory_get_usage can return the same before and after creating a variable. See #48368. You said me that internal php memory is different from system allocated memory, and I want to access internal php memory. Memory_get_usage (with or without the first parameter) allow only to access to syem allocated memory. Please reply ------------------------------------------------------------------------ [2009-05-30 10:01:50] scott...@php.net Sorry, but your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions. Due to the volume of reports we can not explain in detail here why your report is not a bug. The support channels will be able to provide an explanation for you. Thank you for your interest in PHP. It's already there. memory_get_usage() and memory_get_usage(true) ------------------------------------------------------------------------ [2009-05-30 09:33:08] busia at tiscali dot it Description: ------------ You said me (#48368) that unset != free. The memory can remain occupied also after I unset an array, that memory is reused when I set a new variable and, for this reason, it's not a leak. Ok, now it's clear but a problem remains: how can I optimize my code when I cannot see the php internal memory use? I need a function like: memory_get_usage() - memory_allocated_but_usable_for_newly_created_variables(); Setting a variable and seeing that memory use don't change make scripts impossible to optimize. Thanks ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=48434&edit=1