Sun Certification Training Guide (310-025, 310-027): Java™ 2 Programmer and Developer Exams
by Jamie Jaworski
How Does the Garbage Collector Work?
The Java garbage collector helps recycle memory and other resources when they are no longer needed. It consists of a separate low-priority 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 needed, it becomes subject to garbage collection.
At this point, you are probably wondering what it means for an object to be no longer needed and how the garbage collector determines which objects are needed and which are not. A program does not need an object that is no longer in use or that cannot be brought back into use. The garbage collector determines that an object cannot be used if it is no longer reachable by the program. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access