Re: Memory leak in eval()'d code
| From: | Benjamin Morel | Date: | Sat, 29 Jun 2019 09:48:49 +0000 |
| Subject: | Re: Memory leak in eval()'d code | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-106107@lists.php.net to get a copy of this message | ||
> As Johannes already pointed out, we cannot garbage collect anonymous
class definitions due to the existence of opaque references.
I still don't understand *why*, then, the memory stays flat when the new
class does not happen in eval():
```
for ($i = 0; $i < 1000000; $i++) {
$object = new class {};
if ($i % 1000 == 0) {
echo memory_get_usage() . "\n";
}
}
```
I checked get_class() for all instances returned, **it's always the same
class name whether it's called from eval() or not**, so this code should
only ever create a single class in memory, right? Why the leak with eval()?
> $class = get_class($obj);
> $obj = new $class;
Interesting. Can this behaviour be relied upon (is it documented?), or is
this an implementation detail that may change at any time?
Thank you,
Ben