Token导航 LogoToken导航

Agent Skill · 研究检索

memory-leak-diagnosis-skill(内存泄漏诊断技巧)

memory-leak-diagnosis-skill 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

memory-leak-diagnosis-skill 是研究检索类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为需要联网;许可证为 MIT,暂无第三方扫描结果,按安装量在研究检索类的 73,674 个 Skill 里排第 7,961。

总安装 17,560周安装 569GitHub Stars 公开资料未说明下载 3,576核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
MIT

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:memory-leak-diagnosis-skill(内存泄漏诊断技巧)
来源仓库:https://github.com/pstuart/pstuart
仓库路径:skills/memory-leak-diagnosis-skill
安装命令:
npx skills add pstuart/pstuart --skill "memory-leak-diagnosis-skill"
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

AgentSkills.tonpx skills
npx skills add pstuart/pstuart --skill "memory-leak-diagnosis-skill"

这个 Skill 是做什么的

研究检索类 Skill 主要解决「找资料、核对事实、把来源整理清楚」的问题,通常会让助手先检索再总结。

memory-leak-diagnosis-skill 用于诊断和定位 AI 代理中的内存泄漏问题。适用于 Codex、Claude、Cursor、Gemini CLI 中性能调优与稳定性保障场景。通过 GitHub 安装,使用 npx 命令指定技能路径。

安装命令:npx skills add pstuart/pstuart --skill "memory-leak-diagnosis-skill";需具备进程监控权限。建议结合日志分析工具验证诊断结果准确性。

来源仓库内路径:skills/memory-leak-diagnosis-skill

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add pstuart/pstuart --skill "memory-leak-diagnosis-skill";命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要需要联网,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

memory-leak-diagnosis-skill 怎么安装?

在终端执行 npx skills add pstuart/pstuart --skill "memory-leak-diagnosis-skill"。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

memory-leak-diagnosis-skill 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

memory-leak-diagnosis-skill 需要什么权限?

权限级别是需要联网。该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

memory-leak-diagnosis-skill 是免费的吗?

来源标注的许可证是 MIT。本站不代收任何费用,也不托管安装包;能否商用、要不要署名,以许可证原文为准。

memory-leak-diagnosis-skill 用的人多吗?

公开数据是累计安装 17,560 次,近一周安装 569 次,下载 3,576 次。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

memory-leak-diagnosis-skill 安全吗?

没有查到第三方扫描结果,安全性无法从公开资料判断,安装前请自行审查源码、依赖和命令行为。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 许可证明确为 MIT,商用和分发边界好判断。

先想清楚的地方

  • 没有第三方扫描结果,安全性只能靠自己读源码判断。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理研究检索类任务、又不想每次都手写提示词的人。

不太适合

  • 要求有安全扫描结论才肯安装的团队。
  • 需要厂商级技术支持和 SLA 的生产系统。

研究检索类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
find-skills

寻找技能 · Codex、Claude

31,199,81316,486操作浏览器MIT有提醒
self-improving-agent

自我改进 Agent · OpenClaw

16,464,0023,396接触敏感数据MIT-0通过
soultrace

灵魂追踪 · Codex、Claude

7,588,94412需要联网未明确有提醒
self-improving

自我完善 · OpenClaw

6,829,2841,046需要联网MIT-0通过
microsoft-foundry

微软代工厂 · Codex、Claude

6,614,144764调用外部服务未明确有提醒
memory-leak-diagnosis-skill

内存泄漏诊断技巧 · 本页

17,560—需要联网MIT未收录

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

name
Memory Leak Diagnosis Skill
description
Detecting and fixing memory leaks and retain cycles in Swift apps using Instruments and best practices.
version
1.0
activation
Activate for queries on memory leaks, retain cycles, Instruments leaks detection, ARC issues, or memory management problems.

Memory Leak Diagnosis Skill

