Bug #80125 [Opn->Nab]: CallbackFilterIterator is leaking memory
| From: | kalle@php.net | Date: | Wed, 23 Sep 2020 16:19:36 +0000 |
| Subject: | Bug #80125 [Opn->Nab]: CallbackFilterIterator is leaking memory | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-229182@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80125&edit=1
ID: 80125
Updated by: kalle@php.net
Reported by: mvorisek at mvorisek dot cz
Summary: CallbackFilterIterator is leaking memory
-Status: Open
+Status: Not a bug
Type: Bug
Package: Scripting Engine problem
Operating System: linux
PHP Version: 7.4.10
Block user comment: N
Private report: N
New Comment:
You should declare the closure as
static and you will get the desired result:
https://3v4l.org/QPlkq
Previous Comments:
------------------------------------------------------------------------
[2020-09-20 13:12:33] mvorisek at mvorisek dot cz
Description:
------------
see test script, explicit GC does not help
the issues seems present when the given callback to CallbackFilterIterator is bound (eg. not static)
https://3v4l.org/UpmHK
Test script:
---------------
class IteratorWithFilter
{
public $generator;
public function __construct(array $data)
{
$this->generator = new \ArrayIterator($data);
}
public function filter()
{
$this->generator = new \CallbackFilterIterator($this->generator, function ($row) {
return true;
});
return $this;
}
}
function createIterator() {
$iter = new IteratorWithFilter([['a'], ['b']]);
return $iter->filter();
}
for ($i = 0; $i < 50 * 1000; $i++) {
createIterator();
if (($i % 1000) === 0) {
// gc_collect_cycles(); // explicit GC does not help...
echo round(memory_get_usage() / (1024 * 1024), 3) . " MiB\n";
}
}
Expected result:
----------------
reported memory usage should stay below 1 MiB
Actual result:
--------------
0.375 MiB
1.719 MiB
3.071 MiB
4.36 MiB
5.774 MiB
7.064 MiB
8.353 MiB
9.892 MiB
...
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80125&edit=1