axiom-objc-block-retain-cycles

Diagnose and fix Objective-C block retain cycles in ARC apps.

Updated Dec 23, 2025
One-click install
npx skills add https://github.com/pradeepmouli/swift-template --skill axiom-objc-block-retain-cycles-pradeepmouli
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: axiom-objc-block-retain-cycles
Source: https://github.com/pradeepmouli/swift-template/tree/main/.agents/skills/axiom-objc-block-retain-cycles
Command: npx skills add https://github.com/pradeepmouli/swift-template --skill axiom-objc-block-retain-cycles-pradeepmouli

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Block retain cycles in Objective-C cause memory leaks when blocks capture self and are retained by the object that owns them, leading to memory growth and potential crashes. This skill provides a structured, repeatable approach to diagnose and fix such leaks using a mandatory weak-strong pattern and a clear decision tree.

Core Features & Use Cases

  • Systematic diagnosis of block retain cycles with a four-pattern framework (Pattern 1–4) and explicit guard rules.
  • Guidance for nested blocks, hidden self references in macros, and cross-block retention pathways.
  • Real-world workflows for iOS/macOS apps, ARC, and network callbacks to ensure memory is released when UI or controllers are dismissed.

Quick Start

Apply the weak-strong pattern to every block capturing self and verify memory release with Instruments.

Frequently Asked Questions about axiom-objc-block-retain-cycles

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix an Objective-C block retain cycle causing memory leaks?

Fix an Objective-C block retain cycle by applying a weak-strong pattern to break the strong reference chain, preventing the block and its owning object from retaining each other indefinitely. Use Instruments to verify memory is released.

Why does my iOS app leak memory when using network callbacks with blocks?

iOS apps leak memory during network callbacks when blocks capture self strongly and are retained by the controller, creating a retain cycle. Apply guard conditions and weak-strong references to ensure safe memory release.

How do I identify hidden self references in Objective-C blocks?

Identify hidden self references in Objective-C blocks by inspecting macros and nested blocks for implicit captures. A diagnostic framework helps trace cross-block retention pathways that bypass standard weak-strong checks. Apply guard conditions to secure them.

What is the best way to diagnose memory leaks in ARC apps using Instruments?

The best way to diagnose memory leaks in ARC apps is using Instruments to trace allocations, while systematically applying a four-pattern decision tree to identify block retain cycles and verify memory release upon UI dismissal.

Do I need a weak-strong pattern for every block capturing self in Objective-C?

Yes, the weak-strong pattern is mandatory for every block capturing self in Objective-C to prevent retain cycles. Guard conditions must also be applied to handle nested blocks and cross-block retention safely. Verify release with Instruments.

How do nested blocks cause retain cycles in macOS and iOS apps?

Nested blocks cause retain cycles in macOS and iOS apps when inner blocks capture strong references established by outer blocks. A diagnostic framework resolves this by applying specific guard rules and tracing cross-block retention pathways.