Bug #80140 [NEW]: Including a file multiple times with anonymous class is leaking memory

From: Date: Tue, 22 Sep 2020 21:07:34 +0000
Subject: Bug #80140 [NEW]: Including a file multiple times with anonymous class is leaking memory
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-229153@lists.php.net to get a copy of this message
From: mvorisek at mvorisek dot cz Operating system: any PHP version: 7.4.10 Package: Scripting Engine problem Bug Type: Bug Bug description:Including a file multiple times with anonymous class is leaking memory 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 bug report at https://bugs.php.net/bug.php?id=80140&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=80140&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=80140&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=80140&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=80140&r=needscript Try newer version: https://bugs.php.net/fix.php?id=80140&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=80140&r=support Expected behavior: https://bugs.php.net/fix.php?id=80140&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=80140&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=80140&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=80140&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=80140&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=80140&r=dst IIS Stability: https://bugs.php.net/fix.php?id=80140&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=80140&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=80140&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=80140&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=80140&r=mysqlcfg

« previous php.bugs (#229153) next »