Bug #53071 [Com]: Use of SPLObjectStorage Defeats gc_collect_cycles

From: Date: Thu, 14 Oct 2010 23:33:10 +0000
Subject: Bug #53071 [Com]: Use of SPLObjectStorage Defeats gc_collect_cycles
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-155191@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=53071&edit=1

 ID:                 53071
 Comment by:         chris dot crapo at bsci dot com
 Reported by:        chris dot crapo at bsci dot com
 Summary:            Use of SPLObjectStorage Defeats gc_collect_cycles
 Status:             Open
 Type:               Bug
 Package:            SPL related
 Operating System:   Windows XP
 PHP Version:        5.3.3
 Block user comment: N

 New Comment:

//Cycle example:
class myClass
{
	public $member;
}
function LimitedScope()
{
	$myA = new myClass();
	$myB = new SplObjectStorage();
	$myC = new myClass();
	$myC->member = $myA; // myC has a referece to myA
	$myB->Attach($myC);  // myB attaches myC
	$myA->member = $myB; // myA has myB, comleting the cycle
}
echo "Memory used:   ".$mem = memory_get_usage()."\n";
echo "Function Call\n";
LimitedScope();
echo "Memory used:   ".memory_get_usage()."\n";
echo "Cycles culled: ".gc_collect_cycles()."       should be 1\n";
echo "Memory used:   ".memory_get_usage()."  should be {$mem}";


Previous Comments:
------------------------------------------------------------------------
[2010-10-15 01:14:53] chris dot crapo at bsci dot com

Description:
------------
Using SPLObjectStorage objects in a cycle will defeat gc_collect_cycles
ability to detect that cycle.

So, if I have an object ParentObject which has an SPLObjectStorage which
attaches a ChildObject that has a reference back to ParentObject, the
garbage collector will never actually collect ParentObject.



Expected result:
----------------
After calling gc_collect_cycles() old objects that no longer have
references should be collected

Actual result:
--------------
Cycles that have SPLObjectStorage in them are not collected


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=53071&edit=1


Thread (4 messages)

« previous php.bugs (#155191) next »