php.net |  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
 [2011-07-18 07:31 UTC] cofyc dot jackson at gmail dot com
Description:
------------
If objects' classes extends ArrayIterator/ArrayObject, and recursively refer to 
each other, they will not be garbage collected.

I tried reproduction code in https://bugs.php.net/bug.php?id=33595, modified A to 
extend ArrayIterator, B to extend ArrayObject.

And is there a way to work around it currently?

Test script:
---------------
<?php
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);
}



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-22 04:43 UTC] cataphract@php.net
-Status: Open +Status: Duplicate
 [2011-07-22 04:43 UTC] cataphract@php.net
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-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC