http://qs321.pair.com?node_id=1090104


in reply to Enforce Memory Cleanup

Looks like the garbage collection is not triggered in time.

Not really :)

Is there some way I can enforce garbage collection?

Not really

Have you faced such a problem?

Yes, I have created circular references that leaked memory, once I fixed my mistakes the problem went away

Read all about it, I did, and it improved my code tremendously :)

Tutorials: Variable Scoping in Perl: the basics,
Coping with Scoping , Mini-Tutorial: Perl's Memory Management,
Lexical scoping like a fox,
Read this if you want to cut your development time in half!,
Closure on Closures , perlref#Circular References,
Memory leaks and circular references,
Circular references and Garbage collection.,
make perl release memory,
about memory management , Re^3: Scope of lexical variables in the main script , Re: What's the weaken here for?,
Devel::Cycle,
Devel::NYTProf,
Devel::Leak Devel::LeakTrace,
WeakRef

Replies are listed 'Best First'.
Re^2: Enforce Memory Cleanup
by solegaonkar (Beadle) on Jun 18, 2014 at 03:33 UTC
    Thanks for your reply, but I don't see any possible memory leakage here. I have attached the code above.. This one blows up with an empty process method ...

      Thanks for your reply, but I don't see any possible memory leakage here. I have attached the code above.. This one blows up with an empty process method ...

      Well, in that code, %tmap keeps growing ; %tmap keeps eating memory ; until %tmap has eaten all the memory; does that make sense to you?

      ... $tmap ... &process(); ...

      That looks suspiciously like you're not coping with scoping, subs should take arguments ...

        Thanks for your interest. But I am not able to understand what is the meaning of this undef? undef %map I thought that should clear off all the memory!

        I tried to push the map inside the while loop, so that the scope itself takes care of things. But, the code still runs out of memory..

        while(sysread(CSV, $record, 66)) { my $count = 0; my %map; $map{substr($record, 18, 14)}->{substr($record, 3, 15)} = subs +tr($record, 36, 29); while (sysread(CSV, $record, 66)) { $map{substr($record, 18, 14)}->{substr($record, 3, 15) +} = substr($record, 36, 29); if ($count++ > 1000) { $count = 0; last; } } &process(\%map); }