wood burning stoves 2.0*
The moose likes Java in General and the fly likes Forcing Full GC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Forcing Full GC" Watch "Forcing Full GC" New topic
Author

Forcing Full GC

krishna bulusu
Ranch Hand

Joined: Aug 28, 2006
Posts: 185
Hi,

We would like to run Full GC for every 1 hour on our production system. What I found was, be setting below JVM parameters, we can force the Full GC on the JVM heap.

-Dsun.rmi.dgc.client.gcInterval=3600000
-Dsun.rmi.dgc.server.gcInterval=3600000


Can somebody tell me the real purpose of the above statements? Would Full GC run every 1 hour and all the unreachable objects gets cleaned by the full GC which was triggered by above parameters?

I read some where that, only RMI objects which are unreachable gets cleaned by the above JVM Parameters.
Please can somebody help me?


Thanks&Regards, Krishna.
SCJP1.4, SCWCD1.4, SCBCD 5.0
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3418
    
  12
Your question is a little ambiguous.

This suggests that you have tried it and it did force a full GC
krishna bulusu wrote:What I found was, be setting below JVM parameters, we can force the Full GC on the JVM heap.


Yet here you appear to be asking if if a full GC would happen.
krishna bulusu wrote:Would Full GC run every 1 hour and all the unreachable objects gets cleaned by the full GC which was triggered by above parameters?


Have you tried it and if so, what happened ?
I would be surprised if it did force a full GC as those parameters are related only to RMI GC.


Joanne
krishna bulusu
Ranch Hand

Joined: Aug 28, 2006
Posts: 185
Hi,

Thanks for your reply.
I will Explain my question in more detail.
We have the below JVM parameters on our production system:

-Dsun.rmi.dgc.client.gcInterval=3600000
-Dsun.rmi.dgc.server.gcInterval=3600000


We observed on the logs that, Full GC is happening in every 1 hour. Below is the sample Log satement.

3780.425: [Full GC [PSYoungGen: 17367K->0K(484544K)] [ParOldGen: 687597K->404076K(1094848K)] 704964K->404076K(1579392K) [PSPermGen: 50827K->50247K(101120K)], 1.3162930 secs]

After 24 hours of the server restart, I have taken the heap dump of my production JVM. Its about 1.5GB.
After given it to the Eclipse Memory Analyzer, the size comes to 140MB!!(Eclipse Memory analyzer parsed it and removes all the unreachable objects.) The Eclipse Memory analyzer shows that, the Unreachable objects size is about 1.3GB!!

Can I assume that, after running the Full GC every hour by below JVM parameters, the unreachable objects should be cleaned up? Does the below JVM parameters forces Full GC which claims the unreachable objects (or) its related to RMI objects only?

-Dsun.rmi.dgc.client.gcInterval=3600000
-Dsun.rmi.dgc.server.gcInterval=3600000
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

As far as I know, RMI objects only.

I'd *really* still recommend using a full-on memory profiler, not a heap dump analyzer, to find out what physical memory is actually being used, and by what.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37926
    
  22
I didn't think it was possible to "force" the garbage collector to execute.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3418
    
  12
Campbell Ritchie wrote:I didn't think it was possible to "force" the garbage collector to execute.


RMI distributed garbage collection runs at regular intervals. These two variables can be used to alter what that interval is.
krishna bulusu
Ranch Hand

Joined: Aug 28, 2006
Posts: 185
Hi,

Thanks for your replies.
Is there any way to 'request' Explicit GC(System.gc()) if we can't force it?
For our production, it would be very useful for us to clean up the unreachable objects in regular basis instead of having them on our heap and let the GC clean them when it is short by memory.


David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

System.gc() is how you request GC. But the chances if you handling memory better than the JVM are very, very low: it'll reclaim memory when needed. This kind of manual memory management is almost *never* needed in server apps.
Gaurav Raje
Ranch Hand

Joined: Jul 23, 2010
Posts: 136
i think you asked a very sensitive question.... Ive seen quite a few threads flood with highly emotional responses about how "You can never force a GC" and "All you can do is suggest a GC".

Indeed. System.gc is the best way to go about it. But it depends on the platform. It has been known to not do anything(Quote kathy sierra and bert bates - scjp 6 ). In most of the platforms however for a very high percentage of times, it will run the GC. I know that whenever I have tried on windows, to test it, Ive seen it run. But this is not guaranteed. This is like saying the higher priority thread started first will run first. Even though this is true most of the times, its not something you can rely on.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Forcing Full GC
 
Similar Threads
100% CPU usage on JBoss with 8GB memory
Garbage Collection Help!
GC kicking in a bit too regularly...!
JBoss performance decrease
Heap used for a simple program seems too much