Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Memory usage of array and hashe variables by multiple inclusion.

by flexvault (Monsignor)
on Jul 02, 2013 at 13:16 UTC ( #1042005=note: print w/replies, xml ) Need Help??


in reply to Memory usage of array and hashe variables by multiple inclusion.

tobias_hofer,

    I am facing an increasing memory usage over the time (during the application-run) and i am not sure what could be the root-cause.

When I have this problem, it usually is a global variable that continues to grow. In some cases, I use a subroutine that I call every so many seconds to show the memory status of the variables. Something like this (Note: I did this from memory so it may not compile asis).

sub ShowGrowth { use Devel::Size qw(total_size); our ( $BigScalar, %BigHash, @BigArray ); my $nokeys = keys ( %BigHash ); my $noitems = $#BigArray; print $DLOG "####### Devel::Size #########\n"; print $DLOG "\$BigScalar: ",total_size(\$BigScalar),"\n"; print $DLOG "\%BigHash: ",total_size(\%BigHash)," No of keys: $no +keys\n"; print $DLOG "\@BigArray: ",total_size(\@BigArray), " No of element +s: $noitems\n"; }
You may want to add the actual memory location to the log. I have learned the hard way that the variable that I think I'm clearing may be the wrong one. To get the memory address:
print $DLOG "\$BigScalar: ",total_size(\$BigScalar)," Addr: ",\$Bi +gScalar,"\n";
Leaking memory problems are never easy to find, but this code may give you some ideas on how to find the problem.

Regards...Ed

"Well done is better than well said." - Benjamin Franklin

Replies are listed 'Best First'.
Re^2: Memory usage of array and hashe variables by multiple inclusion.
by tobias_hofer (Friar) on Jul 02, 2013 at 14:49 UTC
    Thanks a lot! I am now checking the size of the globals. They seem to increase quite fast due to logging

    Best Regards!
    Tobias

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2018-08-21 14:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:









    Results (200 votes). Check out past polls.

    Notices?