Help! Flush Jvm, Java.lang.outof Memory
I'm using a java applet that paints a table-based database grid and running it on apache server. It works fine but after 2-3 hours of reloading (which initializes and draws the applet again to show the DB's most recent data), the browser will not render the applet.
When I put my mouse over the applet, I see a java.lang.outofmemory error.
The work-around is to open and close the browser(which kills the JVM instance).
How can I prevent this? Or better yet, how I can I flush the JVM's memory so that every time I repaint the applet, the JVM's stack will not overflood.
BTW, memory increase will only increase the time it takes for the applet to crash but I'd rather flush it when I refresh the browser somehow.
Any help would be greatly appreciated.
Simple approadh is to call :
This will just request that garbage collection be ran....it may not actually run, and it is only a temporary solution. You NEED to find out what objects you are not cleaning up/releasing and fix it, otherwise you will continue to run out of memory. Are you closing you sql statements (and other jdbc objects) when you are finished? They are memory intensive and WILL not be garbage collected until they are closed by you or a parent object.
Reloading the page document.location.reload() will free the applet.
You can find which objects are not garbage collected using a profiler. The easiest way is to create a small program that puts the applet in a Frame and run it in the profiler.
To determine the objects that are not freed:
1. Reset the heap instance counters to 0.
2. Perform the operations implemented by the applet.
3. Run the garbage collector.
4. Some instance counters may have changed. Analyze if these new instances are needed and if not determine the references preventing the garbage collection and find a solution to brake them.
I'm currently using OptimizeIt.
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center