ID: 48434 Updated by: lbarn...@php.net Reported By: busia at tiscali dot it -Status: Open +Status: Closed Bug Type: *General Issues PHP Version: 5.3.0RC2 New Comment:
PHP uses an array internally to store all objects. When you create more objects, the array is grown. When you destroy some objects, the array is not resized, so that creating other objects is faster. This is the difference you see; ~32 bytes per object. This is not due to the allocator. There is a few other caches of this kind in PHP that make it running faster. Previous Comments: ------------------------------------------------------------------------ [2009-05-31 07:44:54] busia at tiscali dot it The correction create an other problem: look this script: <? ini_set('memory_limit','300M'); class a { } echo memory_get_usage()."\n"; $a=array(); for ($i=0; $i<=1000000; $i++) { $a[]= new a(); } echo memory_get_usage()."\n"; unset($a); echo memory_get_usage()."\n"; $b=10000; echo memory_get_usage()."\n"; ?> Regarding this code in bug #48368 you said me that unset != free. The memory can remain occupied also after I unset an array, that memory is reused when I set a new variable. Now it is is possibile to check $foo dimension but the memory is not reused. The output of the script is: 325792 230042232 33847560 33847640 It seems that the memory between 325792 and 33847560 is lost, it is not reused when I set $foo. ------------------------------------------------------------------------ [2009-05-30 16:44:58] lbarn...@php.net This bug has been fixed in CVS. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. Thank you for the report, and for helping us make PHP better. ------------------------------------------------------------------------ [2009-05-30 14:35:56] busia at tiscali dot it Look this code: ---------------- <? ini_set('memory_limit','300M'); class a { } echo "a - ".(memory_get_usage(true) - memory_get_usage())."\n"; $a=array(); for ($i=0; $i<=1000000; $i++) { $a[]= new a(); } echo "b - ".(memory_get_usage(true) - memory_get_usage())."\n"; unset($a); echo "c - ".(memory_get_usage(true) - memory_get_usage())."\n"; $foo=10000; echo "d - ".(memory_get_usage(true) - memory_get_usage())."\n"; ?> ------------- That show a - 201640 b - 774800 c - 685360 d - 685360 ------------------------ If it is as you said the output near "d" should be different from the output near "c" but they are identical. I want to know how many internal mamory is used from the "$foo" variable. I know the the system memory is the same because php don't make always garbage collection but it collect on the request end bue i want to be able to know how much memory is interested by section of code. Using your code seems that $foo is registered on the void. Thanks ------------------------------------------------------------------------ [2009-05-30 13:29:54] scott...@php.net What aren't you understanding? memory_get_usage(true) = memory allocated to process from system memory_get_usage() = memory actually in use for PHP Therefore memory_get_usage(true) - memory_get_usage() That's the memory that has been allocated from the system but isn't used for variables yet. ------------------------------------------------------------------------ [2009-05-30 13:00:52] busia at tiscali dot it I unsderstand what you say but my request is different: when I posted bug #48368, j...@php.net answered me: ------------------------ unset != free. The memory is freed once the process shuts down. Until that, it's available inside the process. This is not a leak. ------------------------ I need a function that tell me the amount of this memory "available inside the process" or even better the difference between memory_get_usage() and this memory "available inside the process". I don't think this is bogus, i think this must be an "open" feature request. Thanks ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/48434 -- Edit this bug report at http://bugs.php.net/?id=48434&edit=1