How does Garbage collector locate Garbage?

Sumit Jolly

Sumit Jolly

Aug 01, 2014

    There are three generations. Gen0, Gen1, Gen2 Whenever objects are created they are kept into Gen0 bucket. Garbage collector visits to Gen0 quite frequently. if any objects are are not referencing to any anybody, in other terms if it is assigned to null, then this object is moved to garbage collection queue from there the object is removed.longer the object resides into Gen0 its is subsequently moved to Gen1 and then Gen2 buckets.

    sarang Chandaikar
    August 07, 2014

    Garbage Collection is a memory management and automatically recycling the heap memory. The collector recycles the memory that is not referencing and that can prove will never be used again. By collector it is assumed that when something is no longer needed, it is no longer referenced. This can be detected and the widget collected. Reference Counting: each object contains a counter saying how many references to it there are. When you refer to an object, you increment the counter. When you're done with it, you decrement the counter. When the counter reaches 0, the object can be recycled.Stop And Copy: The heap is divided into two regions. One contains objects, and the other is empty. You recursively traverse all the objects in the first region (as in mark-and-sweep), copying them into the second region. Then you interchange the roles of the two regions. No need to scan the unused objects in the first region.

    Raghav Mehra
    August 26, 2014

    By using WeekReference Object it will find out the unused object and it will clear.

    lv prasad
    August 16, 2014