Eval is not the only case that will cause memory usage growing actually. https://3v4l.org/fPhlU is an example using include inside a loop, which is used to simulate including same file several times. I agree it might be trivial to improve for eval since it's not recommended to use due to security concern nowadays. But I think we should pay attention to this issue since include/require behave the same.
In theory, I understand how it happens. You won't be surprised if you copy the code and paste it several times and more memory is used. It's reasonable that more memory is needed to compile longer codes. Include several times just work like copy&paste several times. But since we are including the same file, is it possible to detect and reuse the space? Regards, CHU Zhaowei > -----Original Message----- > From: Stanislav Malyshev <smalys...@gmail.com> > Sent: Sunday, June 30, 2019 10:43 AM > To: Benjamin Morel <benjamin.mo...@gmail.com>; Nikita Popov > <nikita....@gmail.com> > Cc: CHU Zhaowei <m...@jhdxr.com>; PHP Internals <internals@lists.php.net> > Subject: Re: [PHP-DEV] Memory leak in eval()'d code > > Hi! > > > I still don't understand *why*, then, the memory stays flat when the > > new class does not happen in eval(): > > Because that code creates only one class. > > > 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()? > > There's no leak, eval() just creates new class each time. > -- > Stas Malyshev > smalys...@gmail.com > > -- > PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: > http://www.php.net/unsub.php > -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php