|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 10:00:01 2025 UTC |
//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}";