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: 2020-01-08 15:58 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: Not a bug Package: Performance problem
PHP Version: 7.2.7 OS: CentOS, Debian, Maybe any
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mimipim at abv dot bg
New email:
PHP Version: OS:

 

 [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

Pull Requests

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.
 [2020-01-08 15:58 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2020-01-08 15:58 UTC] nikic@php.net
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: Sun Dec 08 20:01:27 2024 UTC