[EMAIL PROTECTED] (Sean M. Burke) writes:
> > * I think we still have a memory leak. I need to investigate.
> That's quite puzzling. Maybe someone who has Devel::Peek can
> troubleshoot?
What I found out is that HTML::Element leaks by itself because sub
delete_content doesn't really work, because you shift to $self, and
then go on using $_[0].
It also appears that the $self->{_body} and $self->{_head} need to be
unlinked manually too, and just nuking out %$self will remove the
_hparser_xs_state variable that HTML-Parser-v3 use to clean up in it's
DESTROY.
This quick&dirty patch got rid of the memory leak:
Index: lib/HTML/Element.pm
===================================================================
RCS file: /home/cvs/aas/perl/mods/html-tree-s/lib/HTML/Element.pm,v
retrieving revision 1.1.1.1
diff -u -p -u -r1.1.1.1 Element.pm
--- lib/HTML/Element.pm 1999/12/16 13:17:53 1.1.1.1
+++ lib/HTML/Element.pm 1999/12/17 11:50:45
@@ -620,7 +620,7 @@ Returns $h.
sub delete_content
{
- my $self = shift;
+ #my $self = shift;
for (@{ delete($_[0]->{'_content'})
# Deleting it here (while holding its value, for the moment)
# will keep calls to detach from trying to uselessly filter
@@ -665,7 +665,10 @@ sub delete
$self->detach if $self->{'_parent'} and $self->{'_parent'}{'_content'};
- %$self = (); # null out the whole object on the way out
+ delete $self->{_body}{_parent};
+ delete $self->{_head}{_parent};
+
+ #%$self = (); # null out the whole object on the way out
return undef;
}
The delete $self->{_body|_head}{_parent} stuff should obviously go into a
overridden HTML::TreeBuilder->delete.
For HTML::Parser we should go the route of making _hparser_xs_pstate
it's own object with it's own destructor, so it can clean up itself
and make %$self = () safe for HTML::Parser subclasses. Perhaps some
tricks with perl's internal magic can work. I will look into that.
Regards,
Gisle