The moose likes Java in General and the fly likes How you say that JVM does not guarantee Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How you say that JVM does not guarantee" Watch "How you say that JVM does not guarantee" New topic

How you say that JVM does not guarantee

Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Posts: 293
I read that You can't force GC, but could request it by calling System.gc().
JVM does not guarantee that GC will be started immediately.
My question is how you say JVM doesnot guarantee, can we check that.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074

What do you mean exactly? Are you asking what the sentence "does not guarantee" means?

It just means exactly what it says: if you call System.gc(), the JVM might or might not perform a garbage collection immediately. According to the Java specification it is not required to do a garbage collection if you call System.gc(). It might, but you can't be sure.

Note that normally you should not call System.gc(). It's only for special circumstances, when you know there is a problem (for example, you've noticed that the program pauses at a certain moment because the JVM is doing garbage collection at an inconvenient moment). In that case calling System.gc() at an appropriate moment might help. But almost always you should just leave the garbage collector alone, because in general it does its job well without needing intervention. (In fact, you might even make garbage collection less efficient by calling System.gc()).

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Posts: 293
No, My interviewer asked how you say that you cannot force garbage collection.
what should i reply
Darryl Burke

Joined: May 03, 2008
Posts: 4523


luck, db
There are no new questions, but there may be new answers.
I agree. Here's the link: http://aspose.com/file-tools
subject: How you say that JVM does not guarantee
Similar Threads
Problem of freeMemory()?
Concurrent Mark Sweep Vs Garbage 1 GC
finalize() method.
Q from Marcus Green jdk1.4 exam
Help In System.GC