Bug #71366 [Opn->Nab]: When use anonymous function in class property have a memory leak
| From: | bwoebi@php.net | Date: | Fri, 15 Jan 2016 06:02:05 +0000 |
| Subject: | Bug #71366 [Opn->Nab]: When use anonymous function in class property have a memory leak | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-198665@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71366&edit=1
ID: 71366
Updated by: bwoebi@php.net
Reported by: xiemaomao520 at 163 dot com
Summary: When use anonymous function in class property have a
memory leak
-Status: Open
+Status: Not a bug
Type: Bug
-Package: PDO Core
+Package: Scripting Engine problem
Operating System: All
PHP Version: 7.0.2
Block user comment: N
Private report: N
New Comment:
That's not a leak, you just are hitting a case in class A which holds a reference to itself via
the anonymous function and thus will only be destructed when the cycle collector is run. (Which, in
this simple script, is at the end of it.)
Previous Comments:
------------------------------------------------------------------------
[2016-01-14 09:24:50] xiemaomao520 at 163 dot com
Change title.
------------------------------------------------------------------------
[2016-01-14 09:22:08] xiemaomao520 at 163 dot com
Description:
------------
Affect all PHP versions.
Test script:
---------------
<?php
class A {
public function __construct ()
{
$this->call = function () {
};
}
public function __destruct()
{
echo 'Destruct: ' . get_class($this) . PHP_EOL;
}
}
class B
{
public function __destruct()
{
echo 'Destruct: ' . get_class($this) . PHP_EOL;
}
}
function test()
{
new A;
new B;
}
test();
echo "Exit\n";
Expected result:
----------------
Destruct: A
Destruct: B
Exit
Actual result:
--------------
Destruct: B
Exit
Destruct: A
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71366&edit=1