Bug #71737 [NEW]: Memory leak in closure with parameter named $this
| From: | james dot harris at icecave dot com dot au | Date: | Tue, 08 Mar 2016 05:38:04 +0000 |
| Subject: | Bug #71737 [NEW]: Memory leak in closure with parameter named $this | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-199662@lists.php.net to get a copy of this message | ||
From: james dot harris at icecave dot com dot au
Operating system: OSX
PHP version: 7.0.4
Package: Scripting Engine problem
Bug Type: Bug
Bug description:Memory leak in closure with parameter named $this
Description:
------------
A memory leak occurs when a closure that is defined inside a class and
has a parameter named $this is invoked with a value that contains a
reference to $this.
This gist (https://gist.github.com/jmalloc/e3db5842c2c4ab2a1edf) might
help explain a little better.
Affected PHP versions: https://3v4l.org/lr963
Test script:
---------------
class MemoryLeak
{
public function bad()
{
$closure = function ($this) {};
$closure([$this]);
}
}
$object = new MemoryLeak;
ini_set('memory_limit', '10M');
for ($i = 0; $i < 1000000; ++$i) {
$object->bad();
}
echo "Done" . PHP_EOL;
Expected result:
----------------
Done
Actual result:
--------------
Fatal error: Allowed memory size of 10485760 bytes exhausted (tried to
allocate 4096 bytes) in /Users/james/<snip>/leak.php on line 8
--
Edit bug report at https://bugs.php.net/bug.php?id=71737&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71737&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71737&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71737&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=71737&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=71737&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=71737&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=71737&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=71737&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=71737&r=support
Expected behavior: https://bugs.php.net/fix.php?id=71737&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=71737&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=71737&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=71737&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71737&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=71737&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=71737&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=71737&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71737&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=71737&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=71737&r=mysqlcfg