Contents |
by Monica Pawlan
of the Java Developer Connection (JDC)The Reference Objects application programming interfaces (API) let a program maintain special references to objects that allow the program to interact with the garbage collector in limited ways. Not all programs require this level of interaction with the garbage collector. For example, a program that keeps a lot of objects in memory or a program that needs to perform cleanup operations on related objects before an object is reclaimed might be good candidates for using the Reference Objects API.
- A web-based program might display a lot of images when an end user goes to a particular page on the web. If the end user leaves the page, it is not always certain he or she will return. Such a program can use reference objects to create a situation where the garbage collector reclaims the images when heap memory runs low. In the event the end user returns to the page, the program can reload the image if it has been reclaimed.
- A program can use a reference queue to create a situation where the program is notified when a certain object is reachable only through reference objects. Upon notification, the program can proceed with clean-up operations on other related objects to make them eligible for garbage collection at the same time.
Because it is essential to understand garbage collection before you can understand how reference objects work, this trail begins with a lesson on garbage collection and concludes with a lesson on reference objects:
Understanding Garbage Collection explains how garbage collection works in the Java Virtual Machine (VM) and what happens when reference objects are added to the heap.
All About Reference Objects covers everything you need to know to use reference objects in applications.
Note: This is a draft! Please send comments and suggestions on this trail to tutorial@java.sun.com. Put Reference Objects in the subject. Your feedback is important to us.
Contents |