     public var root:XML?
     public let data:Data
     
-    var currentParent:XML?
-    var currentElement:XML?
+    weak var currentElement:XML?
     var parseError:Swift.Error?
+    
+    deinit {
+        self.root = nil
+        self.currentElement = nil
+        self.parseError = nil
+    }
     
     public init(data: Data) {
         self.data = data

                             qualifiedName qName: String?,
                             attributes attributeDict: [String : String])
    {
        if self.root == nil {
            self.root = XML(name: elementName, attributes: attributeDict)
            self.currentParent = self.root
        } else {
            self.currentElement = XML(name: elementName, attributes: attributeDict)
            self.currentParent?.addChild(self.currentElement!)
            self.currentParent = currentElement
        }
    }
    
    @objc public func parser(_ parser: XMLParser, foundCharacters string: String) {

        let newValue = string.trimmingCharacters(in: .whitespacesAndNewlines)
        guard !newValue.isEmpty else { return }
        

        parser.shouldProcessNamespaces = false
        parser.shouldReportNamespacePrefixes = false
        parser.shouldResolveExternalEntities = false
        parser.parse()
        if let error = parseError {
            throw error
        }
    }
