note 59272 deleted from language.oop5.decon by levim
| From: | levim@php.net | Date: | Tue, 18 Mar 2014 02:08:01 +0000 |
| Subject: | note 59272 deleted from language.oop5.decon by levim | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-198915@lists.php.net to get a copy of this message | ||
Note Submitter: aya at eh dot org
----
For those who aren't already aware, PHP5 currently suffers from the classic reference counting
leak. See http://en.wikipedia.org/wiki/Reference_counting
for more info.
Example code:
<?php
class Noisy
{
private $name;
public function __construct($name)
{
$this->name = $name;
echo "Noisy::__construct($this->name)\n";
}
public function __destruct()
{
echo "Noisy::__destruct($this->name)\n";
}
}
function foo($num)
{
$noisy = new Noisy($num);
//$noisy->me = $noisy; // Uncomment this line to create a cyclic reference
}
for ($i = 0; $i < 10; ++$i)
foo($i);
?>
As it stands, the destructor of class 'Noisy' will be called on '$noisy' when it
goes out of scope in function 'foo', but uncommenting the second line in function
'foo' will prevent this, and cause a memory leak.
See http://bugs.php.net/bug.php?id=33595 for a
bug report, which reads as if this is not likely to get fixed in the near future, so watch out!