php.net |  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: 2018-06-24 15:27 UTC
Votes:2
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: Open Package: Performance problem
PHP Version: 7.2.7 OS: CentOS, Debian, Maybe any
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2018-06-24 15:25 UTC] 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-06-24 15:27 UTC] 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 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.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Nov 16 22:01:35 2019 UTC