This skill provides expertise in identifying, diagnosing, and fixing memory leaks and retain cycles in Swift applications. It covers Instruments usage, ARC concepts, and memory management best practices for iOS development.

Best Practices

  1. Understand ARC: Automatic Reference Counting manages memory automatically, but cycles can still occur.
  1. Use Weak References: Break retain cycles by using weak or unowned references in closures and delegates.
  1. Profile Regularly: Use Instruments to detect leaks early in development.
  1. Avoid Strong Reference Cycles: Be aware of parent-child relationships and delegate patterns.
  1. Clean Up Resources: Properly invalidate timers, cancel network requests, and remove observers.
  1. Test Memory Usage: Monitor memory growth during app usage.

Memory Management Guidelines

  • Classes create strong references by default.
  • Use weak for optional relationships that can become nil.
  • Use unowned for non-optional relationships that will always exist.
  • Capture self weakly in closures to prevent retain cycles.
  • Use Instruments Leaks and Allocations instruments for diagnosis.
  • Monitor memory usage with Xcode's Memory Graph Debugger.

Examples

Example 1: Fixing Retain Cycles in Closures

User Prompt: "Fix the retain cycle in this network manager that uses a completion handler."

Expected Output:

import Foundation

// PROBLEMATIC CODE - Retain Cycle
class NetworkManagerBad {
    var completionHandler: (() -> Void)?
    
    func fetchData() {
        // This creates a retain cycle: self -> completionHandler -> self
        self.completionHandler = {
            print("Data fetched")
            self.processData() // 'self' is strongly captured
        }
        
        // Simulate async operation
        DispatchQueue.global().asyncAfter(deadline: .now() + 1) {
            self.completionHandler?()
        }
    }
    
    func processData() {
        print("Processing data")
    }
    
    deinit {
        print("NetworkManagerBad deallocated")
    }
}

// FIXED CODE - Using weak self
class NetworkManagerGood {
    var completionHandler: (() -> Void)?
    
    func fetchData() {
        // Use [weak self] to break the retain cycle
        self.completionHandler = { [weak self] in
            print("Data fetched")
            self?.processData() // 'self' is now weakly captured
        }
        
        // Simulate async operation
        DispatchQueue.global().asyncAfter(deadline: .now() + 1) {
            self.completionHandler?()
        }
    }
    
    func processData() {
        print("Processing data")
    }
    
    deinit {
        print("NetworkManagerGood deallocated") // This will now print!
    }
}

// Alternative: Using unowned for guaranteed non-nil self
class NetworkManagerUnowned {
    var completionHandler: (() -> Void)?
    
    func fetchData() {
        // Use [unowned self] if you're certain self won't be nil
        self.completionHandler = { [unowned self] in
            print("Data fetched")
            self.processData() // No optional chaining needed
        }
        
        DispatchQueue.global().asyncAfter(deadline: .now() + 1) {
            self.completionHandler?()
        }
    }
    
    func processData() {
        print("Processing data")
    }
    
    deinit {
        print("NetworkManagerUnowned deallocated")
    }
}

// Usage example
func testMemoryLeak() {
    print("Creating NetworkManagerBad...")
    var managerBad: NetworkManagerBad? = NetworkManagerBad()
    managerBad?.fetchData()
    managerBad = nil // Won't deallocate due to retain cycle
    
    print("Creating NetworkManagerGood...")
    var managerGood: NetworkManagerGood? = NetworkManagerGood()
    managerGood?.fetchData()
    managerGood = nil // Will deallocate properly
    
    // Give time for async operations
    RunLoop.current.run(until: Date(timeIntervalSinceNow: 2))
}

Example 2: Delegate Pattern Retain Cycles

User Prompt: "Fix the retain cycle between a view controller and its delegate."

Expected Output:

import UIKit

// PROBLEMATIC CODE
protocol DataManagerDelegateBad: AnyObject {
    func dataDidUpdate(_ data: [String])
}

class DataManagerBad {
    weak var delegate: DataManagerDelegateBad? // This is correct
    
