hmos-memleak-analysis
Installation
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.