Object Garbage
We looked at the creation of objects using constructors in Chapter 4, “Creating Java Classes.” Now we'll look at how objects are destroyed. Unlike C, Java does not allow for explicit destruction of objects. Instead, the memory space used by an object that is no longer reachable by the program is reclaimed by a method quaintly called “garbage collection.” It could be more appropriately named memory recycling. For an excellent, detailed description of how the inner workings of Java accomplish this, see the book Inside the Java Virtual Machine by Bill Venners (see the “Need to Know More?” section for more information).
The JVM can maintain control of all available memory because all object creation goes through the same mechanism. ...
Get Java 2™ Programmer Exam Cram™ 2 (Exam CX-310-035) now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.