Menu

#562 LOBs > Buffer size Memory Leak (File.deleteOnExit())

closed
momo
8
2012-08-15
2008-05-05
Paul Smith
No

In net.sourceforge.jtds.util.BlobBuffer.createBlobFile(), a temporary File is created, and marked for deleteOnExit.

This temp buffer file is used for LOB's of size > configured buffer size, defaulting to 32Kb.

Our application uses CLOB's to store email body data, more often than not exceeding that size during retrieval.

Over a long running JVM (several weeks uptime), the # files marked for deleteOnExit ends up consuming hundreds of Mb of memory, simply holding references internally to the fully qualified pathname to the temporary file.

Inside the BlobBuffer.finalize() however the File is explicitly cleaned up, so more often than not these physical files are deleted looooong before the JVM exits. At JVM exit I presume the JVM loops through it's now very very long list trying to delete files that now do not exist, a benign condition.

This means that JTDS, while technically not leaking memory on it's own, is actually 'encouraging' the JVM to leak it's own memory.

Is there some way this could be addressed ? I think File.deleteOnExit() is doing more harm than good. I think the Finalizer is probably doing enough, which should get invoked when the Object is collected, or on JVM exit. I know there are some cases where this Finalizer-on-exit does not get called, but then a few files not cleaned up on JVM exit (those not done properly through the Finalizer) is a small price to pay for longer uptime.

Any chance of a fix ?

Discussion

  • Paul Smith

    Paul Smith - 2008-05-05

    Logged In: YES
    user_id=2079325
    Originator: YES

    misspelled leak in the title, oops. :)

     
  • Paul Smith

    Paul Smith - 2008-05-05

    Logged In: YES
    user_id=2079325
    Originator: YES

    I'm not sure this link refers to JTDS at all, but you can see a similar pattern and someone's work around here, if anyone else runs into this:

    http://www.jroller.com/javabean/entry/solving_an_outofmemoryerror_java_6

     
  • momo

    momo - 2009-08-03

    Thank you for reporting that issue. All calls to File.removeOnExit() have been removed from the current code base, finalizers have been added where necessary. It's a shame Sun still doesn't address this problem although dozens of bug reports have been filed related to the flawed design of File.deleteOnExit().

     
  • momo

    momo - 2009-08-07

    Forgot to close the issue...

     

Log in to post a comment.

MongoDB Logo MongoDB