php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72466 Memory leak
Submitted: 2016-06-22 07:41 UTC Modified: 2016-06-22 08:53 UTC
From: rusa959 at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.6.22 OS: Ubuntu 16.04 LTS
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: rusa959 at gmail dot com
New email:
PHP Version: OS:

 

 [2016-06-22 07:41 UTC] rusa959 at gmail dot com
Description:
------------
In php versions 7.0.6, 5.6.22, 5.6.16, 5.4.35
I have construct object that have anonymous function in his field named "callback".
When i am trying to unset object - object is still exists, memory that allocated to object is not released.
In php version 5.3.10 memory is released.

Test script:
---------------
<?php
class Leak
{
    protected $callback;

    public function set()
    {
        $this->callback = function(){};
    }
}
$base_usage = memory_get_usage();
for($i=0;$i<12;$i++) {
    echo 'step-1 ' . (memory_get_usage() - $base_usage) . PHP_EOL;
    $leak = new Leak();
    $leak->set();
    unset($leak);
    echo 'step-2 ' . (memory_get_usage() - $base_usage) . PHP_EOL;
}
echo 'step-3 ' . (memory_get_usage() - $base_usage) . PHP_EOL;

Expected result:
----------------
step-1 344
step-2 840
step-1 840
step-2 840
step-1 840
step-2 840
step-1 840
step-2 840
step-1 840
step-2 840
step-1 840
....

Actual result:
--------------
step-1 344
step-2 840
step-1 840
step-2 1328
step-1 1328
step-2 1816
step-1 1816
step-2 2304
step-1 2304
step-2 2792
step-1 2792
step-2 3280
....

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-06-22 07:49 UTC] rusa959 at gmail dot com
Possible memory is not released because "callback" variable has internal reference to object by variable $this
 [2016-06-22 08:12 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2016-06-22 08:12 UTC] nikic@php.net
The cycle collector will release this memory once it runs.
 [2016-06-22 08:53 UTC] rusa959 at gmail dot com
Thank you!
My script reached memory limit earlier than php reached limit that needed to run garbage collector.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 12:00:01 2026 UTC