An object reference identifies an object and can keep it reachable. The garbage collector removes an object only when no remaining references make it reachable. section 5.1.1 section 10.2
Retaining references after objects are no longer needed creates a memory leak. Profiling and heap dumps reveal whether references are still required and where they are stored. section 5.1.1 section 10.2
Investigate suspicious object retention by:
- Finding types with unusually many instances or large memory usage. section 10.2
- Inspecting what each instance refers to and which objects refer to it. section 10.2
- Locating the reference in application code and deciding whether the retained object is still needed. section 10.2
A retained Product instance
A Product instance refers to its name, while an Object array in an ArrayList keeps more than one million Product references. The ArrayList is stored in a static Main variable, making it a likely memory-leak lead. section 10.2
Figure 10.8 References to an instance. By using the heap dump, you can find, for each instance, what other instances were being referenced at the time the dump was generated. The profiling tool also tells you where a given reference is stored in the code. In this case, ArrayList, which holds over one million references, is a static variable in the Main class.
Shows how a heap dump identifies the references held for an instance and locates the code storing them. section 10.2
















