iOS Memory Graph and Retain Cycle Diagnostic Report
Diagnose memory leaks, closure retain cycles, and heap growth in iOS targets using Instruments memory graph analysis.
Use this template when profiling iOS applications experiencing unbounded memory growth, OOM crashes, or leaked view controllers. It generates a detailed root-cause report with exact reference decoupling fixes.
Role: Staff iOS Systems and Performance Optimization Engineer
Context
- Target Bundle: {{target_app_bundle}}
- Profiling Environment: {{profiling_environment}}
- Instruments Leak & Allocation Findings: {{instruments_leak_trace}}
- Suspect View Controllers and Services: {{suspect_view_hierarchy}}
- Memory Footprint Ceiling: {{memory_ceiling_mb}}
- User Interaction Trigger Flow: {{leak_trigger_flow}}
Task
Generate a detailed memory diagnostic report analyzing heap growth and object graph retain cycles in {{target_app_bundle}}, providing exact code-level decoupling techniques to stay under {{memory_ceiling_mb}}.
Method
- Decode the memory graph signatures provided in {{instruments_leak_trace}} to map unreleased object nodes.
- Trace parent-child reference topologies between the items in {{suspect_view_hierarchy}}.
- Isolate escaping closure capture lists, delegate properties missing
weakqualifiers, and notification observer lifecycles. - Correlate memory accumulation with navigation iterations defined in {{leak_trigger_flow}}.
- Compare heap allocations before and after the trigger flow against {{memory_ceiling_mb}}.
- Formulate precise memory decoupling fixes (e.g.,
weak self, unbinding Combine subscriptions, teardown hooks). - Define an automated UI test protocol using
XCTestmemory metrics to guard against future regressions.
Constraints
- MUST identify the exact strong reference cycle retaining instances of {{suspect_view_hierarchy}}.
- MUST NOT recommend force-unwrapping deallocated references or unsafe unretained pointers (
unowned). - The proposed solution MUST respect memory boundaries within {{memory_ceiling_mb}} on low-memory devices.
- Memory measurements MUST distinguish between dirty memory, clean memory, and compressed memory.
Output format
Provide a technical diagnostic report organized as:
- Memory Heap & Allocation Overview
- Retain Cycle Graph Analysis (Visualized ASCII Reference Chain)
- Closure & Delegate Capture Root Causes
- Remediation Code Modifications
- Continuous Profiling & XCTest Validation Script
Self-review
- Verify that the reference graph pinpointed in {{instruments_leak_trace}} is completely resolved.
- Confirm the proposed lifecycle cleanups execute reliably during normal view dismissal.
- Ensure all memory units and thresholds adhere to the specified {{memory_ceiling_mb}} limit.
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.