hmos-memleak-analysis

Detects memory leaks in HarmonyOS ArkTS, JS, and C/C++ source code.

2|Updated Jun 21, 2026
One-click install
npx skills add https://github.com/IsKenKenYa/skills --skill hmos-memleak-analysis-iskenkenya
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: hmos-memleak-analysis
Source: https://github.com/IsKenKenYa/skills/tree/main/skills/harmonyos/solutions/quality/stability/hmos-memleak-analysis
Command: npx skills add https://github.com/IsKenKenYa/skills --skill hmos-memleak-analysis-iskenkenya

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve? HarmonyOS apps leak memory through unbalanced API pairs (napi_create_reference without napi_delete_reference), unpaired on/off event listeners, and unreleased native objects. This Skill statically analyzes source code to catch these leaks before deployment. ## Core Features & Use Cases - Language-Routed Analysis: Routes .ets/.ts/.js files to ArkTS/JS specifications and .c/.cpp/.h files to C-API specifications for rule-based inspection. - Script-Assisted Candidate Detection: Runs filter_on.py and filter_risk_func.py to surface on/off listener pairs and risky function calls as leak hypotheses for verification. - Structured Reporting: Generates a timestamped markdown report listing file path, line number, issue type, severity, code snippet, suggested fix, and confidence score. - Use Case: Reviewing a PR that adds a NAPI bridge between ArkTS and C++ — the Skill checks napi reference balancing, handle scope usage in loops, and lifecycle listener cleanup, then reports each finding with a concrete fix. ## Quick Start Analyze the HarmonyOS source code in my project directory for potential memory leaks and generate a structured report.

Frequently Asked Questions about hmos-memleak-analysis

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I detect memory leaks in HarmonyOS ArkTS code?

Run static analysis that checks for unpaired on/off event listeners, unreleased PixelMap or AVPlayer instances, uncleared setInterval timers, and RxJS subscriptions without unsubscribe. Findings are mapped to official HarmonyOS memory leak specifications with severity ratings.

How to find NAPI memory leaks in HarmonyOS C++ code?

Check that napi_create_reference is balanced with napi_delete_reference, napi_open_handle_scope with napi_close_handle_scope, and napi_wrap results are released via napi_remove_wrap when the last parameter is not nullptr. Missing pairs in loops are a common leak source.

What causes memory leaks in HarmonyOS window listeners?

Window.on and WindowStage.on listeners leak when off is not called in aboutToDisappear, when the event key does not match, or when anonymous functions are passed to off. Omitting the callback in off releases all callbacks of that type.

Does this analysis confirm leaks automatically?

No. The filter scripts produce candidate findings that are hypotheses or leads requiring human-like verification. Each reported issue includes a confidence score from 1 to 10 indicating how certain the finding is.

What output does the HarmonyOS memory leak analysis produce?

It generates a markdown report named memory_leak_analysis_report_<timestamp>.md listing each issue's file path, line number, issue type, severity (Major or Minor), surrounding code snippet, suggested fix, and confidence score.