Date: Sun, 23 Sep 2001 20:32:43 +0200
From: peter pilsl <pilsl_@goldfisch.at>
Subject: eval-statement fools garbage-collection ?
Message-Id: <3bae2acc$1@e-post.inode.at>


I work with big anonymous structures and have the problem, that garbage 
collection doesnt work. First I thought about circular references, but now 
I found my problem:

When I add an anonymous subroutine to my structure via an eval-statement 
(the routine is defined in a config-file that is parsed), something goes 
awfully wrong. The used mem of the structure is not released. This happens 
only when involving an eval in a sub that adds an anonymous sub to the 
structure ....

I wrote a small script that shows my problem:
(It runs on unixlike systems only cause I use `ps` for easy printing of 
used memory)

----script named mem.pl ----
#!/usr/bin/perl -w
use strict;

print `ps waux | grep mem.pl | grep -v grep | grep -v emacs`;
my $ptr={};
$ptr->{big}=[];
$#{$ptr->{big}}=5000000;
def2($ptr);
print &{$ptr->{test}->{func2}}(5),"\n";
print `ps waux | grep mem.pl | grep -v grep | grep -v emacs`;
undef $ptr;
print `ps waux | grep mem.pl | grep -v grep | grep -v emacs`;

sub def2 {
  my $ptr=shift;
  my $cmd='$ptr->{test}->{func2}=sub{return $_[0]+4};';
#  $ptr->{test}->{func2}=sub{return $_[0]+4};
  eval $cmd;
}


when running this way I get (skipped last column, the 5th column is the 
size):
pilsl    24212  0.0  1.0  2816 1288 pts/9    S    20:17   0:00 
9
pilsl    24212  0.0 16.4 22356 20900 pts/9   S    20:17   0:00 
pilsl    24212  0.0 16.4 22356 20904 pts/9   S    20:17   0:00 
So the memory is *not* freed at the undef-statement ..

When commenting the eval-statement in the def2-sub and uncomment the other 
assignment, I get the following (expected result):

pilsl    24245  0.0  1.0  2820 1292 pts/9    S    20:21   0:00 
9
pilsl    24245  0.0 16.4 22356 20900 pts/9   S    20:21   0:00 
pilsl    24245  0.0  1.0  2824 1372 pts/9    S    20:21   0:00 
So the mem is released at the undef-statement ...

this is strange ...

thnx,
peter

-- 
peter pilsl
pilsl_@goldfisch.at
http://www.goldfisch.at



