I posted
Memory usage & hashes of lists of hashes of lists a couple of days ago regarding memory usage in a foreach loop. Here is some updated code, with some attempts at finding the leak.
I am still unsuccesful, this code uses up a large amount of memory very quickly (~200 meg after ~100 iterations), then slowly releases it, until it's using ~50 meg. Says to me that there is a memory leak somewhere, but here's the code:
my %tick_inf;
foreach (sort keys %tickets)
{
my $ticket = ((split " ",$_)[0]);
(%tick_inf = ars_GetEntry($remedy,$schema,$ticket))
|| warn "Could not retrieve $ticket: $ars_errstr";
++$count;
print "$count\n";
undef (%tick_inf);
next;
}
I have attempted a few things to clean this up, most notable is moving the %tick_inf decleration to outside of the foreach loop, and undefing it once I'm done with the data (in this example I'm not doing anything with it). I've also attempted to dump the hashes (using Storable), the results of that show that the serialized hash size averages about 800k. I've used a seperate script to retrieve the hashes and it's mem usage hovers around 9 meg. Some of the values in the hash are AoH's.
This also does not seem to be a platform thing, as I've run the script on Windows 2000, Linux and HP-Unix with the same problem on each. Perl version is 5.6.1 for all of these.
I'm ready to attribute this to a bug with ARSperl so I need to do some hunting in the ARSperl module(s). My questions are:
a) Am I right in assuming this is a memory leak in the ARSperl module? Or can anybody spot anything in this code that would cause the problem that I have described
b) If a is correct then what kinds of things am I looking for in the module - self referencing hashes is one thing that causes memory leaks - what else?
c) Is this even a memory leak - normally those just cause the RAM to be consistently chewed up vs chewed up quickly and released slowly right?
Someone in the last post suggested that I go the political route instead, and indeed in this case that is what has happened - the sysadmins are increasing the user RAM limit on the server. But I am still incredibly curious about this, I don't like to let things go when I don't understand why it is happening.. and I will be using this module in the future (in fact I have a few more times), and I want to make sure that I don't see these issues again.