    func fetchData() {
        // Simulate network call
        DispatchQueue.global().asyncAfter(deadline: .now() + 1) {
            let data = ["Item 1", "Item 2", "Item 3"]
            self.delegate?.dataDidUpdate(data)
        }
    }
}

class ViewControllerBad: UIViewController, DataManagerDelegateBad {
    var dataManager: DataManagerBad?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        dataManager = DataManagerBad()
        dataManager?.delegate = self // This creates: VC -> dataManager -> delegate -> VC
        
        dataManager?.fetchData()
    }
    
    func dataDidUpdate(_ data: [String]) {
        print("Received data: \(data)")
    }
    
    deinit {
        print("ViewControllerBad deallocated")
    }
}

// The issue is that ViewController strongly holds DataManager,
// DataManager weakly holds the delegate (ViewController),
// but the closure in fetchData strongly captures self (DataManager).
// When ViewController is dismissed, DataManager's closure keeps it alive.

// FIXED CODE
protocol DataManagerDelegate: AnyObject {
    func dataDidUpdate(_ data: [String])
}

class DataManager {
    weak var delegate: DataManagerDelegate?
    
    func fetchData() {
        // Use [weak self] in the closure to break any potential cycle
        DispatchQueue.global().asyncAfter(deadline: .now() + 1) { [weak self] in
            let data = ["Item 1", "Item 2", "Item 3"]
            self?.delegate?.dataDidUpdate(data)
        }
    }
    
    deinit {
        print("DataManager deallocated")
    }
}

class ViewController: UIViewController, DataManagerDelegate {
    var dataManager: DataManager?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        dataManager = DataManager()
        dataManager?.delegate = self
        
        dataManager?.fetchData()
    }
    
    func dataDidUpdate(_ data: [String]) {
        print("Received data: \(data)")
    }
    
    deinit {
        print("ViewController deallocated") // This will now print!
    }
}

// Alternative pattern: Using a closure instead of delegate
class DataManagerClosure {
    var onDataUpdate: (([String]) -> Void)?
    
    func fetchData() {
        DispatchQueue.global().asyncAfter(deadline: .now() + 1) { [weak self] in
            let data = ["Item 1", "Item 2", "Item 3"]
            self?.onDataUpdate?(data)
        }
    }
    
    deinit {
        print("DataManagerClosure deallocated")
    }
}

class ViewControllerClosure: UIViewController {
    var dataManager: DataManagerClosure?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        dataManager = DataManagerClosure()
        // Use [weak self] to avoid retain cycle
        dataManager?.onDataUpdate = { [weak self] data in
            print("Received data: \(data)")
        }
        
        dataManager?.fetchData()
    }
    
    deinit {
        print("ViewControllerClosure deallocated")
    }
}

Example 3: Instruments Leaks Detection

User Prompt: "How do I use Instruments to detect memory leaks in my iOS app?"

Expected Output: To detect memory leaks using Instruments:

  1. Open Instruments: In Xcode, go to Product > Profile (⌘I)
  1. Choose Leaks Instrument: Select the "Leaks" template
  1. Configure Recording:

- Target your app - Make sure "Record reference counts" is enabled - Start recording

  1. Use Your App: Navigate through the screens where you suspect leaks
  1. Analyze Results:

- Look for red bars in the Leaks track - these indicate memory leaks - The Detail pane shows leaked objects and their allocation backtraces - Use the "Cycles & Roots" view to see retain cycles

  1. Identify the Problem:

- Click on a leak to see the allocation history - Look for objects that should have been deallocated but weren't - Check for strong reference cycles

Example Leaks Output Interpretation:

Leaks detected: 5
- Leaked Object: ViewController (0x7f9b8c0a5e00)
  - Responsible Library: UIKit
  - Allocation: -[UIViewController initWithNibName:bundle:]
  - Backtrace shows it was created in viewDidLoad of parent VC
  - Never deallocated because of retain cycle with timer

