php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #46654 circular reference suggestion
Submitted: 2008-11-23 15:44 UTC Modified: 2016-03-26 12:10 UTC
Votes:2
Avg. Score:3.0 ± 2.0
Reproduced:0 of 1 (0.0%)
From: luka8088 at gmail dot com Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 5.3.0alpha2 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2008-11-23 15:44 UTC] luka8088 at gmail dot com
Description:
------------
I have a suggestion for circular reference problem, already mentioned in report 33595 ... I realize that it is already fix in cvs with David Wang's patch, but maybe this would also be good to have ?


Reproduce code:
---------------
for example:

class foo {
  function __construct () {
    $this->bar = new bar($this);
  }
  
  function __refcount ($count) {
    if ($count <= 1)
      unset($this->bar);
  }
}

class bar {
  function __construct ($foo = null) {
    $this->foo = $foo;
  }
}

$object = new foo();
unset($object);
// $object->__refcount(1); // one reference left

Expected result:
----------------
now, this would create a circular reference when creating foo, and I suggest that when a reference to an object is removed or added, and refcount changes, a __refcount method is called, that way, in some cases when object knows how many circular references it has, can unset them and free the memory... in this example, foo knows that it has exactly 1 reference from bar, and if count is greater then 1, it is still needed...

I know that with this, David Wang's patch may still be needed for objects that don't know the exact refcount, but this may have some good effect on performance ? rather then calculating circular references ?




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-26 12:10 UTC] nikic@php.net
-Status: Open +Status: Wont fix -Package: Feature/Change Request +Package: *General Issues
 [2016-03-26 12:10 UTC] nikic@php.net
As we have a cycle GC nowadays, this is no longer relevant. Checking for cycles this way would be both very slow and very error prone.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 08:01:29 2024 UTC