Re: (non)growing memory while creating anoymous functions via eval()

From: Date: Sun, 03 Feb 2013 16:28:33 +0000
Subject: Re: (non)growing memory while creating anoymous functions via eval()
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-65574@lists.php.net to get a copy of this message
On 03/02/13 16:27, Hans-Juergen Petrich wrote:
> The only different in the second example is the fixed body length of
> the eval()-created anoymous function.
> I wondering why the memory in the second code-example will be freed at
> some point while in the first example not.
>
> I don't think it's a PHP-Bug but i also not understand this behavior.
>
> Is there one who can explain this?
> Thank you very much.
>
> Greetings
> Hans-Juergen Petrich

It can be simplified to:
> <?php
> while (true) {
>     $value = mt_rand(1, 10000);
>     $a = '$ano_fnc = function() {' . str_repeat(" ", $value) .
> '};';
>     eval ($a);
>     echo "Mem usage: ".memory_get_usage()."\n";
> }
The function *is* being removed, $ano_fnc alternates between
object(Closure)#1 and object(Closure)#2, it's not leaking function objects.
I suspect eval is checking a hashtable which is being forced to resize
continuously, but it shouldn't grow unbounded either.



Thread (15 messages)

« previous php.internals (#65574) next »