Bug #69615 [Opn->Nab]: memory leak with eval declaring closure

From: Date: Sun, 10 May 2015 04:28:29 +0000
Subject: Bug #69615 [Opn->Nab]: memory leak with eval declaring closure
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192612@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 Updated by: requinix@php.net Reported by: ryan dot brothers at gmail dot com Summary: memory leak with eval declaring closure -Status: Open +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: 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. Previous Comments: ------------------------------------------------------------------------ [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 (#192612) next »