|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2000-07-15 14:04 UTC] h dot raaf at i-k-c dot net
While working on my current project I run into
the following memory leak problem:
class A {
var $Bref=0;
function CreateB() {
$ob=new B;
$this->Bref=&$ob;
$this->Bref->Aref=&$this;
}
}
class B {
var $Aref=0;
}
$oa=new A;
$oa->CreateB();
--- Results in:
./zend_execute.c(392) : Freeing 0x085D570C (12 bytes), script=/var/www/users/test8/www/classleak.php
Last leak repeated 1 time
zend_hash.c(271) : Freeing 0x085422A4 (40 bytes), script=/var/www/users/test8/www/classleak.php
Last leak repeated 1 time
zend_hash.c(200) : Freeing 0x088E6614 (20 bytes), script=/var/www/users/test8/www/classleak.php
Last leak repeated 1 time
./zend_execute.c(1895) : Freeing 0x085478E4 (48 bytes), script=/var/www/users/test8/www/classleak.php
zend_API.c(208) : Actual location (location was relayed)
Last leak repeated 1 time
------
My real project code (a HRXSLT) generates
many, many more of this leaks...
I just tried to make the shortest program
which illustrates the problem.
Greetings,
Hans Raaf
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 12:00:01 2025 UTC |
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 RaafI made another example of what I think is a problem: <?php class A { var $Bref=0; } class B { var $Aref=0; } $oa=new A; $ob=new B; $oa->Bref=&$ob; $ob->Aref=&$oa; ?> ./zend_execute.c(392) : Freeing 0x093D0C04 (12 bytes), script=/var/www/users/test8/www/classleak3a.php Last leak repeated 1 time zend_hash.c(271) : Freeing 0x093D10D4 (40 bytes), script=/var/www/users/test8/www/classleak3a.php Last leak repeated 1 time zend_hash.c(200) : Freeing 0x0970C79C (20 bytes), script=/var/www/users/test8/www/classleak3a.php Last leak repeated 1 time ./zend_execute.c(1895) : Freeing 0x097135E4 (48 bytes), script=/var/www/users/test8/www/classleak3a.php zend_API.c(208) : Actual location (location was relayed) Last leak repeated 1 timeSorry, maybe I am just stupid... :( I really don't want to bother you... please excuse me! I just don't understand where the 'circular reference' is in respect to my last example code and why the code works even if it uses something that is not supported by php4: class A { var $Bref=0; } class B { var $Aref=0; } $oa=new A; $ob=new B; $oa->Bref=&$ob; $ob->Aref=&$oa; Would you be please so kind and explain it to me (or give me some reference to look it up by myself)