This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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
Author

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
    
  16

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
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

http://java.sun.com/docs/books/performance/1st_edition/html/JPAppGC.fm.html


luck, db
There are no new questions, but there may be new answers.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How you say that JVM does not guarantee
 
Similar Threads
Concurrent Mark Sweep Vs Garbage 1 GC
Problem of freeMemory()?
finalize() method.
Q from Marcus Green jdk1.4 exam
Help In System.GC