Garbage collection is a method to detect and collect free nodes. The node which is in use and allocated are not detected whereas any no longer in use is recovered.
When a request is made for additional nodes and there are none available, then a system routine is called garbage collector searches through all of the nodes in the system and identifies those that are no longer accessible from an external pointer, and restores the inaccessible nodes to the available pool.
The Process of garbage collection takes place into two-phase. The first phase is called making phase, where all nodes are accessible from an external pointer are marked.
The second phase is called the collection phase, involves proceeding sequentially through memory and freeing all nodes that have not been marked. This second phase is trivial when all nodes are of fixed size. In this case, the second phase requires only the examination of each node to see whether or not it has been marked.
If there are a total of n nodes then the second phase of garbage collection can be carried out in O(n) steps. In this situation, it is only the first or marking phase that is of any interest in designing the algorithm.
When variable size nodes are in use, it is desirable to compact memory so that all free nodes from a contiguous block of memory. In this case, the second phase is referred to as memory compaction of disk space to reduce average retrieval time is desirable even for fixed-size nodes.
Garbage collection is a simple phenomenon of releasing the memory from those objects which are no longer used in the program. When we create a variable function or any object while developing the program then once the use of these objects is over the garbage collector detects all such object and free the memory block by taking the resource from these objects, so that it can be used by another variable or function.
In the case of any queries, you can write to us at firstname.lastname@example.org we will get back to you ASAP.
Hope! you would have enjoyed this post about Garbage collection.
Please feel free to give your important feedbacks in the comment section below.
Have a great time! Sayonara!