Skip to main content
Glama

Review memory and retain cycles

review_swift_memory

Detect retain cycles and lifetime defects in Swift code, including strong self captures in timers, observers, Combine sinks, and escaping closures. Use when memory grows or deinit never fires.

Instructions

Check a Swift project for retain cycles and lifetime defects: repeating Timers and block-based NotificationCenter observers capturing self strongly, Combine sinks stored in a cancellables set owned by the same object, non-weak delegate properties, stored closure properties capturing self, unowned self in escaping closures, and long-running unstructured Tasks that keep an object alive after its screen is gone. Use when memory grows over time, when deinit is never called, or before shipping a screen with timers or subscriptions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesAbsolute path to the Swift project root (the folder containing Package.swift or the .xcodeproj).

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
scoreYes0-100 defect density. 100 = no findings. penalty = 10*blockers + 3*serious + 1*minor; capacity = files*10. Comparable across runs on ONE project, not between projects.
countsYes
issuesYesEvery finding, most severe first.
summaryYesOne-line plain-language result.
suggestionsYesPrioritized next actions, deduplicated by rule — not a restatement of every issue's fix.
files_checkedYesSwift files actually scanned.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv2.7.0

TDQS

A4.3/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It is transparent about what the tool analyzes, listing concrete detection targets. The verb "Check" implies a read-only analysis, but the description does not explicitly confirm no side effects, which is a minor gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, dense sentence with every clause providing concrete detection categories or usage guidance. It is front-loaded with the core purpose and contains no filler or redundant phrases.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a single-parameter analysis tool with an output schema, the description covers the tool's purpose, the specific patterns it detects, and the signals for when to run it. Nothing necessary for an agent to decide to invoke it is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema already describes the single `path` parameter with 100% coverage, including the meaning of the project root. The description adds no additional parameter-level detail, so the baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with a specific verb and resource: "Check a Swift project for retain cycles and lifetime defects." It then enumerates the exact defect categories, which clearly differentiates this from sibling review tools like review_swift_concurrency or review_swift_performance.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly states when to use the tool: "when memory grows over time, when deinit is never called, or before shipping a screen with timers or subscriptions." It does not mention alternatives or when not to use it, so it falls just short of a 5.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.