Welcome to the Xceed Community | Help
Community Search  
More Search Options

Memory Leak while using DLL API through Java Native Interface (JNI)

Sort Posts: Previous Next
  •  08-06-2012, 3:47 AM Post no. 32509

    Memory Leak while using DLL API through Java Native Interface (JNI)

    Attachment: hs_err_pid612.txt

    I am using Xceed's compression library to decompress some data. I have written the native code using the DLL API and calling this native code through JNI. The programming model that I'm following is the one dictated here  i.e. i initialize the DLL and then create a XceedCompressionObject (although I use the methods XcCreateXceedCompressionA). I use this object to call XcUncompress. Once I have copied the returned decompressed array to the java array, i free the native array returned by XcUncompress using XzFree. Finally I free the XceedCompressionObject with XcDestroyXceedCompression and then shutdown the DLL using XceedZipShutdownDLL.

      This whole sequence of calls (DLL initialisation, XcCompressionObject creation, Decompression, MemoryFreeing, XceedCompressionObject destruction and DLLShutdown) is repeated a number of times, once every 100 millisecods or so for 8 - 10 hours. After 8-10 hours the java code that uses the Xceed library over JNI crashes with OutOfMemoryError (I have attached processlog that JVM throws along with this). I have seen the java code and the profiler shows that the java heap and generations increases and decrease within bounds as they should so I don't think that there is a leak withing the java process. Also, since the method fails in native code, I have a feeling that there is memory leak in the native code.

    IsXzFree the right function to use for freeing memory created during decompressing (calling XcUncompress)?

    If I am freeing memory correctly what do u think would be the reason for the issue?

  •  08-09-2012, 12:06 PM Post no. 32543 in reply to 32509

    Re: Memory Leak while using DLL API through Java Native Interface (JNI)

    Hi Nishant,

    Your code sequence seems correct. And yes, XzFree() is the correct function to call when you are decompressing. It should work without a leak.

    From your exception trace, I am concerned with the name of Xceed methods I see. I see two references to a function called 'xzUncompress()'. Is that part of your 'glue' code or is this a call into the Xceed library?

    Another thing to look at closely is your call to XzFree(). XcUncompress() outputs a BYTE** ppcUncompressed:

       int XcUncompress( HXCEEDCMP hComp, const BYTE* pcSource, DWORD dwSourceSize, BYTE** ppcUncompressed, DWORD* pdwUncompressedSize, BOOL bEndOfData )
     
    This is a pointer to a pointer to data.

    What you want to do is free the data and not the pointer to the data. So, in C/C++, your call to XzFree() would be:

       XzFree( *ppcUncompressed );

    Is that what you are doing?

     


    ** Quick Tip: Clients with an active support subscription should be sending their questions by email if they wish to benefit from the faster response time. Thanks!


    Diane Lafontaine
    Technical Support
    Xceed Software Inc.
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.