A referrer is an object or runtime entity that holds a reference to another object. In a heap dump, finding referrers shows what keeps an object reachable and may prevent garbage collection. section 10.3
Use referrer analysis to investigate:
- Objects that may retain leaked instances. section 10.3
- Long-lived reference paths and instances preventing garbage collection. section 10.3
- Duplicate objects or class relationships visible without source inspection. section 10.3
Finding the object retaining Products
Query Product instances with select unique(referrers(p)) from model.Product p. If one list refers to many Product objects, that list may keep them reachable and indicate a memory leak. Count referrals with select { product: p.name, count: count(referrers(p))} from model.Product p. section 10.3
Figure 10.14 Selecting all the unique referrers for instances of a type shows you if there’s one object that prevents the GC from removing the instances from memory. This can be a quick way to identify a memory leak.
Inspect the heap-dump result showing unique referrers and the object that may prevent garbage collection. section 10.3
