liveBook · Manning

Referrer

As explained in Troubleshooting Java, Second Edition

A referrer is an object or runtime entity that holds a reference to another object.

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

How Troubleshooting Java, Second Edition covers it

How deep it goes
Explains referrers through OQL queries, uniqueness, counting, and garbage-collection interpretation.
Examples
Uses Product instances, a retaining list, unique referrer queries, and referral counts.
What it assumes
Assumes heap-dump and OQL-console use while defining referrers through object retention.
What you can do after
Diagnose/debug memory leaks by querying which objects retain selected instances.
How it connects
Connects referrers with heap dumps, OQL, garbage collection, object references, and memory leaks.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Troubleshooting Java, Second Edition. The section links point to the parts of the book it draws on.