php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47233 recursive references are not garbage collected
Submitted: 2009-01-28 23:24 UTC Modified: 2009-01-29 00:07 UTC
From: piotr dot banasik at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.3CVS-2009-01-28 (snap) OS: Linux/os-x
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: piotr dot banasik at gmail dot com
New email:
PHP Version: OS:

 

 [2009-01-28 23:24 UTC] piotr dot banasik at gmail dot com
Description:
------------
This appears to be the same issue as the now closed bug #33595

I originally experienced this with php 5.2, after googling around I stumbled upon #33595. It looked like it fixed the issue, so I grabbed first the alpha, and then the snapshot of 5.3, neither of them appear to have the issue fixed.

I'm using the op's original test code and memory usage jumps from 329,956 bytes before, to 1,027,088 after the 1mil iterations. (In my actual way more complex code this is causing ~20k per iteration memory jumps so its very non trivial to me).

Reproduce code:
---------------
<?php
class A {
    function __construct () {
        $this->b = new B($this);
    }
}

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

echo number_format(memory_get_usage()) . "\n";

for ($i = 0 ; $i < 1000000 ; $i++) {
    $a = new A();
}

echo number_format(memory_get_usage()) . "\n";

?>

Expected result:
----------------
the before and after memory usage should not go up by much

Actual result:
--------------
329,956
1,027,088

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-01-29 00:07 UTC] scottmac@php.net
Won't work until script shutdown because of the way the code is written, you overwrite $a which is fine. But the garbage collector isn't called on *every* destructor as that would be slow.

for ($i = 0 ; $i < 1000000 ; $i++) {
    $a = new A();
    unset($a);
    gc_collect_cycles();
}


Works fine though.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Aug 16 04:00:02 2025 UTC