Garbage collection is totally JVM dependent... Some JVMs may use a mark and sweep algorithm. The first thing u should understand abt Java's garbage collection is totally unpredicatble. You cant really predict when garbage collection is done. If and when the JVM decides that garbage coll should be run, it checks all objects, and those objects which have no references to it will be deleted from the heap memory. System.gc() makes a request to the JVM to run the garbage collection mechanism. But its a bad practice to call it, because you cant really be sure that JVM will not choose to ignore it. Moreover you can safely ignore it cos the JVM, most probably is smarter than you, and knows when to run the garbage collection mechanism on its own...
On Sat, Jul 30, 2011 at 11:40 PM, vaibhav shukla <[email protected]>wrote: > please give a glimps of how garbage collection is done in java. > how *System.gc()* works ? > > -- > best wishes!! > Vaibhav > > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- Regards, Deepthi -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
