in reply to Understanding garbage collection specifics...

I'm not an expert on garbage collection, but I played around with it awhile ago, and found out this tidbit..... you also need to undef the array, before it goes out of scope. This works.
#!/usr/bin/perl use strict; use warnings; show_size(); { my @var=(0..1000000); show_size(); # undef before it goes out of scope undef @var; } show_size(); exit(0); sub show_size { local $/; open(my $pfh, '<', "/proc/$$/status") || die $!; my $size = <$pfh> =~ /VmSize:\s+(\d+)/ ? $1 : 'unknown'; close($pfh); print "Process size: $size\n"; }

Output:

Process size: 47936 Process size: 51976 Process size: 48064
As you can see, a bit of it is left over. Also it works in this simple example, but it may not in big complex scripts, or where objects are involved. </code>

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

Replies are listed 'Best First'.
Re^2: Understanding garbage collection specifics...
by cLive ;-) (Prior) on Feb 01, 2007 at 15:08 UTC
    Thanks for paying attention to my original post :)
      Doh.... damn that Speed Reading Class !! :-)

      I'm not really a human, but I play one on earth. Cogito ergo sum a bum