Bug #69615 [Com]: memory leak with eval declaring closure

From: Date: Tue, 17 Nov 2015 14:14:30 +0000
Subject: Bug #69615 [Com]: memory leak with eval declaring closure
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-197297@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69615&edit=1 ID: 69615 Comment by: chris at willowsconsulting dot ie Reported by: ryan dot brothers at gmail dot com Summary: memory leak with eval declaring closure Status: Not a bug Type: Bug Package: Performance problem Operating System: Linux PHP Version: 5.6.8 Block user comment: N Private report: N New Comment: I became interested by the eval() behavior recently, and I can confirm that the memory usage gets higher by the time of the execution. However it is not really a bug, but the way eval() is fundamentally written: * it creates a temp file with the code inside (sometimes it is stored in memory) * it then includes that temp file using a normal include() function As you can see, the more eval() you do, the more include() it will trigger, resulting in a memory usage that cannot be freed... Previous Comments: ------------------------------------------------------------------------ [2015-05-10 04:28:29] requinix@php.net It's not actually a leak; see bug #33487 and bug #68132 for more. To demonstrate, try this modification: echo "0 ", number_format(memory_get_usage())."\n"; for ($i = 0; $i <= 100000; $i++) { test(); if(strlen(rtrim($i, "0")) == 1) { echo $i, " ", number_format(memory_get_usage())."\n"; } } When I run that (5.5.13 on Windows) I get 0 120,360 ... 10 142,696 ... 100 172,072 200 183,088 300 186,760 400 205,120 500 212,464 600 212,464 700 212,464 800 212,464 900 212,464 1000 212,464 ... 10000 212,464 ... 100000 212,464 As you can see, memory usage will increase but eventually does plateau. ------------------------------------------------------------------------ [2015-05-10 02:45:10] ryan dot brothers at gmail dot com Description: ------------ I am seeing a memory leak when using eval() to declare a closure in certain cases. In the below example, the memory usage increases by about 1MB when it should remain relatively constant. Test script: --------------- <?php function test() { $php_code = '$run = function() {'; foreach (range(1, 15) as $a) { $php_code .= 'if (1 == 1) { $aaaaaa = true; } else { $aaaaaa = false; }'; } $php_code .= '};'; eval($php_code); } echo number_format(memory_get_usage())."\n"; for ($i = 0; $i <= 1000; $i++) { test(); } echo number_format(memory_get_usage())."\n"; Expected result: ---------------- 224,440 224,440 Actual result: -------------- 224,440 1,271,128 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=69615&edit=1

« previous php.bugs (#197297) next »