title: Is it safe to return a cloned XmlNode of a local IXmlDocument in Delphi?
body: <p>I am on Delphi XE2. I have a common function that takes a XML string and returns the CloneNode of the root IXmlNode. It is supposed for commonizing the settings to the XMLDocument. The inside of the function simply use a local variable IXMLDocument and call things like NewXMLDocument and modify some parse options. </p>
  
  <p>But I found that occasionally, accessing the fields of the returned cloned node outside would gives AV, mostly when accessing the ChildNodes field.</p>
  
  <p>Is such problem occurring because the local variable IXMLDocument goes out of scope as the function ends and so the interface reference count mechanism freed it, ignoring whether it has any cloned node? </p>