in reply to Re^2: XML::LibXML memory leak
in thread XML::LibXML memory leak
There's no reason to go messing with someone else's namespace.
sub detach { my( $node ) = @_; $node->parentNode->removeChild( $node ); } detach($node);
would work just as well.
Except it's not enough. It won't separate it from the document.
$ perl -MXML::LibXML -E' my $node; { my $xml = "<root><foo><bar/></foo></root>"; my $doc = XML::LibXML->new->parse_string($xml); ($node) = $doc->findnodes("//bar"); $node->parentNode->removeChild($node); } { my $doc = $node->ownerDocument; say "owner=", $doc; if ($doc) { say $_->nodeName for $doc->findnodes("//*"); } } ' owner=XML::LibXML::Document=SCALAR(0x817bcb8) root foo
You need to give the node a new document.
$ perl -MXML::LibXML -E' my $foster_home = XML::LibXML::Document->new("1.0", "UTF-8"); my $node; { my $xml = "<root><foo><bar/></foo></root>"; my $doc = XML::LibXML->new->parse_string($xml); ($node) = $doc->findnodes("//bar"); $node->setOwnerDocument($foster_home); } { my $doc = $node->ownerDocument; say "owner=", $doc; if ($doc) { say $_->nodeName for $doc->findnodes("//*"); } } ' owner=XML::LibXML::Document=SCALAR(0x832af38)
Note that transfers the node's children too.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: XML::LibXML memory leak
by spstansbury (Monk) on Dec 08, 2010 at 17:38 UTC | |
by ikegami (Patriarch) on Dec 08, 2010 at 19:37 UTC | |
by spstansbury (Monk) on Dec 08, 2010 at 20:31 UTC | |
by ikegami (Patriarch) on Dec 08, 2010 at 20:56 UTC | |
by spstansbury (Monk) on Dec 08, 2010 at 22:35 UTC | |
|