PHP 4.0 Bug #5620 Updated: Memory leaks with classes and references to objects
| From: | Bug Database | Date: | Sun, 16 Jul 2000 17:10:57 +0000 |
| Subject: | PHP 4.0 Bug #5620 Updated: Memory leaks with classes and references to objects | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-24679@lists.php.net to get a copy of this message | ||
ID: 5620
User Update by: h.raaf@i-k-c.net
Status: Suspended
Bug Type: Scripting Engine problem
Description: Memory leaks with classes and references to objects
Hmm... As stated in my initial text. This was a try to do the "smalles" possible code to
produce the problem.
I need to have one class which generates objects of a second class and keeps a list of them. This
second class objects need to have a reference to modify data in the class which created (first
class) them. And in addition the first class needs to maintain a 'pointer' to different
'active' second class objects. Both classes make heavily use of recursive functions.
There is also a third class whose objects are generated by the second class (and also need a
reference to the creating object). This objects are used by the first class and the second class....
I know that this all sounds a bit strange... I talk about working code (my XLST Processor). But
something going wrong and one thing is this leaking of memory. If the stuff I do is
'forbidden' it would be fine if some error/warning would prevent me to do it.
I made another example code to illustrate the problem
-----------------------------------------------------
<?php
class A {
var $name="A";
var $B=0;
function CreateB() {
$this->B=new B;
$this->B->Aref=&$this;
}
function CallB() {
$this->B->Test();
print("NewNameA: ".$this->name."<br>");
}
}
class B {
var $name="B";
var $Aref=0;
function Test() {
print("NameB: ".$this->name."<br>");
print("NameA: ".$this->Aref->name."<br>");
$this->Aref->name="BA";
}
}
$oa=new A;
$oa->CreateB();
$oa->CallB();
?>
Produces following debug infos:
./zend_execute.c(392) : Freeing 0x084436BC (12 bytes),
script=/var/www/users/test8/www/classleak2.php
Last leak repeated 1 time
zend_hash.c(271) : Freeing 0x08445D54 (40 bytes), script=/var/www/users/test8/www/classleak2.php
Last leak repeated 3 times
zend_hash.c(200) : Freeing 0x094428D4 (20 bytes), script=/var/www/users/test8/www/classleak2.php
Last leak repeated 1 time
./zend_execute.c(1895) : Freeing 0x094419FC (48 bytes),
script=/var/www/users/test8/www/classleak2.php
zend_API.c(208) : Actual location (location was relayed)
Last leak repeated 1 time
zend_compile.c(1554) : Freeing 0x08419CBC (12 bytes),
script=/var/www/users/test8/www/classleak2.php
./zend-scanner.l(1343) : Freeing 0x095EA804 (2 bytes),
script=/var/www/users/test8/www/classleak2.php
--------------------------------
Thanks!
Hans Raaf
Full Bug description available at: http://bugs.php.net/?id=5620