php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36672 Function Call in IF ( ) with empty code block causes memory leak
Submitted: 2006-03-09 16:01 UTC Modified: 2006-03-17 01:00 UTC
Votes:3
Avg. Score:3.7 ± 0.9
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:1 (33.3%)
From: treehousetim at gmail dot com Assigned:
Status: No Feedback Package: Scripting Engine problem
PHP Version: 5.1.2 OS: Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: treehousetim at gmail dot com
New email:
PHP Version: OS:

 

 [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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-09 20:44 UTC] mike@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.1-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.1-win32-latest.zip

Not reproducible on Linux.

 [2006-03-17 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2009-09-28 06:57 UTC] intersect at gmail dot com
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.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 06 11:02:27 2025 UTC