RE: [PHP-DEV] Memory leak in eval()'d code
| From: | CHU Zhaowei | Date: | Sun, 30 Jun 2019 12:48:32 +0000 |
| Subject: | RE: [PHP-DEV] Memory leak in eval()'d code | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-106121@lists.php.net to get a copy of this message | ||
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 <smalyshev@gmail.com>
> Sent: Sunday, June 30, 2019 10:43 AM
> To: Benjamin Morel <benjamin.morel@gmail.com>; Nikita Popov
> <nikita.ppv@gmail.com>
> Cc: CHU Zhaowei <me@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
> smalyshev@gmail.com
>
> --
> PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit:
> http://www.php.net/unsub.php
>