Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How you say that JVM does not guarantee

 
Rajendra Prakash
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15490
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()).
 
Rajendra Prakash
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, My interviewer asked how you say that you cannot force garbage collection.
what should i reply
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://java.sun.com/docs/books/performance/1st_edition/html/JPAppGC.fm.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic