|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-03-09 16:01 UTC] treehousetim at gmail dot com
Description:
------------
Empty if that calls a function that returns a value causes php to consume huge amounts of memory (at least under windows)
This was tested using CLI
Reproduce code:
---------------
function testIt()
{
return true;
}
for ( $ix = 0; $ix < 200000; $ix++ )
{
echo "Jere is the Memory King $ix" . NL;
if ( testIt() )
{
}
}
Expected result:
----------------
php's memory usage to remain somewhat stable.
Actual result:
--------------
php's memory usage goes up at the rate of about one meg per second while this script is running.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 23 10:00:01 2025 UTC |
Exists on 5.2.4 on Linux. Reproduce with the following code: $ cat TestMem.php <?php $counter=0; echo "Loop that does something..\n"; for($c=0;$c<1000000;$c++) { if(MyFunc()) { echo "."; } } echo "\nLoop that does nothing..\n"; $counter=0; for($c=0;$c<1000000;$c++) { if(MyFunc()) { } } function MyFunc() { global $counter; if(($counter % 100000) === 0) { echo "$counter:" . memory_get_usage() . "\n"; } $counter++; return(false); } ?> Results: $ php TestMem.php Loop that does something.. 0:58216 100000:58216 200000:58256 300000:58256 400000:58256 500000:58256 600000:58256 700000:58256 800000:58256 900000:58256 Loop that does nothing.. 0:58256 100000:4058244 200000:8058244 300000:12058244 400000:16058244 500000:20058244 600000:24058244 700000:28058244 800000:32058244 900000:36058244 Note that memory leak results are identical if a 'slightly' non-empty loop (ie: if($blah) { 1; } ) is included instead. Leigh.