Bug #80125 [Nab]: CallbackFilterIterator is leaking memory

From: Date: Wed, 23 Sep 2020 16:45:14 +0000
Subject: Bug #80125 [Nab]: CallbackFilterIterator is leaking memory
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-229184@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: 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: Then create a closure, and pass it, clone + bindTo on assignment it to the scope which you want: https://3v4l.org/gemWn Previous Comments: ------------------------------------------------------------------------ [2020-09-23 16:27:29] mvorisek at mvorisek dot cz No! The CallbackFilterIterator must be GCable like any other object. I simplified the test script (to use bound function with simple condition), I can not use static and I also mentioned this in the description. This is a clear bug to me. ------------------------------------------------------------------------ [2020-09-23 16:19:36] kalle@php.net You should declare the closure as static and you will get the desired result: https://3v4l.org/QPlkq ------------------------------------------------------------------------ [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

« previous php.bugs (#229184) next »