I have written an app that interacts with ODBC and feeds messages into an GUI. For some reason as a campaign goes on Java’s memory usage grows to very large amounts over 1GB ram. The app is simple and should not be running up memory like that. I think that because the threads are so busy and not stifled in anyway Java isn’t getting the chance to release the memory it is allocating so it keeps getting bigger and bigger. What I would like to do is somewhere in the thread force Java to release the memory. Can anyone tell me how to do this?
Share
Java can only release memory for objects that are no longer referenced (i.e., in use) by the program. And, once an object is no longer referenced, it will be cleaned up fairly quickly (albeit in a way that’s out of your direct control).
This is likely a straightforward memory leak. You’ll need to analyse the memory to see which objects are there that shouldn’t be, and then determine why the garbage collector thinks they are still reachable. At some point in your code you’ll be failing to release these variables that are no longer needed (for example, putting them in a
Map, though there are many ways of leaking memory if you’re not careful).The first step is to analyse the heap to find out which objects are there that shouldn’t be. You can use jhat, jvisualvm, various profilers and likely other tools for this.
The following questions may be of use in solving this issue: