(non)growing memory while creating anoymous functions via eval()
| From: | Hans-Juergen Petrich | Date: | Sun, 03 Feb 2013 15:27:16 +0000 |
| Subject: | (non)growing memory while creating anoymous functions via eval() | ||
| Groups: | php.internals php.internals | ||
| Request: | Send a blank email to internals+get-65572@lists.php.net to get a copy of this message | ||
Hi all
In this example (using php-5.4.11 on Linux) the memory will grow non-stop:
for ( $fp = fopen('/dev/urandom', 'rb'); true;) {
eval ('$ano_fnc = function() {$x = "'.bin2hex(fread($fp, mt_rand(1, 10000))).'";};');
echo "Mem usage: ".memory_get_usage()."\n";
}
But in this example not:
for ( $fp = fopen('/dev/urandom', 'rb'); true;) {
eval ('$ano_fnc = function() {$x = "'.bin2hex(fread($fp, 10000)).'";};');
echo "Mem usage: ".memory_get_usage()."\n";
}
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