php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74792 Cycles created by AppendIterator not cleaned.
Submitted: 2017-06-21 13:22 UTC Modified: 2021-06-09 09:33 UTC
From: arjen at parse dot nl Assigned: nikic (profile)
Status: Closed Package: SPL related
PHP Version: 7.1.6 OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: arjen at parse dot nl
New email:
PHP Version: OS:

 

 [2017-06-21 13:22 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-06-08 14:35 UTC] nikic@php.net
-Status: Open +Status: Verified
 [2021-06-08 14:35 UTC] nikic@php.net
Looks like this issue still exists on master.
 [2021-06-09 09:33 UTC] nikic@php.net
-Status: Verified +Status: Closed -Assigned To: +Assigned To: nikic
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Dec 01 07:03:34 2021 UTC