|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 24 00:00:01 2025 UTC |
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