Bug #81215 [Fbk->Opn]: Possible memory leak with closure nested \array_filter()
| From: | berliozdavid at gmail dot com | Date: | Thu, 01 Jul 2021 13:01:35 +0000 |
| Subject: | Bug #81215 [Fbk->Opn]: Possible memory leak with closure nested \array_filter() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-234730@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81215&edit=1
ID: 81215
User updated by: berliozdavid at gmail dot com
Reported by: berliozdavid at gmail dot com
Summary: Possible memory leak with closure nested
\array_filter()
-Status: Feedback
+Status: Open
Type: Bug
Package: Performance problem
Operating System: Fedora/Linux
PHP Version: 8.0.8
Block user comment: N
Private report: N
New Comment:
[PHP Modules]
apcu
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
igbinary
imagick
inotify
intl
json
libxml
mbstring
memcached
mongodb
msgpack
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
redis
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
ssh2
standard
swoole
sysvmsg
sysvsem
sysvshm
tokenizer
xhprof
xml
xmlreader
xmlwriter
xsl
Zend OPcache
zip
zlib
[Zend Modules]
Zend OPcache
Previous Comments:
------------------------------------------------------------------------
[2021-07-01 12:55:47] nikic@php.net
I can't reproduce this, memory usage is stable for me. Tested with and without opcache.
Do you have any interesting extensions like xdebug loaded?
------------------------------------------------------------------------
[2021-07-01 12:42:50] berliozdavid at gmail dot com
Using static closure leads to memory leak too:
$f = static function ($array) {
return \array_filter($array, fn($item) => !is_null($item));
};
------------------------------------------------------------------------
[2021-07-01 12:37:33] berliozdavid at gmail dot com
Description:
------------
With PHP80 using \array_filter() in a closure can lead to memory leak.
PHP74 is not affected.
Test script:
---------------
<?php
namespace Somewhere\On\Earth;
class Foo {
function leaking(array $array) {
$f = function ($array) {
return \array_filter($array, fn($item) => !is_null($item));
};
for (;;) {
$clone = (array) $array;
$res = $f($clone);
printf("memory: %d\n", \memory_get_usage());
unset($clone, $res);
}
}
function run() {
$array = array_combine(range(1, 1000, 2), array_fill(1, 500, null));
$array += array_combine(range(2, 1000, 2), array_fill(1, 500, true));
$this->leaking($array);
}
}
(new Foo())->run();
Expected result:
----------------
stable memory value.
Actual result:
--------------
increasing memory value.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81215&edit=1