Menu

Possible memory leak when using XML on worker scripts

2022-05-25
2022-05-25
  • Sylvain Basset

    Sylvain Basset - 2022-05-25

    Hello Stefan,

    Thank you for your awesome software, it helps me a lot.

    I think I’ve found some kind of memory leak, if I don't made a mistake :

    On a worker script, I created an XML reader object, to read a XML file.
    To do so, I use :

    l_FormatXmlReader = scriptThread.createXmlReader();
    l_FormatXmlReader.readFile("C:/Tmp/Decode.xml", false)
    l_ElemFmtRoot = l_FormatXmlReader.getRootElement() ;
    l_ElemFmtCmds = l_ElemFmtRoot.childElements() ;
    

    Then, I parse among children tags periodically to get some information inside XML with
    ElemFmtCmd.childElements()

    When I do this, I see RAM memory usage always increasing (see included pictures).
    The memory usage increase further, when I call the childElements() function more often, which make me think that there is a problem related to this function (or maybe I missing something using it).

    I included a simplified example of my application (with a XML file) which involve this problem.

    Thank in advance if you can help me to solve this (even with a workaround :)

     
  • Stefan Zieker

    Stefan Zieker - 2022-05-25

    Hi,

    if you call getRootElement and childElements objects are created internally. These objects are deleted if the script exits. If you want to delete these objects manually you can use deleteLater (this is a hidden function).
    Example:

    function ProcessXml()
    {
       ElemFmtCmd = l_ElemFmtCmds[4] ;
    
       if ( ElemFmtCmd )
       {
          if ( ElemFmtCmd.attributeValue( "flavoured" ) == "1" )
          {
             var ElemFmtFlavours = ElemFmtCmd.childElements()
    
               // do some process with flavours
    
               // delete the created objects
               for(var i = 0; i < ElemFmtFlavours.length; i++)
              {
                  ElemFmtFlavours[i].deleteLater();
              }
    
          }
       }
    }
    
     

    Last edit: Stefan Zieker 2022-05-25

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.