|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76523 PHP Leaks memory when utilizing objects
Submitted: 2018-06-24 15:25 UTC Modified: 2020-01-08 15:58 UTC
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (50.0%)
From: mimipim at abv dot bg Assigned:
Status: Not a bug Package: Performance problem
PHP Version: 7.2.7 OS: CentOS, Debian, Maybe any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: mimipim at abv dot bg
New email:
PHP Version: OS:


 [2018-06-24 15:25 UTC] mimipim at abv dot bg
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:

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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-06-24 15:27 UTC] mimipim at abv dot bg
This is minimized script for reproduction:


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++) {
    $a = new NonLeakingClass();

 [2018-06-24 16:10 UTC] 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.
 [2020-01-08 15:58 UTC]
-Status: Open +Status: Not a bug
 [2020-01-08 15:58 UTC]
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.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 17 01:01:29 2024 UTC