Objective-C ARC Patterns

Diagnose ARC memory-management issues in Objective-C projects.

187|20|Updated Nov 20, 2025
One-click install
npx skills add https://github.com/TheBushidoCollective/han --skill objective-c-arc-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Objective-C ARC Patterns
Source: https://github.com/TheBushidoCollective/han/tree/main/jutsu/jutsu-objective-c/skills/objc-arc-patterns
Command: npx skills add https://github.com/TheBushidoCollective/han --skill objective-c-arc-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill covers ARC ownership rules, strong/weak references, retain cycles, and memory-safe patterns in Objective-C.

Core Features & Use Cases

  • Strong/Weak References: Correct ownership and lifetime management.
  • Retain Cycles: Techniques to avoid memory leaks in blocks and delegates.
  • Bridging: Safe bridging with Core Foundation.

Quick Start

Annotate properties with strong/weak and implement a weak delegate to avoid a retain cycle.

Frequently Asked Questions about Objective-C ARC Patterns

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

FAQPage Schema
How do I prevent retain cycles in Objective-C blocks and delegates?

Retain cycles occur when strong references create circular ownership. Use weak references for delegates and in block captures: declare properties with `__weak` or `weak` qualifiers, or capture `self` weakly in blocks using `__weak typeof(self) weakSelf = self;` to break the cycle and enable proper memory deallocation.

What's the difference between strong and weak references in ARC?

Strong references increase an object's retain count and keep it alive; weak references do not. Use strong for ownership and weak for back-references (delegates, observers) to avoid cycles. ARC automatically manages both, but incorrect qualification causes leaks or premature deallocation.

How do I safely bridge between Objective-C and Core Foundation?

Use bridging casts with ownership semantics: `(__bridge)` for zero-cost casts, `(__bridge_retained)` when passing to Core Foundation (transfers retain), and `(__bridge_transfer)` when receiving from Core Foundation. Incorrect bridging causes memory leaks or crashes due to mismatched retain counts.

Can I use ARC with asynchronous callbacks and dispatch blocks?

Yes, but capture `self` carefully. In dispatch blocks and async callbacks, capture `self` weakly to avoid retain cycles: convert to a strong reference inside the block only if needed. This prevents blocks from keeping the object alive longer than intended.

Why does my iOS app leak memory with delegate patterns?

Delegate properties often create retain cycles if declared strong. The owner retains the delegate, and the delegate retains the owner. Declare delegate properties as `weak` to break the cycle: `@property (nonatomic, weak) id<MyDelegate> delegate;`

What ownership qualifiers should I use for Objective-C properties?

Use `strong` for owned objects (default in ARC), `weak` for back-references and delegates, `copy` for immutable objects like NSString, and `assign` only for primitive types. Correct qualifiers prevent retain cycles and ensure predictable object lifetimes.