php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77209 Leaks memory
Submitted: 2018-11-27 12:09 UTC Modified: 2018-12-09 04:22 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: silicid at gmail dot com Assigned:
Status: No Feedback Package: Performance problem
PHP Version: 7.2.12 OS: Debian 8
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2018-11-27 12:09 UTC] silicid at gmail dot com
Description:
------------
You must create a file with the specified code.
If you execute method "is_object" from "$this" and unset the object, then leaks memory. But if you call method "is_object" for "$object", then there are no problems.
In version 7.1 there are no problems. There are no problems in Windows.


Test script:
---------------
<?php
class Test {
    public function __construct() {
        for ($i = 0; $i < 1000; ++$i) {
            $this->result[] = rand(1, 1000);
        }
    }
    function object() {
        is_object($this);
    }
}

$memory = memory_get_usage();
for ($i = 0; $i < 1; ++$i) {
    $object = new Test();
    $object->object();
    unset($object);
}
var_dump(memory_get_usage() - $memory);

$memory = memory_get_usage();
for ($i = 0; $i < 100; ++$i) {
    $object = new Test();
    $object->object();
    unset($object);
}
var_dump(memory_get_usage() - $memory);

$memory = memory_get_usage();
for ($i = 0; $i < 100; ++$i) {
    $object = new Test();
    is_object($object);
    unset($object);
}
var_dump(memory_get_usage() - $memory);


Expected result:
----------------
int(0)
int(0)
int(0)


Actual result:
--------------
int(37336)
int(3733600)
int(0)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-11-27 13:20 UTC] silicid at gmailc dot om
PHP Version 7.2.12-1+0~20181112102353.11+jessie~1.gbp55f215
System 	Linux VV10015-z2174 4.15.17-3-pve #1 SMP PVE 4.15.17-13 (Mon, 18 Jun 2018 17:15:04 +0200) x86_64 
Build Date 	Nov 12 2018 13:46:27
 [2018-11-27 13:39 UTC] danack@php.net
-Status: Open +Status: Feedback
 [2018-11-27 13:39 UTC] danack@php.net
please could you check again, with code like the below as I don't think the garbage collection kicks in immediately every single time, and also if it is actually a memory leak, the memory usage should continue to go up, rather than just be slightly higher for a moment. 

The output of the script below for me is:

int(0)
int(0)
int(32)
int(0)
int(0)
int(32)
int(0)
int(0)
int(32)...

https://3v4l.org/dPZ2R


class Test {
    public function __construct() {
        for ($i = 0; $i < 1000; ++$i) {
            $this->result[] = rand(1, 1000);
        }
    }
    function object() {
        is_object($this);
    }
}




function checkMemory($memoryAtStart)
{
    for ($i = 0; $i < 1; ++$i) {
        $object = new Test();
        $object->object();
        unset($object);
    }
    var_dump(memory_get_usage() - $memoryAtStart);

    $memoryAtStart = memory_get_usage();
    for ($i = 0; $i < 100; ++$i) {
        $object = new Test();
        $object->object();
        unset($object);
    }
    var_dump(memory_get_usage() - $memoryAtStart);

    $memoryAtStart = memory_get_usage();
    for ($i = 0; $i < 100; ++$i) {
        $object = new Test();
        is_object($object);
        unset($object);
    }
    var_dump(memory_get_usage() - $memoryAtStart);
}

$memoryAtStart = null;

for ($x=0; $x<100; $x++) {
    if ($memoryAtStart === null) {
        $memoryAtStart = memory_get_usage();
    }

    checkMemory($memoryAtStart);
    gc_collect_cycles();
}
 [2018-11-27 14:05 UTC] silicid at gmailc dot om
It depends on the number of objects created.
The output for me is:

int(37336)
int(3733600)
int(0)
int(3808384)
int(3733600)
int(0)
int(7579320)
int(3733600)
int(0)
int(11350256)
int(3733600)
int(0)
int(15121192)
int(3733600)
int(0)
int(18892128)
int(3733600)
int(0)
int(22663064)
int(3733600)
int(0)
int(26434000)
int(3733600)
int(0)
int(30204936)
int(3733600)
int(0)
int(33975872)
int(3733600)
int(0)...
 [2018-12-09 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 03:01:28 2024 UTC