Bug #76523 [Opn->Nab]: PHP Leaks memory when utilizing objects

From: Date: Wed, 08 Jan 2020 15:58:14 +0000
Subject: Bug #76523 [Opn->Nab]: PHP Leaks memory when utilizing objects
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224783@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76523&edit=1 ID: 76523 Updated by: nikic@php.net Reported by: mimipim at abv dot bg Summary: PHP Leaks memory when utilizing objects -Status: Open +Status: Not a bug Type: Bug Package: Performance problem Operating System: CentOS, Debian, Maybe any PHP Version: 7.2.7 Block user comment: N Private report: N New Comment: This actually has nothing to do with the object construction, but rather with the var_dump(). Which is also why the first echo makes a difference. PHP obviously lazily initializes some output mechanism. Previous Comments: ------------------------------------------------------------------------ [2018-06-24 16:10:04] mimipim at abv dot bg According to debug data collected with the meminfo extension it seems that the problem is not actual memory leakage but instead the memory_get_usage function is not reporting correct number. Only experts on PHP's code would be able to tell what is the case. ------------------------------------------------------------------------ [2018-06-24 15:27:00] mimipim at abv dot bg This is minimized script for reproduction: https://3v4l.org/dSB4T <?php class NonLeakingClass { } //echo "Test empty object memory leakage" . PHP_EOL; // WARNING: Uncomment this line and PHP stops to leak memory on object creation, strange :) for ($h = 0; $h < 5; $h++) { var_dump(memory_get_usage(false)); $a = new NonLeakingClass(); unset($a); gc_collect_cycles(); var_dump(memory_get_usage(false)); } exit; ------------------------------------------------------------------------ [2018-06-24 15:25:36] mimipim at abv dot bg Description: ------------ I have found that PHP leaks memory simply by creating empty class object. The leakage happens only on first initiation of the exact class type, each next new object will not leak any more. Test script: --------------- Check out the live test script: https://3v4l.org/T5qsG It shows you that after initialization of the fist object and destroying it the memory is not freed up. Strangely if you uncomment the echo statement the leakage is not appearing. HHVM reports the same memory in all cases, just as expected. Expected result: ---------------- All memory reports to show the same memory usage. Actual result: -------------- After the first memory report are following reports of used RAM bigger than expected. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76523&edit=1

« previous php.bugs (#224783) next »