php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42758 memory leak in class method calls
Submitted: 2007-09-25 14:09 UTC Modified: 2007-10-04 14:32 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: benoit dot heinrich at swisscom dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 4.4.7 OS: linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: benoit dot heinrich at swisscom dot com
New email:
PHP Version: OS:

 

 [2007-09-25 14:09 UTC] benoit dot heinrich at swisscom dot com
Description:
------------
Hi,

There is a memory leak when calling a method of a class.
I know the bug is fixed in PHP5 but for business reasons we can't afford to upgrade to php5 right now.

Is that possible to fix this very annoying issue?


/Benoit

Reproduce code:
---------------
<?php

class ClassA
{
	var $member;
	
	function setMember($value)
	{
		$this->member = $value;
	}
}

$obj =& new ClassA();
$mem = memory_get_usage();
for ($i=0; $i< 1000000; $i++)
	$obj->member = null;

print "Direct property set memory leak is " . number_format(memory_get_usage()-$mem) . "\n";

$mem = memory_get_usage();
for ($i=0; $i< 1000000; $i++)
	$obj->setMember(null);
	
print "Method call memory leak is " . number_format(memory_get_usage()-$mem) . "\n";

?>

Expected result:
----------------
Direct property set memory leak is 0
Method call memory leak is 0


Actual result:
--------------
Direct property set memory leak is 128
Method call memory leak is 8,000,040


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-09-26 09:18 UTC] benoit dot heinrich at swisscom dot com
Hi again,

I made some research to try to find out what is the exact reason of the memory leak.

So I first try to replace the set method by a very simple method that does nothing:

class ClassA
{
	function method()
	{
	}
}


Then I tried to remove the 'for' loop and I created a test case with 10000 call to $obj->method(); and again I got the memory leak.

So my 2 cents that is a bug in the PHP engine call stack where it keeps a pointer somewhere to the object that is calling the method.


Hope it helps.
/Benoit
 [2007-10-04 14:32 UTC] benoit dot heinrich at swisscom dot com
Sorry,

This was not a bug of PHP but a bug of the APD extension.
By disabling the APD extension the bug disappeared.


Cheers,
/Benoit
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Sep 21 00:01:27 2024 UTC