|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-02-04 14:35 UTC] jparneodo at yahoo dot fr
/*
If you don't set the UP property,
garbage collection is done in real time
If you set the UP property,
garbage collection is done on script shutdown only
and the VmSize increase.
This is a test case
but if a sub-object (in some package) creates a
circular reference with a sub-sub-object you leak
memory without the knowledge of it.
*/
for($i=1;$i<=$nb_loop;$i++){
echo "<br>loop $i";
flush();
for($j=1;$j<=$nb_by_loop;$j++){
$a=&new A(500);
$a->b=&new B(500);
$a->b->UP=&$a; // Memory Leak here
// unset($a->b->up);
}
sleep($sleep_by_loop);
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 16:00:01 2025 UTC |
I had this problem with PHP4.3.3. I then found this bug report and upgraded to PHP5.0.0b4 to try and fix this problem and I still get the memory leak problem, there is some demo code below, you need to change /path/to/large/file. I've been using a file which is about 1.5mb and when PHP is set to stop when it reaches 8mb then it only makes it through the loop twice. I'm 1.5 years into a project and I could really do with knowing if this is going to be fixed anytime soon so I can either wait for the fix or try and find a work around. Thanks for your time, Tom --- <?php class C { var $ref; var $val; function C() { $this->val = file('/path/to/large/file'); } } while (1) { $x = new C; $y = new C; $x->ref =& $y; $y->ref =& $x; unset($y); unset($x); echo "."; } ?>Is anyone looking into this? I've found any method of releasing the objects fails, no just using the unset() function, if the object just go out of scope they aren't released, for ezample, if you do something like function MyFunc() { $x = new C; $y = new C; $x->ref =& $y; $y->ref =& $x; } Then after the function has finished then the memory allocated for the local variables $x and $y is not freed up.I have experienced this problem on PHP5 as well... here's a test script: echo memory_get_usage() . " (initial)\n"; $t = new test; echo memory_get_usage() . " (after: \$t = new test();)\n"; unset($t); echo memory_get_usage() . " (after: unset(\$t);)\n"; echo "done\n"; class test { protected $str; protected $t2; function __construct() { print "construct test\n"; $this->str = str_repeat('1234567890', 1000); $this->t2 = new test2($this); } function __destruct() { print "destruct test\n"; } } class test2 { protected $str; protected $t1; function __construct($t1) { print "construct test2\n"; $this->str = str_repeat('1234567890', 1000); $this->t1 = $t1; } function __destruct() { print "destruct test2\n"; unset($this->str); } } And the output of this script: 51416 (initial) construct test construct test2 72000 (after: $t = new test();) 72000 (after: unset($t);) done destruct test destruct test2 It's definitely a real problem. Simply removing the cross- referenced instance vars will remove the problem. However, as you can see, even explicitly calling unset() still doesn't release the objects or call destructors until the script EXITS. This is a *MAJOR* problem for anyone using OO to process large amounts of information.