|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55228 Objects cannot be collected if they extends some spl classes
Submitted: 2011-07-18 07:31 UTC Modified: 2011-07-22 04:43 UTC
From: cofyc dot jackson at gmail dot com Assigned:
Status: Duplicate Package: SPL related
PHP Version: 5.3.6 OS: Mac OS X
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: cofyc dot jackson at gmail dot com
New email:
PHP Version: OS:


 [2011-07-18 07:31 UTC] cofyc dot jackson at gmail dot com
If objects' classes extends ArrayIterator/ArrayObject, and recursively refer to 
each other, they will not be garbage collected.

I tried reproduction code in, modified A to 
extend ArrayIterator, B to extend ArrayObject.

And is there a way to work around it currently?

Test script:
class A extends ArrayIterator {
    function __construct () {
        $this->b = new B($this);

class B extends ArrayObject {
    function __construct ($parent = NULL) {
        $this->parent = $parent;

for ($i = 0 ; $i < 1000000 ; $i++) {
    $a = new A();
    printf("gc: %d, %f\n", gc_collect_cycles(), memory_get_usage()/1024/1024);


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-22 04:43 UTC]
-Status: Open +Status: Duplicate
 [2011-07-22 04:43 UTC]
Duplicate of bug #53803.
 [2012-04-23 04:42 UTC] cofyc dot jackson at gmail dot com
Can you fix ArrayObject/ArrayIterator classes like SPLObjectStorage in 
bug #53071?

We use these two classes in production.

This gc bug troubles us very much.

Thanks in advance.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Thu Mar 23 06:03:38 2023 UTC