Bug #80140 [Dup]: Including a file multiple times with anonymous class is leaking memory
| From: | nikic@php.net | Date: | Tue, 22 Sep 2020 21:27:39 +0000 |
| Subject: | Bug #80140 [Dup]: Including a file multiple times with anonymous class is leaking memory | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-229156@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80140&edit=1
ID: 80140
Updated by: nikic@php.net
Reported by: mvorisek at mvorisek dot cz
Summary: Including a file multiple times with anonymous class
is leaking memory
Status: Duplicate
Type: Bug
Package: Scripting Engine problem
Operating System: any
PHP Version: 7.4.10
Block user comment: N
Private report: N
New Comment:
Duplicate of bug #76982. Also last comment on bug #79519.
Previous Comments:
------------------------------------------------------------------------
[2020-09-22 21:24:17] mvorisek at mvorisek dot cz
Even function declaration included multiple times is leaking memory:
```
return;
function xxx() {}
```
https://3v4l.org/NOejV
------------------------------------------------------------------------
[2020-09-22 21:07:34] mvorisek at mvorisek dot cz
Description:
------------
see https://3v4l.org/nUFqX
including file multiple times is very common usecase and memory should not increase
the issue is present when the included file contains an anonymous class, but the class should be not
recreated again and again
Test script:
---------------
if (isset($fromRequire)) {
// return; // leaking even if code below is never executed
$class = new class() extends \stdClass {};
return;
}
for ($i = 0; $i < 10 * 1000; $i++) {
$fromRequire = true;
require __FILE__;
if (($i % (1000)) === 0) {
gc_collect_cycles();
echo round(memory_get_usage() / (1024 * 1024), 3) . " MiB\n";
}
}
Expected result:
----------------
reported memory usage should stay below 1 MiB
Actual result:
--------------
0.37 MiB
1.152 MiB
1.973 MiB
2.872 MiB
3.614 MiB
4.67 MiB
5.412 MiB
6.155 MiB
6.898 MiB
8.265 MiB
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80140&edit=1