php.net |  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 (profile)
Status: Closed Package: SPL related
PHP Version: 5.3.3 OS: Windows XP
Private report: No CVE-ID: None
 [2010-10-15 01:14 UTC] 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

Patches

Pull Requests

History

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";
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}";
 [2010-10-25 03:41 UTC] cataphract@php.net
Automatic comment from SVN on behalf of cataphract
Revision: http://svn.php.net/viewvc/?view=revision&revision=304723
Log: - Fixed bug #53071 (SPLObjectStorage defeats gc_collect_cycles).
 [2010-10-25 03:42 UTC] cataphract@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cataphract
 [2010-10-25 03:42 UTC] cataphract@php.net
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
http://snaps.php.net/.
 
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] cataphract@php.net
Automatic comment from SVN on behalf of cataphract
Revision: http://svn.php.net/viewvc/?view=revision&revision=304724
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-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 08:01:29 2024 UTC