libxml-raku / LibXML-raku

Raku bindings to the libxml2 native library
Artistic License 2.0
11 stars 4 forks source link

Memory leak resulting from childNodes #76

Closed jnthn closed 2 years ago

jnthn commented 2 years ago

This program leaks (golfed from reports of a significant leak in Spreadsheet::XLSX):

use LibXML::Document;
loop {
    my LibXML::Document $doc .= new: :version('1.0'), :enc('UTF-8');
    $doc.setStandalone(LibXML::Document::XmlStandaloneNo);
    my LibXML::Element $root = $doc.createElementNS(
            'http://schemas.openxmlformats.org/spreadsheetml/2006/main',
            'worksheet');
    $root.addNamespace('http://schemas.openxmlformats.org/officeDocument/2006/relationships', 'r');
    $doc.setDocumentElement($root);

    $doc.documentElement.childNodes;
}

Commenting out the call .childNodes, by contrast, does not leak, so it seems the leak is somehow related to that.

jnthn commented 2 years ago

I've analyzed this one further and it turns out that this module is not at fault, but rather there's a Rakudo/MoarVM issue where the DESTROY does not get run as expected. With a workaround for that (but still need to develop a proper fix), there's no leak.