Garbage Collector

How does garbage collector decide which objects are to be removed? Can garbage collector be forced?

Questions by Darsh_singh

Showing Answers 1 - 9 of 9 Answers

shivdeep87

  • Oct 27th, 2010
 

Garbage collector is invoked by JVM automatically.
This function checks for all the object in heap memory and whether oject are having any refrence or not.
If an object does have any refrence variable, means it is unreachable then garbage collector frees that memory.


By using system.gc() commond we can run garbage collector forcefully.

KhyatiK

  • Nov 11th, 2010
 

Garbage collector removes those objects from heap memory which are no longer referred by any other objects.
Using System.gc() you can call garbage collector but its not neccesary that it will run.
JVM decides when the Garbage Collector will run.

Garbage collector is used to collect those objects in the Heap memory which is not referenced by any reference variable by calling System.gc() method. The purpose of GC is to delete objects that can't be reached. Only the JVM decides when to run the GC, you can only suggest it.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions