in reply to Re^4: modularization, memory usage and performance
in thread modularization, memory usage and performance

It is perhaps1 code like this:

$self->[0] = \%h;

from Tie::Persistent that is making a circular reference. And a circular reference would mean that nothing tied to that module ever gets destroyed (prior to global destruction). (Or the module could be squirreling away a reference to your hash or to the 'tie' object in some other spot even without a circular reference.) Next step: Augment your simple example above with code that shows that the destruction isn't happening when it should and report that to the module author.

1 Wild guess, really. I didn't study the code long enough to understand it. I was just scanning for something like the above which your report made me highly suspicious of existing.

- tye        

Replies are listed 'Best First'.
Re^6: modularization, memory usage and performance (circles)
by jmagiera (Novice) on Feb 09, 2005 at 08:03 UTC
    A good idea, tye. Here is the code that proves it. I separated the two parts (create and read file), to prove that the error is in the reading.

    First, create the big datafile:
    #!/usr/bin/perl use Tie::Persistent; my %a = (); tie %a , 'Tie::Persistent', "bigdatafile" , 'rw'; for my $i (1...5000) { $a{"ENTRY$i"}{"has"}{"a lot"}{"of data"}; } untie %a;

    Now read the big datafile:
    #!/usr/bin/perl use strict; use Tie::Persistent; # use this time to look up the process # and see how much memory it consumes print "My Process ID is $$\nIn 10 seconds I will tie a big data file:\ +n"; for my $i (1..10) { print "$i\n"; sleep 1; } &loadData("bigdatafile"); # now look at memory usage again sleep 100; exit 0; sub loadData { my $file = shift; my %localhash = (); tie %localhash , 'Tie::Persistent', $file , 'rw'; print "File tied\n"; untie %localhash; print "File untied\n"; undef %localhash; }
    Perl help me.