Uploaded image for project: 'XMLBeans'
  1. XMLBeans
  2. XMLBEANS-283

Creating new cursors for the same XmlObj and selecting paths leads to memory leak

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • Version 2.2
    • None
    • Cursor
    • None
    • Java 1.4.2_10, Windows XP

    Description

      I have a reference to XmlObject that I like to keep while my application is running. During run new cursor for the XmlObject is created many times and selectPath(..) is called for the cursor. I call dispose() when I'm finished with the cursor. However using a profiler I can see that Cursor object are not garbage collected. If XmlObject would be unreferenced then all cursors would be garbage collected.

      Here is an example code:

      public class XmlBeansTest
      {
      public static void main( String[] args )
      throws Exception
      {
      XmlObject xmlObj = XmlObject.Factory.parse( "<test>foobar</test>" );
      while ( true )

      { // if xmlObj would be created here then there wouldn't any leak //XmlObject xmlObj = XmlObject.Factory.parse( "<test>foobar</test>" ); XmlCursor cursor = xmlObj.newCursor(); cursor.selectPath( "*" ); // in this example case we don't do anything for selected elements cursor.dispose(); }

      }
      }

      Above code results to increasing amount of Cursor objects. If xmlObj is created inside loop there would be any problem.

      Checking the code it seems that ChangeListener structure is Cursor and Locale classes keep references alive. The problem occurs if selectPath() is called because _selectPath calls Locale.registerForChange(..) that builds up ChangeListener "linked list".

      I wonder if it could be possible to clear _nextChangeListener when calling dispose() or some other way to tear down ChangeListener structure. I'm not familiar with XmlBeans code so I don't know what could be side effects of that change.

      Attachments

        Activity

          People

            Unassigned Unassigned
            pontifex Tero Vuorela
            Votes:
            2 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: