|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-03-28 17:02 UTC] roland at inkoeln dot com
I found a serious memory leaks which occures when passing
objects. I have included two small code snipplets which
will reproduce the leak:
Code Snipplet-1:
memory leak when passing $this object.
<?php
class Tok {
var $_filter = array();
function filter($name, &$obj) {
$this->_filter[$name] =& $obj;
}
}
class A {
var $_tok;
function A() {
$this->_tok = new Tok();
$this->_tok->filter('xyz', $this); // memory leak
}
}
$a = new A();
?>
Leak message in error.log:
zend_hash.c(260) : Freeing 0x08210544 (39 bytes),
script=/home/share/server/test/index2.php
Last leak repeated 2 times
zend_hash.c(176) : Freeing 0x082104F4 (32 bytes),
script=/home/share/server/test/index2.php
Last leak repeated 2 times
./zend_execute.c(753) : Freeing 0x08210494 (44 bytes),
script=/home/share/server/test/index2.php
zend_variables.c(117) : Actual location (location was
relayed)
Last leak repeated 1 time
zend_API.c(593) : Freeing 0x0821019C (44 bytes),
script=/home/share/server/test/index2.php
zend_API.c(581) : Actual location (location was relayed)
Last leak repeated 1 time
./zend_execute.c(1940) : Freeing 0x0820E714 (12 bytes),
script=/home/share/server/test/index2.php
Last leak repeated 1 time
Here an another example (i think related):
Code-Snipplet-2:
<?php
class A {
var $_parent;
function setParent(&$obj) {
$this->_parent =& $obj;
}
function setParentCopy($obj) {
$this->_parent = $obj;
}
}
$a1 = new A();
$a2 = new A();
$a1->setParent($a2); // works
$a1->setParent($a1); // memory leak
$a1->setParentCopy($a1); // memory leak too
echo "done";
?>
Leak message in error.log:
zend_hash.c(260) : Freeing 0x085698BC (43 bytes),
script=/home/share/server/test/index.php
zend_hash.c(176) : Freeing 0x0856986C (32 bytes),
script=/home/share/server/test/index.php
./zend_execute.c(425) : Freeing 0x0856980C (44 bytes),
script=/home/share/server/test/index.php
zend_variables.c(126) : Actual location (location was
relayed)
./zend_execute.c(1940) : Freeing 0x08368BCC (12 bytes),
script=/home/share/server/test/index.php
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 22 07:00:01 2025 UTC |
OS SunOS 5.7 / Netscape Enterprise 3.2 / PHP 4.1.2 Script below causes memory leak, it seems to be the same problem... (circular reference ...) class aclass{ var $child; function aclass(){ this->increaseMemoryUse = array( "ABCEDFGHIJKLMNOPQRSTUVWXYZ"); } function setChild(){ $this->child = new achild(); // without the line below, there is no memory leak !!! $this->child->father = $this; } } class achild{ var $father; function achild(){ $this->increaseMemoryUse=array("ABCEDFGHIJKLMNOPQRSTUVWXYZ"); } } function create(){ $aNewclass = new aclass; $aNewclass->setChild(); return $aNewclass; } for($i=0 ; $i <= 5000 ; $i++){ $myClass = create(); if (!($i % 1000)){ echo "TEST : $i mem=" . exec ('ps -o vsz -p ' . getmypid() ) . '<br>'; } } ?> ------------- test output : TEST : 0 mem=10672 TEST : 1000 mem=11888 TEST : 2000 mem=13128 TEST : 3000 mem=14360 TEST : 4000 mem=15600 TEST : 5000 mem=16840