liveBook · Manning

Strong reference

As explained in Fast by Default

A strong reference is an object reference that keeps its referenced object in memory while the reference exists.

A strong reference keeps its referenced object in memory while the reference exists. An object remains alive while at least one strong reference points to it; two opposing strong references can form a retain cycle that prevents release. section 7.3.3

Recognize strong-reference failures through recurring memory patterns:

  • Repeatedly visiting a screen increases memory because transaction data and decoded images remain retained after the screen disappears. section 7.3.3
  • Closures can capture their owning object, delegates can retain each other, and notification listeners can remain registered indefinitely. section 7.3.3
  • Replacing one side of a retain cycle with a weak reference breaks the cycle and allows memory to return to its starting level. section 7.3.3

Diagnosing a navigation leak

Use Allocations to compare memory before and after repeatedly opening and leaving an account overview. Use Leaks to inspect the object type, size, and reference diagram; identify the opposing strong references, then change one relationship to weak. section 7.3.3

How Fast by Default covers it

How deep it goes
Defines object lifetime and retain cycles, then stops at profiling symptoms and replacing one reference with weak.
Examples
Uses account-overview navigation, retained transaction data, decoded images, and Allocations and Leaks diagnostics.
What it assumes
Assumes familiarity with object references and introduces strong-reference lifetime behavior through profiling symptoms.
What you can do after
Diagnose/debug with Allocations and Leaks, trace retaining references, and break a retain cycle with a weak reference.
How it connects
Connects strong references to retain cycles, weak references, closures, delegates, notification listeners, and memory leaks.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Fast by Default. The section links point to the parts of the book it draws on.