in reply to Re^2: Perl 5.10 eval($string) memory leak
in thread Perl 5.10 eval($string) memory leak

Wouldn't it make sense to move your first occurrence of:

$index = int(rand($symbol_size));

... inside the while loop (right at the top of the loop), and then remove the occurrence at the end of the loop?

That is, not:

foo(); while (1) { bar(); foo(); }

But instead:

while (1) { foo(); bar(); }

It should have the same effect; be more compact and avoid repetition.

Anyway, I believe the reason you're leaking memory is that your evaluated strings can end up containing variables, and those variables are not lexicals, so they get stored in the package stash.

package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

Replies are listed 'Best First'.
Re^4: Perl 5.10 eval($string) memory leak
by fuzzmonkey (Sexton) on Aug 16, 2013 at 20:29 UTC

    Yeah the code that is being generated needs to be more constrained. I can't just throw any kind of garbage at it and believe it will get thrown away properly without my help. Thanks for the help!