P
Peter J. Holzer
Indeed, Perl doesn't seem to free all the space immediately.
#!/usr/bin/perl
# 1652 perl ...
BEGIN { getc; }
my @array = (1 .. (1 << 22));
# 331360 perl ...
# huh? 80 bytes per an integer?
Interesting. It should be around 40 bytes on a 64 bit system (less on a
32 bit system). See http://www.hjp.at/programming/perl/memory/ for some
experiments I did with 5.8 and 5.10 a couple of years ago. Would you
mind running the test script on that page? (I just see that it accesses
/proc/$$/statm to get the (virtual) process size - if you don't run
linux, you'll have to change that).
getc;
print $#array, "\n"; # prints: 4194303
undef @array;
# 298640 perl ...
Note that the process shrunk only by 331360 - 298640 = 32720 kB, or
about 8 Bytes per element. That's size of the array itself. The elements
of the array (the other 72 bytes per element) were only returned to the
heap and are available for future malloc calls.
hp