Apple & iOS
AuraScore 79/100

iOS Memory Leak and Retain Cycle Remediation Plan

Construct a systematic diagnosis and remediation plan to eliminate memory leaks, retain cycles, and OOM terminations in iOS apps.

Deploy this template when investigating critical memory pressure crashes, deallocation failures, and background memory terminations in iOS applications. It guides performance leads to trace retain graphs and structure deterministic fixes.

Template

Role: Principal iOS Performance and Debugging Engineer specializing in Memory Graph Analysis and Xcode Instruments diagnostics.

Context

  • Target iOS module: {{app_module_name}}
  • Metric or crash signal: {{crash_rate_metric}}
  • Target screens or user flows: {{affected_screens}}
  • Diagnostic traces and tool findings: {{instruments_findings}}
  • Target hardware profile: {{reproduction_device_matrix}}

Task

Formulate a rigorous debugging, remediation, and architectural containment plan to eliminate retain cycles, unbounded memory growth, and Jetsam OOM crashes in {{app_module_name}} across {{affected_screens}} based on {{instruments_findings}}.

Method

  1. Evaluate the provided {{instruments_findings}} to isolate strong reference cycles, lingering closures, and delegate retain patterns.
  2. Map the object lifecycle graph from initial view controller presentation to dismissal within {{affected_screens}}.
  3. Identify external observer subscriptions (Combine AnyCancellable bags, NotificationCenter, KVO) failing to unregister.
  4. Design deterministic memory leak isolation unit tests utilizing weak references and expectation fulfillments.
  5. Formulate refactoring guidelines replacing implicit self captures with structured capture lists ([weak self]).
  6. Establish image/asset cache limits and background purge routines tailored to {{reproduction_device_matrix}}.
  7. Detail a continuous regression prevention pipeline incorporating MemGraph CI assertions to stabilize {{crash_rate_metric}}.

Constraints

  • MUST provide actionable code-level fixes rather than generic deallocation advice.
  • MUST NOT permit unconstrained memory footprints under background execution transitions.
  • All proposed fixes MUST be verifiable via Xcode Memory Graph Debugger or Instruments Leaks template.
  • Avoid introducing force unwrap patterns when unwrapping weak self captures.

Output format

Provide the remediation plan in the following structure:

  1. Root Cause & Retain Graph Breakdown (max 200 words)
  2. Step-by-Step Code Remediation Strategy (ordered by priority)
  3. Automated Regression Verification Plan (unit test & CI memory assertions)
  4. Target Metric Milestones (measurable recovery targets for {{crash_rate_metric}})

Self-review

  • Verify that the plan directly resolves observations in {{instruments_findings}}.
  • Confirm that hardware limits for {{reproduction_device_matrix}} are considered in cache sizing.
  • Check that weak reference capture rules are explicitly detailed without dangerous force-unwraps.
AuraScore breakdown
79/100Provisional
Instruction clarity15/15 · Strong

Explicit role, a named task, and discrete steps the model can follow.

Context architecture12/12 · Strong

Background, inputs and variables the model needs before it starts.

Constraint engineering10/12 · Adequate

Hard boundaries — what the model must and must not do.

Output specification6/14 · Thin

A named, field-level shape for the response.

Reasoning structure10/10 · Strong

Ordered work items that force analysis before an answer.

Model compatibility10/10 · Strong

Length and structure that travel across frontier models.

Token efficiency5/10 · Thin

Signal density — instruction weight without padding.

Reusability7/7 · Strong

Documented variables so the scaffold adapts to new inputs.

Robustness3/5 · Adequate

Quality bar, assumptions and behaviour when inputs are thin.

Observed performance1/5 · Thin

How much real usage the template has behind it.

developers
developers-apple
software-engineering-debugging
memory-management
debugging
instruments