Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Enforce Memory Cleanup

by Anonymous Monk
on Jun 17, 2014 at 06:37 UTC ( #1090104=note: print w/ replies, xml ) Need Help??


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


Comment on Re: Enforce Memory Cleanup
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); }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1090104]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2014-10-23 22:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (129 votes), past polls