- Leaked Object: Timer (0x7f9b8c0a6120)
  - Responsible Library: Foundation
  - Allocation: +[NSTimer scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:]
  - Strong reference to target (ViewController) prevents deallocation

Common Leak Patterns to Look For:

  1. Timer Retain Cycles:
// BAD
class MyViewController: UIViewController {
    var timer: Timer?
    
    func startTimer() {
        timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(update), userInfo: nil, repeats: true)
    }
    
    @objc func update() {
        // Update UI
    }
}

// GOOD
class MyViewController: UIViewController {
    var timer: Timer?
    
    func startTimer() {
        timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { [weak self] _ in
            self?.update()
        }
    }
    
    func update() {
        // Update UI
    }
    
    deinit {
        timer?.invalidate()
    }
}
  1. Closure Capture Issues:
// BAD
var completion: (() -> Void)?
completion = {
    self.doSomething() // Creates retain cycle
}

// GOOD  
completion = { [weak self] in
    self?.doSomething() // Breaks the cycle
}
  1. Delegate Strong References:
// BAD
class MyObject {
    var delegate: MyDelegate? // Strong reference
}

// GOOD
class MyObject {
    weak var delegate: MyDelegate? // Weak reference
}

Example 4: Memory Graph Debugger

User Prompt: "Use Xcode's Memory Graph Debugger to identify and fix a retain cycle."

Expected Output: To use the Memory Graph Debugger:

  1. Enable Memory Graph: In Xcode, go to Debug > Debug Workflow > View Memory Graph (⌘⌃M)
  1. Trigger the Debugger: Run your app and navigate to create the suspected leak
  1. Analyze the Graph:

- Look for objects that should be deallocated but remain in memory - Purple arrows show strong references - Gray arrows show weak references - Numbers show reference counts

  1. Inspect Objects: Click on objects to see their properties and references
  1. Find Cycles: Look for circular references where objects keep each other alive

Example Memory Graph Analysis:

Root View Controller (ref count: 1)
├── Strong reference to Data Manager (ref count: 2)
│   ├── Strong reference to Network Client (ref count: 1)
│   └── Strong reference to Delegate (View Controller) (ref count: 1)
│       └── Strong reference back to Data Manager
└── Strong reference to Timer (ref count: 1)
    └── Strong reference to Timer Target (View Controller)

Fixing the Cycle:

class DataManager {
    weak var delegate: DataManagerDelegate? // Change to weak
    
    private var timer: Timer?
    
    func startPolling() {
        timer = Timer.scheduledTimer(withTimeInterval: 5.0, repeats: true) { [weak self] _ in
            self?.fetchData()
        }
    }
    
    func stopPolling() {
        timer?.invalidate()
        timer = nil
    }
    
    private func fetchData() {
        // Network request with [weak self] in completion
        networkClient.fetch { [weak self] result in
            switch result {
            case .success(let data):
                self?.delegate?.dataDidUpdate(data)
            case .failure:
                break
            }
        }
    }
}

class ViewController: UIViewController, DataManagerDelegate {
    private let dataManager = DataManager()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        dataManager.delegate = self
        dataManager.startPolling()
    }
    
    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        dataManager.stopPolling() // Clean up timer
    }
    
    func dataDidUpdate(_ data: [String]) {
        // Update UI
    }
}

Example 5: ARC and Reference Types

User Prompt: "Explain and fix ARC-related memory issues in a complex object graph."

Expected Output:

import Foundation

// Understanding Reference Types
class Person {
    let name: String
    var car: Car?
    
    init(name: String) {
        self.name = name
        print("\(name) initialized")
    }
    
    deinit {
        print("\(name) deinitialized")
    }
}

class Car {
    let model: String
    weak var owner: Person? // Use weak to prevent cycle
    
    init(model: String) {
        self.model = model
        print("\(model) initialized")
    }
    
    deinit {
        print("\(model) deinitialized")
    }
}

