From 146af78e7c28e1cbbbd79c1a8794a6c0d4b7fd18 Mon Sep 17 00:00:00 2001 From: Sam O'Connor Date: Mon, 14 Mar 2016 09:30:39 +1100 Subject: [PATCH] Set up finalizer for the result of LightXML.parse_string() https://github.com/JuliaLang/LightXML.jl/issues/45#issuecomment-196069680 https://github.com/samoconnor/XMLDict.jl/issues/1 --- src/XMLDict.jl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/XMLDict.jl b/src/XMLDict.jl index 374ce45..62253ca 100644 --- a/src/XMLDict.jl +++ b/src/XMLDict.jl @@ -51,7 +51,11 @@ Base.show(io::IO, x::XMLDictElement) = show(io, x.x) # Parse "xml" string into LightXML.XMLDocument object. -parse_xml(xml::AbstractString) = wrap(LightXML.parse_string(xml)) +function parse_xml(xml::AbstractString) + doc = LightXML.parse_string(xml) + finalizer(doc, LightXML.free) + return wrap(doc) +end @@ -105,7 +109,10 @@ XMLDict.get(x::XMLDocument, tag, default) = get(root(x), tag, default) # Return Dict representation of "xml" string. function xml_dict(xml::AbstractString, dict_type::Type=OrderedDict; options...) - xml_dict(parse_xml(xml), dict_type; options...) + doc = parse_xml(xml) + r = xml_dict(doc, dict_type; options...) + finalize(doc) + return r end