Bug #76982 [Com]: memory leak declaring closure in included file
Edit report at https://bugs.php.net/bug.php?id=76982&edit=1
ID: 76982
Comment by: goetas at gmail dot com
Reported by: ryan dot brothers at gmail dot com
Summary: memory leak declaring closure in included file
Status: Verified
Type: Bug
Package: Scripting Engine problem
Operating System: Linux
PHP Version: 7.2.10
Block user comment: N
Private report: N
New Comment:
This bug is pretty serious when integrating the symfony dependency injection container in reactphp,
phppm or swoole applications.
This https://travis-ci.org/goetas/symfony-mem-leak/builds/551710669
shows the leak in the default configuration of the symfony dependency injection
Previous Comments:
------------------------------------------------------------------------
[2019-06-27 20:23:36] goetas at gmail dot com
I manage to reproduce consistently the issue on all PHP 7.x versions
https://github.com/goetas/symfony-mem-leak
contains the repo to reproduce the issue
https://travis-ci.org/goetas/symfony-mem-leak/builds/551488795
is one build that shows the issue on Travis
Discovered while trying to solve https://github.com/symfony/symfony/issues/32220
------------------------------------------------------------------------
[2019-05-27 21:28:19] tyler dot bannister at remote-learner dot net
I'm seeing the same problem even when I don't use a closure and instead just assign a
variable. I also saw the same problem, but to a lesser extent, with a print command. I filed a
report for that in Bug #78076, but it seems like there may be a common problem related to repeated
requires/includes?
------------------------------------------------------------------------
[2018-10-09 13:21:19] ryan dot brothers at gmail dot com
Thanks for confirming. If it helps, the same problem also happens if you put "return;" as
the first line of file2.php like the below, so it seems related to compiling perhaps, rather than
executing.
file2.php:
<?php
return;
$test_function = function()
{
};
------------------------------------------------------------------------
[2018-10-09 12:07:45] cmb@php.net
This also happens on current master. It works fine if file2.php
is inlined. Neither a debug build nor valgrind
(ZEND_DONT_UNLOAD_MODULES=1 USE_ZEND_ALLOC=0) report a memory
leak, though.
------------------------------------------------------------------------
[2018-10-08 02:40:59] ryan dot brothers at gmail dot com
Description:
------------
I am running PHP 7.2.10 on CentOS 7. If I run the below script file1.php, the memory usage
gradually increases until it hits the memory limit. The memory usage should remain relatively
constant. It's related to declaring the closure in file2.php, as if I remove the closure, then
the memory usage stays constant.
Also, the memory usage stays constant in PHP 5.6, so the issue is perhaps only in PHP 7 and later.
Test script:
---------------
file1.php
<?php
for ($i = 0; $i < 1000000; $i++)
{
echo $i.' - '.number_format(memory_get_usage())."\n";
require('file2.php');
}
file2.php:
<?php
$test_function = function()
{
};
Expected result:
----------------
Memory usage stays constant.
Actual result:
--------------
Memory usage increases until it hits the memory limit.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76982&edit=1
Thread (10 messages)