swift-memory-storage-pro
Skill5 starsChanged 11 days agoMITView on GitHub
Audits Apple-platform apps for memory and on-device storage problems — retain cycles in closures, Tasks, Combine, timers, and delegates; image decode size; unbounded caches; extension and watchOS budgets; jetsam exits; the wrong directory for a file, iCloud backup bloat, secrets in UserDefaults, missing file protection, unbounded disk caches, free-space handling, app size, and disk-space / file-timestamp privacy manifest reasons. Use when investigating memory growth, leaks, jetsam terminations, storage complaints, backup rejections, or when reviewing code that caches, decodes images, or writes files.
In this repository19 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- app-intents-proSkill
- coredata-swift6-proSkill
- instruments-profiling-proSkill
- motion-design-proSkill
- store-compliance-proSkill
- swift-accessibility-proSkill
- swift-adaptive-layout-proSkill
- swift-concurrency-proSkill
- swiftdata-proSkill
- swift-design-system-proSkill
- swift-docc-proSkill
- swift-error-handling-proSkill
- swift-logging-proSkill
- swift-modularization-proSkill
- swift-package-proSkill
- swift-testing-proSkill
- swiftui-proSkill
- xcode-security-proSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 13
If asked to fix rather than review, make the changes directly and summarize them in the same file-by-file format.
- Very specific: line 18
Footprint: Check image decoding, in-memory caches, collection loading, and extension budgets using references/memory-footprint.md.
≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Audit Swift code for memory and storage problems. This is the deep-review companion to the always-on apple-memory-management.md and apple-storage-management.md rules: the rules steer while writing; this skill traces ownership, footprint, and file placement across whole features. Report only genuine problems.
If asked to fix rather than review, make the changes directly and summarize them in the same file-by-file format.
Review process:
- Leaks. For each type that stores closures, Tasks, Combine subscriptions, timers, observers, or delegates, trace who owns whom using
references/retain-cycles.md. A cycle needs a path back toself; confirm it before reporting. - Footprint. Check image decoding, in-memory caches, collection loading, and extension budgets using
references/memory-footprint.md. - Storage. For every file write, UserDefaults key, Keychain item, and disk cache, check the location, backup status, protection class, size cap, and privacy manifest reason using
references/storage-layout.md. - Evidence. When the user reports a symptom (memory growth, jetsam exits, disk use), or before you claim a fix worked, use
references/measuring.mdto reproduce and confirm it with the memory graph, Instruments, MetricKit, or a leak test. Add a leak test for each cycle you fix.
For a partial review (only leaks, only storage), load only the matching reference.
Core Instructions
- A cycle is only a finding when you can name the path.
self→cancellables→ sink closure →selfis a cycle; a[weak self]missing from a non-escaping or one-shot closure is not. Don't spray[weak self]everywhere as a "fix". - Size findings in bytes. "Decodes a 4032×3024 photo for a 60pt thumbnail: ~48 MB per cell" is actionable; "large image" is not.
- Location findings name the consequence: backed up when it shouldn't be (iCloud bloat, App Review), purgeable when it shouldn't be (offline content disappears), readable while locked when it holds sensitive data.
- Severity by user impact: crash or data loss (jetsam on a common flow, secrets in plain files, offline content in Caches, missing privacy manifest reason) > degraded (leaked view models, unbounded cache growth, backup bloat) > hygiene (missing size cap on a small cache, no storage settings screen).
- Cross-reference, don't duplicate: actor isolation belongs to
swift-concurrency-pro; Core Data and SwiftData store setup tocoredata-swift6-pro/swiftdata-pro; logging what you measured toswift-logging-pro.
Output Format
Organize findings by file. For each issue: file/line, the problem, the measured or estimated cost (bytes, objects, or files), and a brief before/after. Skip clean files. End with a prioritized summary.
Example finding:
FeedViewModel.swift
Line 31: the update loop holds self forever, so every visit to the feed leaks a view model.
// Before
updatesTask = Task {
for await update in repository.updates() {
apply(update)
}
}
// After: capture weakly, re-bind per iteration
updatesTask = Task { [weak self, repository] in
for await update in repository.updates() {
guard let self else { return }
self.apply(update)
}
}Summary
- Crash risk:
PhotoGridCelldecodes originals (~48 MB each) for 80pt thumbnails; jetsam after ~10 cells on a 3 GB device. - Degraded:
FeedViewModelleaks on every visit (Task holdsself). - Hygiene:
URLCache.sharedleft at the default size while the app prefetches video posters.
End of example.
References
references/retain-cycles.md— closures, Tasks andfor await, Combine, NotificationCenter, timers and display links, delegates,weakvsunowned, SwiftUI ownership.references/memory-footprint.md— image downsampling, NSCache, memory warnings and pressure, lazy containers, streaming, autorelease pools, extension and watchOS budgets, the increased-memory-limit entitlement.references/storage-layout.md— the directory decision table, backup exclusion, UserDefaults limits, Keychain, file protection, app groups, atomic writes, free space, cache budgets, app size, privacy manifest reasons.references/measuring.md— memory graph debugger, Instruments generations, leak tests in Swift Testing and XCTest,XCTMemoryMetric, MetricKit and Organizer, storage inspection withsimctland container downloads.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

