Bug #74792 [NEW]: Cycles created by AppendIterator not cleaned.
| From: | arjen at parse dot nl | Date: | Wed, 21 Jun 2017 13:22:16 +0000 |
| Subject: | Bug #74792 [NEW]: Cycles created by AppendIterator not cleaned. | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-209618@lists.php.net to get a copy of this message | ||
From: arjen at parse dot nl
Operating system: All
PHP version: 7.1.6
Package: SPL related
Bug Type: Bug
Bug description:Cycles created by AppendIterator not cleaned.
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 bug report at https://bugs.php.net/bug.php?id=74792&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74792&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74792&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74792&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=74792&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=74792&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=74792&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=74792&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=74792&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=74792&r=support
Expected behavior: https://bugs.php.net/fix.php?id=74792&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=74792&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=74792&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=74792&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74792&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=74792&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=74792&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=74792&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=74792&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=74792&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=74792&r=mysqlcfg