From:
Operating system: Linux
PHP version: 5.4.0
Package: *General Issues
Bug Type: Bug
Bug description:Possible memory leak (in array copy?)
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 bug report at https://bugs.php.net/bug.php?id=61395&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=61395&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=61395&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=61395&r=trysnapshottrunk
Fixed in SVN:
https://bugs.php.net/fix.php?id=61395&r=fixed
Fixed in SVN and need be documented:
https://bugs.php.net/fix.php?id=61395&r=needdocs
Fixed in release:
https://bugs.php.net/fix.php?id=61395&r=alreadyfixed
Need backtrace:
https://bugs.php.net/fix.php?id=61395&r=needtrace
Need Reproduce Script:
https://bugs.php.net/fix.php?id=61395&r=needscript
Try newer version:
https://bugs.php.net/fix.php?id=61395&r=oldversion
Not developer issue:
https://bugs.php.net/fix.php?id=61395&r=support
Expected behavior:
https://bugs.php.net/fix.php?id=61395&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=61395&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=61395&r=submittedtwice
register_globals:
https://bugs.php.net/fix.php?id=61395&r=globals
PHP 4 support discontinued:
https://bugs.php.net/fix.php?id=61395&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=61395&r=dst
IIS Stability:
https://bugs.php.net/fix.php?id=61395&r=isapi
Install GNU Sed:
https://bugs.php.net/fix.php?id=61395&r=gnused
Floating point limitations:
https://bugs.php.net/fix.php?id=61395&r=float
No Zend Extensions:
https://bugs.php.net/fix.php?id=61395&r=nozend
MySQL Configuration Error:
https://bugs.php.net/fix.php?id=61395&r=mysqlcfg