in reply to Memory Managment with Subroutines and Objects
You seem to come from a language like C where you have to do garbage collection and memory management yourself. In most scripting languages the interpreter does that in the background without your intervention. The simple rule it uses is "If there is no reference anymore pointing to some variable or object, reclaim the memory". This means that for example in this snippet
if ($a==3) { my $f= 'a' x10000; } #no $f, no waste
$f is referencing a very long string (i.e internally $f holds a reference to a memory location). But after the 'if' clause there is no $f anymore and so no reference to that long string. Ergo the memory gets reclaimed by perl. The same would happen if you just did $f='';. No reference, no memory
There might still be memory loss because of circular references, but this is a bug and you can tell the module author about it if you find such a case
Now if you suspect your module or WWW::Mechanize to have such a bug or just want to make sure you could write a test script like you did (good thinking by the way). You just didn't didn't test first if there is a problem at all. Usually tests are written to check for all the worst of cases and make sure that everything works regardless. Specifically a good method is if you find a bug, to first write a test that prints 'fail' because of the bug and then correct the bug until the test prints 'good'.
So what you could have done is write your test so that he calls $mech->get repeatedly and check the memory consumption. Only if the consumption really goes up would there be any reason to act and find a solution.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Memory Managment with Subroutines and Objects
by Anonymous Monk on Dec 28, 2010 at 23:36 UTC |