Memory leak in eval()'d code

From: Date: Fri, 28 Jun 2019 00:41:43 +0000
Subject: Memory leak in eval()'d code
Groups: php.internals 
Request: Send a blank email to internals+get-106084@lists.php.net to get a copy of this message
Hi internals, I've tracked down a memory leak to an anonymous class created within eval(): ``` for ($i = 0; $i < 1000000; $i++) { $object = eval('return new class {};'); if ($i % 1000 == 0) { echo memory_get_usage() . "\n"; } } ``` The memory usage quickly ramps up and memory_limit is reached in seconds. Without eval(), the memory usage stays flat. I'm on 7.3.6. *Is this a bug?* Or is this some inherent limitation of eval() that cannot be fixed? Thanks for any insight. Ben *In case you're wondering (I'm sure you are!), I need this to dynamically create an object that implements an arbitrary number of interfaces <https://github.com/brick/schema/blob/master/src/ObjectFactory.php>, for a schema.org <http://schema.org> structured data reader library.*

« previous php.internals (#106084) next »