// BAD EXAMPLE - Retain Cycle
func createRetainCycle() {
    print("=== Creating Retain Cycle ===")
    var person: Person? = Person(name: "John") // ref count: 1
    var car: Car? = Car(model: "Tesla")        // ref count: 1
    
    person?.car = car      // car ref count: 2 (person + car variable)
    car?.owner = person    // person ref count: 2 (car + person variable)
    
    person = nil // person ref count: 1 (still held by car.owner)
    car = nil    // car ref count: 1 (still held by person.car)
    
    // Neither object is deallocated!
    print("=== Memory leak occurred ===")
}

// GOOD EXAMPLE - No Retain Cycle
func createNoRetainCycle() {
    print("=== No Retain Cycle ===")
    var person: Person? = Person(name: "Jane") // ref count: 1
    var car: Car? = Car(model: "Honda")        // ref count: 1
    
    person?.car = car      // car ref count: 2
    car?.owner = person    // person ref count: 1 (weak reference!)
    
    person = nil // person ref count: 0 -> deallocated
    car = nil    // car ref count: 0 -> deallocated
    
    print("=== Both objects properly deallocated ===")
}

// Complex Object Graph Example
class Company {
    let name: String
    var employees: [Employee] = []
    
    init(name: String) {
        self.name = name
        print("Company \(name) initialized")
    }
    
    deinit {
        print("Company \(name) deinitialized")
    }
}

class Employee {
    let name: String
    unowned let company: Company // unowned because company owns employee
    
    init(name: String, company: Company) {
        self.name = name
        self.company = company
        print("Employee \(name) initialized")
    }
    
    deinit {
        print("Employee \(name) deinitialized")
    }
}

func testComplexGraph() {
    print("=== Complex Object Graph ===")
    var company: Company? = Company(name: "Apple")
    
    // Create employees - company owns them strongly
    let employee1 = Employee(name: "John", company: company!)
    let employee2 = Employee(name: "Jane", company: company!)
    
    company?.employees = [employee1, employee2]
    
    company = nil // This will deallocate company AND all employees
    
    print("=== Complex graph deallocated ===")
}

// Value Types vs Reference Types
struct Address {
    var street: String
    var city: String
}

class PersonWithAddress {
    let name: String
    var address: Address // Value type - copied, not referenced
    
    init(name: String, address: Address) {
        self.name = name
        self.address = address
    }
}

func testValueVsReference() {
    let address = Address(street: "123 Main St", city: "Springfield")
    var person1: PersonWithAddress? = PersonWithAddress(name: "John", address: address)
    var person2: PersonWithAddress? = PersonWithAddress(name: "Jane", address: address)
    
    person1?.address.city = "Changed City" // Only affects person1's copy
    
    print("Person1 city: \(person1?.address.city ?? "")")
    print("Person2 city: \(person2?.address.city ?? "")")
    
    person1 = nil // Only person1's struct is deallocated
    person2 = nil // Only person2's struct is deallocated
    // address was copied, so no reference counting involved
}

Key ARC Concepts:

  1. Strong References (default): Increase reference count
  2. Weak References: Don't increase reference count, automatically nil when object deallocated
  3. Unowned References: Don't increase reference count, assume object won't be deallocated
  4. Value Types (struct, enum): Copied, not referenced - no retain cycles possible
  5. Reference Types (class): Shared instances - retain cycles possible

When to use each:

  • strong: Default, use for owned relationships
  • weak: When reference can become nil, like delegates, parent references
  • unowned: When reference will never be nil during its lifetime, like self in closures where object owns the closure

平台分布

windsurf

27.53%
按下载量换算984

Codex

23.74%
按下载量换算849

Claude Code

19.1%
按下载量换算683

Antigravity

13.51%
按下载量换算483

Gemini CLI

8.34%
按下载量换算298

trae

3.58%
按下载量换算128

安全审计

暂无安全审计结果可展示。

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills