• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is the purpose System.gc()  RSS feed

 
manju anandan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the purpose System.gc() when itcannot force garbage collection.Java 2Std Edition API says "Calling the gc method suggests that the Java Virtual Machine expend effort toward recycling unused objects ".It suggests but doent force.Say the JVM starts garbage collection when this method is called, will it SLOW DOWN THE APPLICATION MEMORY? IF IT SLOWS DOWN THEN WHY SHOULD IT BE CALLED?
UNDER WHAT CONDITIONS SHOULD THIS METHOD BE CALLED.HOW DOES IT HELP THE PROGRAMMER?
 
Vicky Jain
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yups, you are right, making a call to this method is just to make a request to the scheduler to run the garbage collector and it may also reject your request completely.
You cannot force the scheduler to perform the garbage collection
When JVM starts collecting unreachable object from the heap (Garbage Collection) it may insert some pauses to your application.
Vivek Jain
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is seldom a good time to call this method <cynic>(despite it's popularity among The Misinformed)</cynic>
This is because there is a huge effort put into GC routines regarding efficiency, and attempting (I assume you understand that this is an attempt) to override these routines with a relatively poorly-thought-out "suggestion" is hardly a good reason.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!