<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    Hello Samuel,<br>
    <br>
    In XMLObject there is two levels of reference, <br>
     - one on MList (managed by reference counter)<br>
     - one on internal XMLObject (internally manager like handle, an
    integer that link to a C++ object)<br>
    <br>
    xmlDelete destroy internal XMLObject<br>
    clear destroy (unreference and destroy if ref <= 1 ) MList
    object.<br>
    <br>
    So in your case, after a xmlDelete, the internal XMLObject was
    destroyed but not the MList.<br>
    And after a clear doc, the MList was destroyed but the internal
    XMLObject not.<br>
    <br>
    Current XMLObject is based on simple MList with the id of the doc (
    store as double ).<br>
    If we want to correctly destroy the internal XMLObject with the
    clear command.<br>
    We must change the implementation to use types::UserType instead of
    types::Double and uses destructor of UserType to free XMLObject.<br>
    <br>
    > Deleting an object should clear all its pointers. For instance,
    with the XML example<br>
    > hereabove, deleting the document should clear doc and doc2.<br>
    I am not agree with that, I cannot delete an user variable
    indirectly. ( xmlDelete(doc) that will delete doc )<br>
    Only clear command can do that. For me it will be a bad practice.<br>
    <br>
    Antoine<br>
    <div class="moz-cite-prefix">Le 28/07/2018 à 16:20, Samuel Gougeon a
      écrit :<br>
    </div>
    <blockquote type="cite"
      cite="mid:33674333-6211-e3ef-4a3f-94410691f7ac@free.fr">
      <meta http-equiv="content-type" content="text/html; charset=utf-8">
      Hello,<br>
      <br>
      I am doing some tests about the save() function, in order to
      document its behavior when saving pointers to some objects.<br>
      <br>
      There is the case of XML objects:<br>
      Contrarily to graphic handles, that are pointers whose reloading
      restores the pointed graphics, saving XML pointers is possible,
      but then their reloading does NOT restore the XML document.<br>
      Then, when digging in Bugzilla in order to search for features
      about this and the clear() function applied to XML pointers, i've
      found back the following <a
        href="http://bugzilla.scilab.org/show_bug.cgi?id=13398#c2"
        moz-do-not-send="true">comment from Calixte</a>, referring to an
      expected change of Scilab 6 with respect to Scilab 5:<br>
      <br>
      <i>With Scilab 6, things will be easier since each data will have
        a reference counter [of pointers to it] which will allow to call
        a kind of destructor when the reference count will be zero.</i><i><br>
      </i><br>
      In practical, this new feature looks still not to be implemented.
      Here is an illustration:<br>
      <br>
      <font size="-1"><tt>// Let's create an XML document and a pointer
          "doc" to it:</tt><tt><br>
        </tt><tt>--> doc = xmlReadStr("<root><a att=""foo""
rib=""bar""><b>Hello</b></a></root>")</tt><tt><br>
        </tt><tt> doc  = </tt><tt><br>
        </tt><tt>XML Document</tt><tt><br>
        </tt><tt>url: Undefined</tt><tt><br>
        </tt><tt>root: XML Element</tt><tt><br>
        </tt><tt><br>
          // Now, let's make a copy of the pointer:</tt><tt><br>
        </tt><tt>-->doc2=doc</tt><tt><br>
        </tt><tt> doc2  =</tt><tt> </tt><tt><br>
        </tt><tt>XML Document</tt><tt><br>
        </tt><tt>url: Undefined</tt><tt><br>
        </tt><tt>root: XML Element</tt><tt><br>
        </tt><tt><br>
        </tt><tt>--> doc2==doc</tt><tt><br>
        </tt><tt> ans  =</tt><tt><br>
        </tt><tt>  T T    <<< this double True is strange, but
          it's not the matter here<br>
          <br>
          // Then let's clear both pointers: If a counter actually
          exists,<br>
          // it shall be set to 0 afterwards.<br>
          // And if the automatic destructor is implemented, then this
          should<br>
          // automatically delete the XML document. What's the reality?:<br>
          --> clear doc doc2   // OK<br>
          -->  xmlGetOpenDocs()<br>
           ans  =<br>
                 ans(1)<br>
          XML Document<br>
          url: Undefined<br>
          root: XML Element<br>
          <br>
        </tt></font>The document still exists. So, the automatic
      destructor is not yet implemented,<br>
      at least for XML objects.<br>
      <br>
      Is it a pity? To me, the reverse approach would be more relevant:<br>
      Deleting an object should clear all its pointers. For instance,
      with the XML example<br>
      hereabove, deleting the document should clear doc and doc2.<br>
      It's unfortunately not the case:<br>
      <font size="-1"><tt>--> xmlDelete(xmlGetOpenDocs()(:))  //
          cleaning the area</tt><tt><br>
        </tt><tt>--> doc = xmlReadStr("<root><a att=""foo""
rib=""bar""><b>Hello</b></a></root>");</tt><tt><br>
        </tt><tt>--> doc2 = doc;</tt><tt><br>
        </tt><tt>--> xmlDelete(doc)</tt><tt><br>
        </tt><tt>--> isdef(["doc" "doc2"],"l")</tt><tt><br>
        </tt><tt> ans  =</tt><tt><br>
        </tt><tt>  T T</tt><tt><br>
          --> doc<br>
           doc  = <br>
          --> <br>
          <br>
        </tt></font>This is the same issue with graphic handles when the
      figure they point to has been closed:<br>
      We then get some still existing <i>but invalid</i> handles,
      instead of properly clearing them.<br>
      <br>
      Regards<br>
      Samuel<br>
      <br>
      <br>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:users@lists.scilab.org">users@lists.scilab.org</a>
<a class="moz-txt-link-freetext" href="http://lists.scilab.org/mailman/listinfo/users">http://lists.scilab.org/mailman/listinfo/users</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>