What problem does it solve?
This Skill provides a systematic approach to diagnose and fix Objective-C block retain cycles, the leading cause of memory leaks, app crashes, and "sending message to deallocated instance" errors. It prevents silent memory accumulation and ensures app stability.
Core Features & Use Cases
- Systematic Diagnosis: Mandatory first steps using Instruments (Allocations, Memory Debugger) to confirm, trace, and understand retain cycles.
- Weak-Strong Pattern Enforcement: Detailed guidance on correctly applying the
__weak typeof(self) weakSelf = self; and if (strongSelf) pattern to break cycles.
- Hidden Capture Detection: Identifies subtle
self captures within macros (e.g., NSAssert, NSLog) and ensures proper guarding in nested blocks.
- Use Case: When a
UIViewController isn't deallocating after being dismissed, use this skill to systematically check for self references in any blocks assigned to properties or network operations, then apply the weak-strong pattern to break the cycle.
Quick Start
To diagnose a suspected block retain cycle, first use Instruments' Allocations template to confirm memory isn't returning to baseline after dismissing a screen.