Skip to content
Back to skills

Hmos Memleak Analysis

ASecurity

Analyzes HarmonyOS source code (ArkTS, JS, C/C++) to detect memory leaks.Use when (1) Performing static code analysis to catch potential leaks before deployment, (2) Reviewing PRs involving complex UI lifecycles or NAPI implementations,(3) Developing NAPI bridges between ArkTS and C++. Maps code to official specifications and applies heuristics for NAPI reference management and lifecycle synchronization.

  • 2 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added September 22, 2026
documentationpythongoc++api

Works with

  • api

Security analysis

A100/100

Pro scans all 15 files and shows the line behind each finding

Scanned September 22, 2026

npx -y skills add IsKenKenYa/skills --skill hmos-memleak-analysis --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Hmos Memleak Analysis?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Hmos Memleak Analysis
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/iskenkenya-hmos-memleak-analysis/badge)](https://www.skillsdirectory.com/skills/iskenkenya-hmos-memleak-analysis)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: hmos-memleak-analysis
description: Analyzes HarmonyOS source code (ArkTS, JS, C/C++) to detect memory leaks.Use when (1) Performing static code analysis to catch potential leaks before deployment, (2) Reviewing PRs involving complex UI lifecycles or NAPI implementations,(3) Developing NAPI bridges between ArkTS and C++. Maps code to official specifications and applies heuristics for NAPI reference management and lifecycle synchronization.
license: MIT
metadata:
    author: superliet
    version: 1.1.0
    category: memleak
---

# HarmonyOS Memory Leak Expert

## Analysis Workflow

1. **Language Routing**: Based on file extension:
   - `.ets`, `.ts`, `.js` → use `references/HarmonyOS_App_MemoryLeak_Specifications_arkts_js_api.md`,Before applying any code inspection rules
   - `.cpp`, `.c`, `.h` → use `references/HarmonyOS_App_MemoryLeak_Specifications_c_api.md`
   - The final report must include the analysis of the results of 'scripts/filter_on.py' and the results of the code review

2. **Script**
   - you MUST execute an external Python script `scripts/filter_on.py` and `scripts/filter_risk_func.py` with param `target source code dirpath`. Crucial Note: These candidates are NOT confirmed leaks. They are merely hypotheses or "leads" that require human-like verification.

3. **Core Heuristics**:
   - **Lifecycle Sync**: Use a listener similar to ''. The on() in TS must be deregistered as "aboutToDisappear()"/"onPageHide()" after its lifecycle ends. You can use scripts/filter_on.py to investigate possible on/off code involved
   - **NAPI Boundary**: Check `napi_create_reference` balanced with `napi_delete_reference`. Watch for missing `napi_handle_scope` in loops.
   - **Closure Retention**: Async callbacks capturing `this` cause leaks if component is destroyed before callback executes.
   - **Singleton/AppStorage**: Large objects in `AppStorage` need explicit cleanup strategy.

4. **Reporting Format(md)**: 
Report MUST list all issue file and generate a structured markdown report named memory_leak_analysis_report_<timestamp>.md
   - **FilePath**: (e.g., D:/xx/xxx/xxx.ts)
   - **LineNumber**: (e.g. 245)
   - **IssueType **: Category of the leak (e.g.,"Unreleased NAPI Reference", "Uncleared Timer", "Event Listener Leak", "Closure Retention", "Global Variable Accumulation")
   - **Severity**: [Major | Minor], Refer to the rules of HarmonyOS_Sapp_SemoryLeak_Specifications
   - **CodeSnippet**:  The relevant 5~10 lines of code surrounding the issue for quick context.
   - **SuggestedFix**:  Concrete code snippet or instruction to resolve the issue (e.g., "Add `clearTimeout` in `useEffect` cleanup").
   - **ConfidenceScore**: A score from 1-10 indicating the certainty of the finding (10 = Definite Leak). 

Files in this skill

  • SKILL.md2.7 KB
  • references/HarmonyOS_App_MemoryLeak_Specifications.md77.8 KB
  • references/HarmonyOS_App_MemoryLeak_Specifications_arkts_js_api.md35.2 KB
  • references/HarmonyOS_App_MemoryLeak_Specifications_c_api.md38.3 KB
  • references/doc_split.py6.2 KB
  • scripts/README.md2.9 KB
  • scripts/USAGE_GUIDE.md8.1 KB
  • scripts/config.json1.1 KB
  • scripts/filter_on.py12.9 KB
  • scripts/filter_risk_func.py22.2 KB
  • scripts/skill_main.py7 KB
  • scripts/skill_report.json5.5 KB
  • test_examples/complex_example.ts864 B
  • test_examples/good_example.ts549 B
  • test_examples/memory_leak_example.ts569 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.