|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2012-03-15 04:45 UTC] stormbyte at gmail dot com
-Status: Open
+Status: Closed
[2012-03-15 04:45 UTC] stormbyte at gmail dot com
[2012-03-15 04:46 UTC] stormbyte at gmail dot com
[2012-03-15 05:15 UTC] rasmus@php.net
[2012-03-15 05:15 UTC] rasmus@php.net
-Status: Closed
+Status: Not a bug
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 08:00:01 2025 UTC |
Description: ------------ I did found on the internet some code to have test and measure memory usage. After tweaking it a bit, I discovered that when finishes (and unsetting all vars), PHP does not go back to initial memory usage which seems a memory leak. This is the output the test script produces: Note that memory usave in Stage 1, should be equal to memory usage in Stage 8 theoretically. Test script: --------------- <?php echo "Stage 1: Mem usage is: ", memory_get_usage(), "\n"; $arr = array(); for ($i = 0; $i < 100000; ++$i) { $arr[] = rand(); } echo "Stage 2: Mem usage is: ", memory_get_usage(), "\n"; $foo = 1; $bar = 2; echo "Stage 3: Mem usage is: ", memory_get_usage(), "\n"; $foo = $arr; $bar = $arr; echo "Stage 4: Mem usage is: ", memory_get_usage(), "\n"; $arr = array(); echo "Stage 5: Mem usage is: ", memory_get_usage(), "\n"; $bar[] = "hello, world"; echo "Stage 6: Mem usage is: ", memory_get_usage(), "\n"; $foo = array(); echo "Stage 7: Mem usage is: ", memory_get_usage(), "\n"; unset($arr); unset($foo); unset($bar); flush(); echo "Stage 8: Mem usage is: ", memory_get_usage(), "\n"; ?> Expected result: ---------------- Expected output: PHP 5.4.0: Stage 1: Mem usage is: 234104 Stage 2: Mem usage is: 14883160 Stage 3: Mem usage is: 14883432 Stage 4: Mem usage is: 14883336 Stage 5: Mem usage is: 14883472 Stage 6: Mem usage is: 24732360 Stage 7: Mem usage is: 14883736 Stage 8: Mem usage is: 234104 Actual result: -------------- PHP 5.4.0: Stage 1: Mem usage is: 234104 Stage 2: Mem usage is: 14883160 Stage 3: Mem usage is: 14883432 Stage 4: Mem usage is: 14883336 Stage 5: Mem usage is: 14883472 Stage 6: Mem usage is: 24732360 Stage 7: Mem usage is: 14883736 Stage 8: Mem usage is: 234240 PHP 5.2.7: Stage 1: Mem usage is: 95520 Stage 2: Mem usage is: 13945080 Stage 3: Mem usage is: 13945352 Stage 4: Mem usage is: 13945272 Stage 5: Mem usage is: 13945480 Stage 6: Mem usage is: 23794376 Stage 7: Mem usage is: 13945680 Stage 8: Mem usage is: 95656 (Much more memory used in 5.4.0?)