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

 ID:                 53071
 Updated by:         cataphr...@php.net
 Reported by:        chris dot crapo at bsci dot com
 Summary:            Use of SPLObjectStorage Defeats gc_collect_cycles
 Status:             Closed
 Type:               Bug
 Package:            SPL related
 Operating System:   Windows XP
 PHP Version:        5.3.3
 Assigned To:        cataphract
 Block user comment: N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2010-10-25 03:41:57] cataphr...@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-15 01:33:10] 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-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

Reply via email to