Item9127: CompareRevisionsAddOn should call HTML::Element->delete
to avoid memory leaks
Priority: Normal
Current State: Closed
Released In: 1.0.10
Target Release: patch
HTML::Element documentation
states:
$h->delete()
Detaches this element from its parent (if it has one) and explicitly destroys the element and all its descendants. The return value is undef.
Perl uses garbage collection based on reference counting; when no references to a data structure exist, it's implicitly destroyed -- i.e., when no value anywhere points to a given object anymore, Perl knows it can free up the memory that the now-unused object occupies.
But this fails with HTML::Element trees, because a parent element always holds references to its children, and its children elements hold references to the parent, so no element ever looks like it's not in use. So, to destroy those elements, you need to call $h->delete on the parent.
Foswiki::Contrib::CompareRevisionsAddOn::Compare::compare
should call this method to avoid memory leaks. It's not a problem in CGI environment, but users may be using some persistent environment, like FastCGI or mod_perl.
--
GilmarSantosJr - 08 Jun 2010
Since
_getTree
returns a non-root element, it's needed to navigate to it before calling
delete()
method.
--
GilmarSantosJr - 08 Jun 2010