Subject: | HTML::ExtractMain mem leak |
Date: | Mon, 6 Dec 2010 02:16:10 +0000 |
To: | bug-html-extractmain [...] rt.cpan.org |
From: | David Guthrie <guthrie.david [...] gmail.com> |
Hi Anirvan,
I have been using your ExtractMain module for perl. It works very well, but seems to have a memory leak and does not release its memory. Repeated calls to the module will slowly eat up all memory.
I am not sure but it looks like this is probably do to the fact that you use create an HTML tree without releasing it as the module requires. You call
HTML::TreeBuilder->new
without ever calling the ->delete method.
A nice way to take care of the clean up when the variable goes out of scope is to use the Object::Destroyer cpan module.
use Object::Destroyer
my $tree = HTML::TreeBuilder->new;
my $sentry = Object::Destroyer->new($tree, 'delete');
For more info see:
http://www.perl.com/pub/2007/06/07/better-code-through-destruction.html