Knowledgebase

iOS Memory Management Print

  • mobiledevelopment, mobile, guide, howto, solution, zillionkinghost, hosting, support
  • 0

Reference counting in practice.

WHAT THE MODEL IS

Memory released when nothing references it, tracked automatically.

WHAT THAT AVOIDS

A garbage collector, and its pauses.

WHAT IT REQUIRES ATTENTION TO

Reference cycles.

WHAT A CYCLE IS

Two objects holding strong references to each other, so neither is ever released.

WHERE THEY COMMONLY OCCUR

Closures capturing the object that owns them Delegate relationships Parent and child references

WHAT SOLVES IT

Declaring one reference as not owning.

WHAT THE TWO NON-OWNING KINDS ARE

One becoming empty when the object is released One assuming the object outlives it, crashing if not

WHAT TO PREFER

The safer of the two, unless you are certain.

WHAT TO DO IN CLOSURES

Capture the owning object weakly, and check it still exists.

WHAT A LEAK LOOKS LIKE

Memory rising as screens are opened and closed, never falling.

WHAT TO USE TO FIND THEM

The instrumentation tools, showing retained objects and cycles.

WHAT TO TEST

Opening and closing a screen repeatedly, watching memory.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot