rxswift-memory-check

Analyze RxSwift subscriptions for disposal checks and retain cycles.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/daispacy/py-claude-marketplace --skill rxswift-memory-check
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rxswift-memory-check
Source: https://github.com/daispacy/py-claude-marketplace/tree/main/py-plugin/skills/rxswift-memory-check
Command: npx skills add https://github.com/daispacy/py-claude-marketplace --skill rxswift-memory-check

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill quickly identifies common RxSwift memory management issues like missing dispose bags, retain cycles, and strong self references, preventing memory leaks and app crashes. It automates a critical debugging step, saving hours of manual investigation and improving app stability.

Core Features & Use Cases

  • Subscription Validation: Verifies every .subscribe() call has proper disposal (.disposed(by: disposeBag)) and [weak self] usage in closures to prevent retain cycles.
  • Anti-pattern Detection: Flags common mistakes such as local DisposeBag declarations (leading to early cancellation) and strong self captures within Observable chains.
  • Use Case: If your iOS app is experiencing unexplained memory growth or crashes, activate this Skill to scan your RxSwift code and pinpoint exact locations of potential memory leaks, providing immediate fixes and best practice guidance.

Quick Start

Check 'UserViewModel.swift' for RxSwift memory leaks.

Frequently Asked Questions about rxswift-memory-check

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

FAQPage Schema
How do I detect memory leaks in RxSwift subscriptions?

Memory leaks in RxSwift occur when subscriptions aren't properly disposed or hold strong references to `self`. Detect them by verifying every `.subscribe()` call uses `.disposed(by: disposeBag)` with a property-level DisposeBag, checking for `[weak self]` in closures, and scanning for local DisposeBag declarations that cause premature cancellation. Tools that analyze subscription patterns and flag retain cycles pinpoint exact leak locations with remediation guidance.

What causes retain cycles in RxSwift and how do I prevent them?

Retain cycles occur when Observable chains capture strong `self` references without `[weak self]` or `[unowned self]` capture lists, creating circular references that prevent deallocation. Prevent them by always using weak or unowned captures in subscription closures, ensuring subscriptions are disposed via property-level DisposeBags, and avoiding local DisposeBag instances that dispose prematurely. Static analysis identifies these patterns before they cause memory growth.

Do I need a DisposeBag for every RxSwift subscription?

Yes—every RxSwift subscription should be disposed by a property-level DisposeBag to prevent memory leaks and ensure proper cleanup. Local DisposeBags dispose immediately when leaving scope, canceling subscriptions prematurely. Property-level DisposeBags tied to object lifecycles ensure subscriptions persist for the intended duration and clean up when the object deallocates.

How do I find strong self references in RxSwift code?

Strong self references in RxSwift closures (`.subscribe()`, `.map()`, `.flatMap()`) create retain cycles. Find them by scanning for closures that access `self` without `[weak self]` or `[unowned self]` capture lists. Automated analysis flags these locations, shows severity, and provides exact lines where strong captures occur in view models and services, enabling quick remediation.

What's the difference between local and property DisposeBags?

Property-level DisposeBags are instance variables that persist with the object and dispose subscriptions when the object deallocates—the correct pattern. Local DisposeBags are stack variables that dispose subscriptions immediately when exiting scope, causing premature cancellation and breaking Observable chains. Always use property-level DisposeBags for RxSwift subscriptions.

Can memory leak detection work across iOS ViewModels and services?

Yes. Memory leak detection analyzes RxSwift subscriptions across ViewModels, services, and other components by checking disposal patterns, weak/unowned self usage, and DisposeBag placement everywhere subscriptions occur. It generates structured reports showing leak locations, severity, and fixes applicable to your entire RxSwift architecture.