Bug #74792 [Opn->Ver]: Cycles created by AppendIterator not cleaned.
| From: | nikic@php.net | Date: | Tue, 08 Jun 2021 14:35:44 +0000 |
| Subject: | Bug #74792 [Opn->Ver]: Cycles created by AppendIterator not cleaned. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-234268@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74792&edit=1
ID: 74792
Updated by: nikic@php.net
Reported by: arjen at parse dot nl
Summary: Cycles created by AppendIterator not cleaned.
-Status: Open
+Status: Verified
Type: Bug
Package: SPL related
Operating System: All
PHP Version: 7.1.6
Block user comment: N
Private report: N
New Comment:
Looks like this issue still exists on master.
Previous Comments:
------------------------------------------------------------------------
[2017-06-21 13:22:13] arjen at parse dot nl
Description:
------------
Cycles where an AppendIterator is involved are not collected, I guess the algorithm cannot look
inside the internal iterators.
When only using an ArrayIterator, GC works as expected.
See https://3v4l.org/BCI0F#v700
Test script:
---------------
<?php
class A
{
protected $_iterator;
protected $_appendIterator;
public function __construct($appendIterator = true)
{
$this->_appendIterator = $appendIterator;
$arrayIterator= new ArrayIterator([$this, $this, $this, $this]);
if ($appendIterator)
{
$this->_iterator = new AppendIterator();
$this->_iterator->append($arrayIterator);
}
else
{
$this->_iterator = $arrayIterator;
}
}
public function __destruct()
{
echo 'destructing A::class(' . var_export($this->_appendIterator, true) .')
' . PHP_EOL;
}
}
echo "Running with AppendIterator(): " . PHP_EOL;
$mStart = memory_get_usage();
for ($i = 0; $i < 10; $i++)
new A();
echo memory_get_usage() - $mStart . " memory increase " . PHP_EOL;
echo "Running GC.." . PHP_EOL;
echo "Found " . gc_collect_cycles() . " cycles..." . PHP_EOL . PHP_EOL;
echo "Running without AppendIterator(): " . PHP_EOL;
$mStart = memory_get_usage();
for ($i = 0; $i < 10; $i++)
new A(false);
echo memory_get_usage() - $mStart . " memory increase " . PHP_EOL;
echo "Running GC.." . PHP_EOL;
echo "Found " . gc_collect_cycles() . " cycles..." . PHP_EOL;
echo "Done!" . PHP_EOL . PHP_EOL;
Expected result:
----------------
Cycles also collected when AppendIterator is between A->iterator and ArrayIterator.
Actual result:
--------------
No cycles found
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74792&edit=1