Chapter 7, “Garbage Collection”

The Java garbage collector consists of a separate thread of execution that executes in the background and keeps track of all the objects that are used in a Java program. When an object is no longer reachable, it becomes subject to garbage collection.

A reachable object is an object that can be accessed directly or indirectly through the variables that are currently available to the program. An unreachable object is an object that is no longer reachable.

When an object becomes subject to garbage collection, it is not necessarily garbage collected immediately. It might, in fact, never be garbage collected. The program might terminate before the garbage collector gets around to reclaiming the object. Being subjected to garbage collection simply means that an object is eligible to be reclaimed when the garbage collector gets around to reclaiming the object's resources.

Because the garbage collector runs asynchronously to your program (as a separate thread), you can't predict when it will execute, which unreachable objects it will reclaim, and when it will reclaim those objects.

If an object becomes unreachable, it is not guaranteed that the object's finalize() method will be invoked. However, if an object does have a finalize() method, this method will be invoked before the object is garbage collected.

When an object's finalize() method is invoked, the object can perform an action that will make it reachable again.

After an object's finalize() method has completed its processing and returned to the garbage collector, the garbage collector performs no reclamation processing until the garbage collector has again identified the object as being unreachable and subject to collection.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.48.181