Posts

Showing posts from April, 2023

Garbage Collection

 1. Garbage collection is a mechanism of requiring the heap space by destroying all unused/unreferenced objects which are eligible for garbage collection from the heap memory. 2. Garbage collector is a demantbead(low priority thread). 3. Garbage collector always runs in the background of every java program. 4. The algorithm which is used by garbage collector is marked and sweep algorithm. 5. Garbage collection is not process of collecting and discards dead objects. It is more like making the "live"  objects(all objects that are reachable from Java and destroy all other objects.) 6. In our java program no need to call the garbage collector manually, but if we want to call the garbage collector manually we can do that in two ways:     a. By using system class (System.c()) - It is a static method.     b. By using Runtime class-               Runtime r=Runtime.getRuntime();             ...