How To Make Object Eligible For Garbage Collector In Java
Posted By : Nanda Ram | 22-Sep-2017
In the old language like c++, creation and destruction of the object is a responsibility of programmer only. Usually, programmer taking very much care while creating objects and his/her neglecting destruction of useless objects due to this neglecting at the certain point of time for the creation of new object sufficient memory may not be available and the entire program will be collapse due to the memory problem. But in java, a programmer is responsible only for the creation of objects and he is not responsible for the destruction of useless objects.
Some people provided one assistant which is always running in the background for the destruction of useless objects. Due to this assistant the chance of failure java program with memory problems very rare. This assistant is nothing but Garbage Collector. Hence, the main objective of the garbage collector is to destroy useless objects.
The Various ways to make object eligible for Garbage Collector
Although programmer is not answerable to destroy meaningless objects, it is ever a better programming habit to make an object eligible for garbage collector if it is no continue needed. An object is said to be eligible for the garbage collector if it doesn't contain any reference. The following are the various possible ways to make an object eligible for garbage collector
1. Nullifying the reference variable
If an object is no longer required then assign null to all its references, the automatically that object eligible for a garbage collector.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Nanda Ram
Nanda Ram is a Java Developer, he keep conscientious about his task to complete it in a effective and efficient manner .