|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53071 Use of SPLObjectStorage Defeats gc_collect_cycles
Submitted: 2010-10-15 01:14 UTC Modified: 2010-10-25 03:42 UTC
From: chris dot crapo at bsci dot com Assigned: cataphract
Status: Closed Package: SPL related
PHP Version: 5.3.3 OS: Windows XP
Private report: No CVE-ID:
 [2010-10-15 01:14 UTC] chris dot crapo at bsci dot com
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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-15 01:33 UTC] chris dot crapo at bsci dot com
//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";
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}";
 [2010-10-25 03:41 UTC]
Automatic comment from SVN on behalf of cataphract
Log: - Fixed bug #53071 (SPLObjectStorage defeats gc_collect_cycles).
 [2010-10-25 03:42 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: cataphract
 [2010-10-25 03:42 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

Fixed for PHP 5.3 and trunk.
 [2010-10-25 04:03 UTC]
Automatic comment from SVN on behalf of cataphract
Log: - Small optimization of the fix of bug #53071. It's not necessary to destroy
  the debug info as it's not holding references anymore (the fix removed
  the refcount increments).
PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Sun Oct 04 03:01:29 2015 UTC