From: Operating system: FreeBSD PHP version: 5.3.5 Package: SPL related Bug Type: Bug Bug description:circular reference between SPL classes not collected by gc_collect_cycles()
Description: ------------ Circular references between instances of SPL classes are not "cleaned up" by gc_collect_cycles(). The code in the test script can be run from cli. It shows growing memory usage because the circular references between the instances of an extended ArrayObject class and instances of ArrayIterator are not cleaned up by gc_collect_cycles. The long code sample, downloadable from the url provided in "test script section" shows: Case1: SPL classes: expecting gc_collect_cycles to clean up circ references Case2: SPL classes: manual clearing of the circular reference Case3: Userland classes: expecting gc_collect_cycles to clean up circ references This looks similar to http://bugs.php.net/53071 , BUT I am running php5.3.5 which AFAIK includes r304723 and r304724 which were supposed to fix #53071. Test script: --------------- Short code sample: class Collection extends ArrayObject implements Serializable { protected $iterator; public function getIterator() { $this->iterator = new ArrayIterator($this); return $this->iterator; } public function clearIterator() { $this->iterator = null; } } echo "Case 1: ArrayObject/ArrayIterator: expecting gc_collect_cycles() to clean up...\n"; for ($i = 1; $i <= 100; $i++) { $books = array('war and peace', 'crime and punishment'); $book_collection = new Collection($books); $iterator = $book_collection->getIterator(); echo gc_collect_cycles() . ":" . memory_get_peak_usage() . "\n"; } full code sample: http://www.realtsp.com/download/php_circular_reference_test_code_sample.txt Expected result: ---------------- Expect all test cases (Case1, Case2, Case3) to have constant peak memory usage. Actual result: -------------- Only Case2 and Case3 have constant memory usage. In Case1 memory usage grows linearly with loops iterations. This shows that gc_collect_cycles is not collecting circular references between SPL classes. Also shown because it returns "0 cycles collected". In Case 3 (Userland classes) gc_collect_cycles shows "5 cycles collected" each iteration. -- Edit bug report at http://bugs.php.net/bug.php?id=53803&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=53803&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=53803&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=53803&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=53803&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=53803&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=53803&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=53803&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=53803&r=needscript Try newer version: http://bugs.php.net/fix.php?id=53803&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=53803&r=support Expected behavior: http://bugs.php.net/fix.php?id=53803&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=53803&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=53803&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=53803&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53803&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=53803&r=dst IIS Stability: http://bugs.php.net/fix.php?id=53803&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=53803&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=53803&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=53803&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=53803&r=mysqlcfg
