Bug #61395 [Csd->Nab]: Possible memory leak (in array copy?)
| From: | rasmus@php.net | Date: | Thu, 15 Mar 2012 05:15:53 +0000 |
| Subject: | Bug #61395 [Csd->Nab]: Possible memory leak (in array copy?) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-168483@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=61395&edit=1
ID: 61395
Updated by: rasmus@php.net
Reported by: stormbyte at gmail dot com
Summary: Possible memory leak (in array copy?)
-Status: Closed
+Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: Linux
PHP Version: 5.4.0
Block user comment: N
Private report: N
New Comment:
Compare it to PHP 5.3.x
memory_get_usage() in 5.2.x had a number of accuracy problems. If you compare
actual memory usage using htop/top you will see it is less for 5.4.
Previous Comments:
------------------------------------------------------------------------
[2012-03-15 04:46:07] stormbyte at gmail dot com
Forgot to unset($i) and thus the false memory leak. But why 5.4.0 still uses more memory is still a
mistery. Sorry.
------------------------------------------------------------------------
[2012-03-15 04:45:02] stormbyte at gmail dot com
Forgot to unset($i) a variable and thus the false memory leak. Sorry
------------------------------------------------------------------------
[2012-03-15 04:43:04] stormbyte at gmail dot com
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?)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=61395&edit=1