Req #46654 [Opn->Wfx]: circular reference suggestion

From: Date: Sat, 26 Mar 2016 12:10:13 +0000
Subject: Req #46654 [Opn->Wfx]: circular reference suggestion
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200111@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=46654&edit=1 ID: 46654 Updated by: nikic@php.net Reported by: luka8088 at gmail dot com Summary: circular reference suggestion -Status: Open +Status: Wont fix Type: Feature/Change Request -Package: Feature/Change Request +Package: *General Issues PHP Version: 5.3.0alpha2 Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2008-11-23 15:44:42] 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 ? ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=46654&edit=1

« previous php.bugs (#200111) next »