Skip to main content

Forcing “Mark Sweep” Garbage Collection?

3 replies [Last post]
msherbert
Offline
Joined: 2007-05-14

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
luke_sleeman
Offline
Joined: 2006-06-26

The documentation for OutOfMemoryError seems to imply that garbage collection will be run before the JVM gives up and throws OutOfMemoryErrors:

http://java.sun.com/javase/6/docs/api/java/lang/OutOfMemoryError.html

Your message doesn't make it clear if you are getting OutOfMemoryErrors or java.exe is crashing due to exhausting all the physical and virtual memory the OS has available. If you are getting OutOfMemoryErrors you definately have a memory leak. If java.exe is crashing try fiddling around with the maximum amount of memory the JVM can request from the OS. I believe that there is some sort of -X flag for setting it.

- Luke

msherbert
Offline
Joined: 2007-05-14

When the application crashes, the errors that I get are not always the same. In some cases, I see something like:

Exception java.lang.OutOfMemoryError: requested 16 bytes for CHeapObj-new. Out of swap space?

This error is described in:
http://blogs.sun.com/alanb/entry/outofmemoryerror_looks_a_bit_better

I believe it is caused by all the instances of my application growing so large – Solaris is just running out of system resources. So, based on the input I have received and further investigation, I believe the root cause is a memory leak. We are now trying TPTP to isolate it. Of course, we could also try tweaking some of the JVM parameters, so that the “Mark Sweep” GC is invoked more frequently. But this seems like a “bandaid” solution.

Thanks for the pointers,
Mike H.

christian_schli...
Offline
Joined: 2005-05-21

Hi,

as you figured, a sane Java application should not call System.gc() or System.runFinalization() except for very, very special cases - the only one I can think of is to release OS resources in a finalizer if a client has forgot to explicitly "close" the resource.

From what you're saying, it sounds your app is suffering from a memory leak. Instead of messing with the garbage collector, I'ld recommend to fix it. I use jhat/jmap that comes with any recent JDK to do this. Quite effective, although the UI could be advanced (NetBeans?).

Kind regards,
Christian