in reply to Massive Perl Memory Leak
1) Don't use & when calling subroutines. And if you do, DO MAKE SURE you do not use it when calling a subroutine with no parameters! Unless you know what that means.
2) Don't use
use%{$datahash{"devinfo"}} = %devinfo;
instead. It's silly to force perl to flatten the %devinfo hash into a list, build a new has containing the data and then throw %devinfo out of window. Just take a reference.$datahash{"devinfo"} = \%devinfo;
3) Don't use the global. Pass a reference to the %datahash
for (;;) { my %datahash; ..getdevicetopoll.. ifpoll( \%datahash, $dev); print FILE dump %datahash; } ... sub ifpoll { my ($datahash, $dev) = @_; my %devinfo; my %interfaces; ## etc... ..snmp a lot of data here.. $datahash->{"devinfo"} = \%devinfo; $datahash->{"interfaces"} = \%interfaces; return; }
Neither of those changes should affect the leak though, it must be somewhere else in the code. Are you sure you are not producing any cyclic references in the part of the code you did nto show us?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Massive Perl Memory Leak
by wagnerc (Sexton) on Jun 13, 2007 at 19:37 UTC | |
by Jenda (Abbot) on Jun 13, 2007 at 22:04 UTC | |
by wagnerc (Sexton) on Jun 14, 2007 at 00:58 UTC | |
by Jenda (Abbot) on Jun 14, 2007 at 08:38 UTC |