hmos-memleak-analysis
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
- 最近更新
- 2026-10-08
- Stars
- ★ 3
- Forks
- 0
01 前言 Front Matter
- name
- hmos-memleak-analysis
- license
- MIT
- metadata
- { "author": "superliet", "version": "1.1.0", "category": "memleak" }
- 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.
02 资源文件 12
- 脚本scripts/config.json1.1 KB
- 脚本scripts/filter_on.py12.9 KB
- 脚本scripts/filter_risk_func.py22.2 KB
- 脚本scripts/memleak_report.json843.9 KB
- 脚本scripts/memleak_risk_func_report.json1.4 MB
- 脚本scripts/README.md2.9 KB
- 脚本scripts/skill_main.py7.0 KB
- 脚本scripts/skill_report.json5.5 KB
- 脚本scripts/USAGE_GUIDE.md8.1 KB
- 脚本test_examples/complex_example.ts864 B
- 脚本test_examples/good_example.ts549 B
- 脚本test_examples/memory_leak_example.ts569 B
03 SKILL.md 正文
HarmonyOS Memory Leak Expert
Analysis Workflow
-
Language Routing: Based on file extension:
.ets,.ts,.js→ usereferences/HarmonyOS_App_MemoryLeak_Specifications_arkts_js_api.md,Before applying any code inspection rules.cpp,.c,.h→ usereferences/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
-
Script
- you MUST execute an external Python script
scripts/filter_on.pyandscripts/filter_risk_func.pywith paramtarget source code dirpath. Crucial Note: These candidates are NOT confirmed leaks. They are merely hypotheses or "leads" that require human-like verification.
- you MUST execute an external Python script
-
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_referencebalanced withnapi_delete_reference. Watch for missingnapi_handle_scopein loops. - Closure Retention: Async callbacks capturing
thiscause leaks if component is destroyed before callback executes. - Singleton/AppStorage: Large objects in
AppStorageneed explicit cleanup strategy.
-
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
clearTimeoutinuseEffectcleanup"). - ConfidenceScore: A score from 1-10 indicating the certainty of the finding (10 = Definite Leak).
04 同仓库更多 Skills
writing-for-agents
为 agent 撰写文档。当创建或编辑 skill、修改 AGENTS.md 或 CLAUDE.md 时使用。
wait-what
停。上一条消息没讲明白:换个说法再讲一遍。
to-questionnaire
把你无法独自回答的决策转化成一份问卷,交给别人填写。
teach
在当前工作区内,教会用户一项新 skill 或概念。
handoff
把当前对话压缩成一份交接(handoff)文档,供另一个代理接手。
grilling
就一个计划、决策或想法对用户进行无情的访谈。当用户想压力测试自己的思路,或使用任何 'grill' 触发短语时使用。