Overview
Resource leaks occur when resources such as handles, threads, and memory are not correctly released during application running. As a result, the resources are occupied for a long time and cannot be used by other applications. If a type of resources is used up, the system may freeze or restart. To address resource leak problems, the system provides the resource leak detection and determination, maintenance and debugging logs, and log reporting capabilities for you to locate faults. This document describes resource leak detection capability and log specifications.
Basic Concepts
Resource leaks consist of the following types: memory leaks, handle leaks, and thread leaks. The system periodically samples the resource usage of the process to detect these leaks. If the resource usage exceeds the threshold, the system captures the corresponding maintenance and debugging information and reports a leak event. Subscribe to the Hiappevent resource leak event.
Implementation Principles
The following table lists the resource leak detection methods.
| Leak Type | Detection Mechanism |
| Handle leak (FD_LEAK) | Traverse the processes every 60 seconds to obtain the total number of FDs. If the number of FDs exceeds the threshold (5000), detailed handle information is captured and a handle leak is reported. |
| Thread leak (THREAD_LEAK) | Traverse the processes every 60 seconds to obtain the total number of threads. If the number of threads exceeds the threshold (700), thread names are captured and a thread leak is reported. |
| Memory Leak (MEMORY_LEAK) - JS Leak (JS_LEAK) | Insert instrumentation code within the JVM. When the heap usage exceeds 85% or out of memory (OOM) is triggered, a heap dump is captured and a JS leak is reported. |
| Memory Leak (MEMORY_LEAK) - Native Memory Leak (PSS_MEMORY) | Monitor the application dynamic peak memory every 200 seconds. If the dynamic peak memory exceeds twice that of the average dynamic peak memory of applications, a memory leak is reported and memory control is triggered. |
| Memory leak, such as (MEMORY_LEAK) - ashmem/ion/gpu memory leak (KERNEL_MEMORY) | If the anonymous shared memory (ashmem), ION or GPU memory usage exceeds the baseline value, a memory leak is reported and maintenance and debugging information is captured. |
Note:
The thresholds and baselines in the table are default values. If the ecosystem needs to set a baseline during development, you can call the hidebug.setAppResourceLimit API. It is recommended that this API be called in the development phase instead of the official release phase.
VM memory usage = heapUsed/totalHeap
heapUsed: size of the heap used by the current VM, in KB. You can obtain the value through hidebug.getAppVMMemoryInfo().
totalHeap: total size of the heap of the current VM, in KB. You can obtain the value through the hidebug.getAppVMMemoryInfo() interface.
When an application reports a JS_ERROR/CPP_CRASH fault and the error message contains "OutOfMemory", locate the fault by referring to Memory Leak Analysis Method.
Management and control means that the system proactively terminates the behavior of leaking an application after determining that the application is leaked.
The resource leak kernel is controlled as follows:
In HarmonyOS 6.1.0 and later versions, the system resources are insufficient due to fast application resource application or foreground leak. For example, the quick application (RSS, ion, and GPU memory) of a single application exceeds 1/3 of the system memory. As a result, the memory of the system is low, and the system controls the application, some basic RESOURCE_OVERLIMIT maintenance and debugging information is provided.
Description
Currently, the following resource types support kernel control: ion, gpu, rss, ashmem, and thread.
The kernel control does not distinguish the foreground and background. As a result, the foreground of the faulty app may exit unexpectedly.
Constraints
The maintenance and debugging of the handle leak call stack, native memory leak call stack, and JS leak memory snapshot are disabled by default in the no-log version.
If you want to obtain the JS memory leak snapshot of the no-log version, add the subscription to the JS memory snapshot of the no-log version by referring to Resource Leak Event Subscription (ArkTS).
Obtaining Logs
Resource leak logs are managed by the LeakDetector module and can be obtained in any of the following ways:
Method 1: Use DevEco Testing to obtain logs.
DevEco Testing collects resource leak logs in /data/log/reliability/resource_leak/ of the device and displays the logs by process name, fault, and time.
| Leak Type | Log file name: |
| Handle leak (FD_LEAK) | [pid]_fd_leak.txt |
| Thread leak (THREAD_LEAK) | [pid]_thread_leak.txt |
| Memory Leak (MEMORY_LEAK) - JS Leak (JS_LEAK) | memleak-js-[process_name]-[pid]-[tid]-[timestamp].rawheap |
| Memory Leak (MEMORY_LEAK) - Native Memory Leak (PSS_MEMORY) | memleak-native-[process_name]-[pid]-sample.txt memleak-native-[process_name]-[pid]-smaps.txt memleak-native-[process_name]-[pid]-[timestamp].txt |
| Memory leak, such as (MEMORY_LEAK) - ashmem/ion/gpu memory leak (KERNEL_MEMORY) | memleak-kernel-[module]-0-sample.txt memleak-kernel-[module]-0-[timestamp].txt |
The native memory leak call stack (memleak-native-[process_name]-[pid]-[timestamp].txt) cannot be directly opened in DevEco Studio. You need to change the file name extension to .nas and use DevEco Studio-Profiler to open and analyze the call stack. For details, see Memory Analysis and Optimization.
The maintenance and debugging log memleak-js-[process_name]-[pid]-[tid]-[timestamp].rawheap of JS leak is a binary memory snapshot file. You need to use the translator tool to convert the file into a .heapsnapshot file and open the file using DevEco Studio or a browser. For details, see Snapshot Offline Import.
Method 2: Use DevEco Studio to collect logs.
The profiler module of DevEco Studio provides two collection modes: Allocation (obtaining the native call stack profiler) and Snapshot (obtaining the heap dump at the JS layer).
Method 3: Use HiAppEvent APIs to subscribe to resource leak events.
HiAppEvent provides a fault subscription interface to subscribe to various fault dotting. For details, see HiAppEvent Introduction. For details about the resource leak subscription mode, see Resource Leak Event Introduction. Resource leak logs are stored in /data/storage/el2/log/resourcelimit/ and named in RESOURCE_OVERLIMIT_[TIMESTAMP]_[PID].log format. The log content identifies the file type.
Handle Leak Log Specifications
Fault log: [pid]_fd_leak.txt (Method 1) or RESOURCE_OVERLIMIT_[TIMESTAMP]_[PID].log (Method 3)
[h2]Maintenance and Debugging Information About Special Handles
If Leaked fd Top 10 contains information about the ashmem, socket, pipe, sync_file, or dmabuf type and the number of handles of this type exceeds 1000, detailed maintenance and debugging information about the entire system is also provided. The details are as follows:
Handle of the ashmem type
If the top 1 handle type is ashmem, detailed ashmem information of the entire system is captured, as listed in the following table.
| Field name. | Description |
| Process_name | Bundle name of the application process that holds the ashmem block. |
| Process_ID | PID of the failed process, which can be used to search for related process information in the HiLog logs. |
| Fd | Handle held by the process. |
| Applicant_Pid | PID of the process that applies for the ashmem block. Based on this PID, you can identify the source of the ashmem block. |
| Ashmem_name | Name of the ashmem block, which is set by using the corresponding API. It is used to determine the storage resource type and point to different domains. |
| Size | Size of the ashmem block, in bytes. |
Note:
APIs for setting the ashmem memory:
JS-layer API: setMemoryNameSync.
Native-layer API: OH_PixelmapNative_SetMemoryName.
*****************************
LOGGER_MEMCHECK_ASHMEM_INFO
Process ashmem detail info:
---------------------------------------------------------------------------------
Process_name Process_ID Fd Cnode_idx Applicant_Pid Ashmem_name Size
process1 781 18 328233 781 dev/ashmem/PolicyVolumeMap 384
...........
...........
Handle of the socket type
If the top 1 handle type is socket, detailed information about the socket memory of the entire device is captured, as listed in the following table.
| Field name. | Description |
| ProcessName | Bundle name of the application process that holds the socket block. |
| ProcessID | PID of the failed process, which can be used to search for related process information in the HiLog logs. |
| Fd | Handle held by the process. |
| inode | Information about file system object. |
| PeerTid | TID of the peer end connected via the socket (the value is 0 for a connectionless socket). |
Process socket info:
----------------------------------------------------
ProcessName ProcessID Fd inode PeerTid
process1 6874 3 0 0
........
.........
Handle of the pipe type
If the top 1 handle type is pipe, detailed information about the pipe memory of the entire device is captured, as listed in the following table.
| Field name. | Description |
| ProcessName | Bundle name of the application process that holds the pipe block. |
| ProcessID | PID of the failed process, which can be used to search for related process information in the HiLog logs. |
| Fd | Handle held by the process. |
| PipeName | Pipe name. |
| inode | Information about file system object. |
| MaxUsage | Maximum usage. |
| NumAccounted | Accumulated usage. |
| RingSize | Size of the ring buffer, in KB. |
Process pipe info:
------------------------------------
ProcessName ProcessID Fd PipeName inode MaxUsage NumAccounted RingSize
process1 629 7 / 11 16 16 16
process1 629 8 / 11 16 16 16
........
Handle of the sync_file type
If the top 1 handle type is sync_file, detailed information about sync_file of the entire device is captured, as listed in the following table.
| Field name. | Description |
| ProcessName | Bundle name of the application process that holds the sync_file block. |
| ProcessID | PID of the failed process, which can be used to search for related process information in the HiLog logs. |
| Fd | Handle held by the process. |
| FenceName | Name of sync_file. |
| inode | Information about file system object. |
| FenceNum | Number of fences. |
| TimelineName | Timeline name of the fence. |
| DriverName | Driver name. |
| Status | Status of the fence. |
| Timestamp | Timestamp of the fence. |
Process fence info:
----------------------------------------------------
ProcessName ProcessID Fd FenceName inode FenceNum TimelineName DriverName Status Timestamp
process1 1309 25 NULL 4186 1 0:online_composer_gfx_primary ukmd_release_fence_2941430 1 91607485502500
process1 1309 26 NULL 4186 1 0:online_composer_gfx_primary ukmd_release_fence_2941430 1 91607485502500
........
Handle of the dmabuf type
If the top 1 handle type is dmabuf (ION memory), detailed information about the dmabuf of the entire device is captured, as listed in the following table.
| Field name. | Description |
| Process name | Bundle name of the application process that holds the ION block. |
| Process ID | PID of the failed process, which can be used to search for related process information in the HiLog logs. |
| Fd | Handle held by the process. |
| size | Buffer size, in bytes. |
| magic | Unique ID of the buffer. If the values of magic are the same, the same buffer is pointed to. |
| buf->pid | PID of the process that requests the buffer. |
| buf->task_comm | Name of the process that applies for the buffer. |
Process dma_heap info:
----------------------------------------------------
Process name Process ID fd size magic buf->pid buf->task_comm
process1 971 23 3145728 36 971 process2
process1 971 24 1048576 38 971 process2
........
[h2]Clustering Rules for Handle Leak
Leak issues generated by an application at different times on the same or different versions may be caused by the same reason. You can extract fault characteristics from fault logs and cluster multiple fault logs based on the fault characteristics to improve the analysis efficiency of leak issues.
Determine the type of handle leak based on the number of top 10 file handles and the number of top 10 file path handles in Handle Leak Log. Use the handle type that accounts for the largest proportion as the fault characteristic.
For special types of handles such as ashmem and ion, refer to the ASHMEM_LEAK and ION_LEAK rules for clustering.
Thread Leak Log Specifications
Fault log: [pid]_thread_leak.txt (Method 1) or RESOURCE_OVERLIMIT_[TIMESTAMP]_[PID].log (Method 3).
[h2]Clustering Rules for Thread Leaks
Leak problems generated by applications on the same or different versions at different time may be caused by the same cause. Developers can extract fault characteristics from fault logs and cluster multiple fault logs based on the fault characteristics to improve the efficiency of analyzing leak problems.
Analyze the top 10 threads displayed in Thread Leak Log. The name of the thread that accounts for the largest proportion is used as the fault characteristic.
The system has clustered threads with the same name. However, in some special scenarios, thread names may be different, such as IPC_11_13795 and IPC_12_13796. If you want to further enhance the clustering effect, you can use similar process names in all threads as the same fault characteristic, such as IPC_xx_xxx, to improve clustering accuracy.
Extracts the thread snapshot corresponding to the thread from the thread leak log and performs clustering based on the call stack.
JS Memory Leak Log Specifications
Fault log: memleak-js-[process_name]-[pid]-[tid]-[timestamp].rawheap (Method 1) or RESOURCE_OVERLIMIT_[TIMESTAMP]_[PID].log (Method 3)
[h2]Clustering Rules for JS Leaks
Leak problems generated by applications on the same or different versions at different time may be caused by the same cause. Developers can extract fault characteristics from fault logs and cluster multiple fault logs based on the fault characteristics to improve the efficiency of analyzing leak problems.
Description of the clustering procedure
Confirm the clustering scope. Only the top 20 directories and directories whose retained size accounts for more than 5% are clustered.
Cluster the faults reported based on the clustering rules. To ensure the validity of the clustering result, the objects stored in different directories are different, and the clustering rules are different.
Collect statistics on the number and memory size of each type of objects, sort the objects by the number or memory size, and find the object with the highest memory usage as the fault feature of the reported fault.
Clustering rule
There are three types of clustering rules: name clustering, reference chain clustering, and attribute clustering. Different types of objects require different clustering methods.
Clustering by object name
Objects in the Function(closure) directory are clustered by object name. Objects with the same name are considered as one type.
Clustering through the shortest reference chain of an object
Objects in directories such as Method, js_set, Map, string, and JSNativePointer are preferentially clustered through reference chains. The names of this type of objects in the directory are the same. The reference chain can be used to distinguish object creation scenarios. Compares the shortest reference chain from each object in the directory to the GC root. If there are multiple shortest reference chains, the reference chain with the largest retained size is selected. If the shortest reference chains are the same, they are considered as one type.
Object name + reference chain clustering
Service objects (class objects and function objects created on the service side) contain path object names and line numbers. If the call points of the same class or function object are different, the reference chains are different. You need to distinguish the reference chains based on the call points.
In addition, framework and jsarray(array) are clustered by object name and reference chain.
Attribute + reference chain clustering
The objects in the jsobject (js_shared_object) directory have the same name but represent different objects. You need to use the reference chain to classify the jsobject objects, that is, distinguish the jsobject objects of different call points.
There are a large number of objects whose distance is 1 in the jsobject object. These objects cannot be distinguished by reference chains, but can be distinguished by attributes. That is, whether the objects directly held by the jsobject object are consistent. If the names of the objects directly held by the jsobject object are the same and the holding relationships are the same, the objects are classified into one type.
Special clustering
5.1 SourceTextModule
The SourceTextModule object is created on the system side and is used to hold the export object. A SourceTextModule object is generated for each TS file. The SourceTextModule object holds the exported object in the TS file. Therefore, the SourceTextModule object is the result after clustering and does not need to be clustered again.
5.2 Promise/PromiseRecord/PromiseCapability/PromiseReaction
Objects related to asynchronization. Perform clustering based on the handle Message+ reference chain under PromiseReaction. The handle information under PromiseReaction indicates the previous task of the asynchronous task, which can be distinguished by the previous task.
5.3 proxy
Proxy is often closely related to framework objects and can be clustered using the target information (handle) and reference chain under proxy. The target information under proxy indicates the proxied object held by the proxy. The proxy is meaningless and needs to be distinguished based on the proxied object.
Other basic types except the preceding types:
By default, objects of other basic types are clustered based on the shortest reference chain.
native Memory Leak Log Specifications
Fault log: RESOURCE_OVERLIMIT_[TIMESTAMP]_[PID].log (Method 3) or memleak-native-[process_name]-[pid]-sample.txt (Method 1).
[h2]Memory Sampling
The memleak-native-[process_name]-[pid]-sample.txt file contains the process ID, process name, baseline value, and memory sampling information, in which you can view the memory change.
| Field name. | Description |
| SoftThreshold | Process threshold set by the system (or set by the application using setAppResourceLimit()), in KB. If the application memory usage exceeds the threshold for five consecutive times, a memory leak event is reported. |
| HardThreshold | Process hard threshold set by the system, in KB. If the application memory usage exceeds the hard threshold for two consecutive times, a memory leak event is reported. |
| PSS | Proportional resident memory size, in KB. The memory size of the shared library is evenly allocated based on the number of processes. The PSS usage of a process is accurately calculated at the time marked with an asterisk (*). |
| Offset | Offset of the allocation of the shared library, in KB. You can estimate the PSS value without asterisks (*) by using the following formula: RSS + Offset = PSS. |
| RSS | Total resident memory size of the process in the physical memory (including the total memory occupied by the shared library), in KB. |
| SwapPSS | Total memory size that is written to the swap space by the process, in KB. |
| TotalPSS | Total PSS usage of the process, in KB. |
| AvcMem | Memory created by the process when the process creates a codec instance through Avcodec_service. The memory is reported by Avcodec_service to HiView for statistics collection. The unit is KB. |
| MediaMem | Memory created by the process through the Media_service API. The memory is reported by Media_service to HiView for statistics collection. The unit is KB. |
| GPU | GPU memory used by the process, in KB. |
| ION | ION memory used by the process, in KB. |
| TotalMem | Total memory size used by the process, in KB. TotalMem = TotalPSS + ION + GPU + AvcMem + MediaMem. |
| Level | Leak level of the process. |
| RunningTime | Current lifecycle of the process, in seconds. |
| Realtime | Real time of the sampling. |
/*************************************************************
/* ***** READ ME ***** *
/*************************************************************
/* RSS: Resident Set Size *
/* PSS: Proportional Set Size *
/* RSS + Offset = PSS *
/* TotalPSS = PSS + SwapPSS *
/* TotalMem = TotalPSS + Av_Mem + Media_Mem + ION + GPU *
/* ***** Two Modes ***** *
/* Estimate Mode: RSS & SwapPSS is real *
/* Real Mode(Realtime with *): everything is real *
/* Media_rss:apply mem through media_service *
/* Avc_rss:apply mem through avcodec_service *
/* ~ means negligible memory(safe to ignore in analysis) *
/*************************************************************
/* ***** Attention ***** *
/* Formulas about TotalMem and sub-items may change, *
/* please reference current annotation formula *
/*************************************************************
pid: XXXX
processName: XXXXXX
SoftThreshold: 3500(KB)
HardThreshold: 1024000(KB)
Index RSS(KB) Offset(KB) PSS(KB) SwapPSS(KB) TotalPSS(KB) MediaMem(KB) AvcMem(KB) GPU(KB) ION(KB) TotalMem(KB) Level RunningTime(s) Realtime
1 14668 0 14668 5500 20168 ~ ~ ~ ~ 20168 W 112 2025/04/23 12:28:02
2 12732 0 12732 5476 18208 ~ ~ ~ ~ 18208 W 352 2025/04/23 12:32:01
3 13560 0 13560 5456 19016 ~ ~ ~ ~ 19016 W 592 2025/04/23 12:36:02
4 13576 0 13576 5440 19016 ~ ~ ~ ~ 19016 W 832 2025/04/23 12:40:02
5 13576 0 13576 5440 19016 ~ ~ ~ ~ 19016 W 1072 2025/04/23 12:44:02
6 13584 -8320 5264 5440 10704 ~ ~ ~ ~ 10704 W 1072 *2025/04/23 12:44:02
7 12984 -8320 4664 5084 9748 ~ ~ ~ ~ 9748 W 1312 2025/04/23 12:48:02
[h2]Memory Maintenance and Debugging
Log file: memleak-native-[process_name]-[pid]-smaps.txt
| Field name. | Description |
| RealPssMemory | PSS value collected at realtime, in KB. |
| LOGGER_MEMCHECK_MEMINFO | Memory information of the device, including MemTotal and MemFree. |
| LOGGER_MEMCHECK_SMAPS_INFO | smaps information of the process. |
| LOGGER_MEMCHECK_SAMPLE_NMD_INFO | Information about two jemalloc allocations of the process (the interval between the two records is 5 minutes). The system captures the memory stack based on this information. |
| LOGGER_MEMCHECK_DETIAL_INFO | jemalloc snapshot details of the process. |
Generated by HiviewDFX @HarmonyOS
LOGGER_MEMCHECK_GERNAL_INFO
pidNumber: 2017
processName: process1
PidStartTime: 1602
RealPssMemory: 83505
*****************************
LOGGER_MEMCHECK_MEMINFO
MemTotal: 11332540 kB
MemFree: 1686056 kB
......
LOGGER_MEMCHECK_SMAPS_INFO
-------------------------------[memory]-------------------------------
Shared Shared Private Private
Size Rss Pss Clean Dirty Clean Dirty Swap SwapPss Counts Name
2048 0 0 0 0 0 0 0 0 1 /dev/__parameters__/param_sec_dac
...
45778196 744068 827123 213560 55288 403304 71916 308888 308888 6500 Summary
......
LOGGER_MEMCHECK_SAMPLE_NMD_INFO
size allocated nmalloc ndalloc
8 17384 511848 509675
16 129376 338438 330352
32 1138816 1026155 990567
48 3161808 1322095 1256224
64 1869376 908151 878942
......
************ endl ************
LOGGER_MEMCHECK_SAMPLE_NMD_INFO
size allocated nmalloc ndalloc
8 17384 511848 509675
16 129376 338438 330352
32 1138816 1026155 990567
48 3161808 1322095 1256224
64 1869376 908151 878942
......
************ endl ************
*****************************
LOGGER_MEMCHECK_PROC_INFO
ASHMEM_PROCESS_INFO
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------
Process_name Process_ID Fd Cnode_idx Applicant_Pid Ashmem_name Virtual_size Physical_size magic
XXXXX 816 22 328234 816 dev/ashmem/PolicyVolumeMap 541 4096 7
************ endl ************
******************************
LOGGER_MEMCHECK_DETIAL_INFO
allocated nmalloc (#/sec) ndalloc (#/sec) nrequests (#/sec) nfill (#/sec) nflush (#/sec)
small: 183785560 12591759 619 10371251 510 1289491 63 1313204 64 956094 47
large: 31059968 3359 0 2946 0 3359 0 3359 0 0 0
total: 214845528 12595118 619 10374197 510 1292850 63 1316563 64 956094 47
......
bins: size ind allocated nmalloc (#/sec) ndalloc (#/sec) nrequests (#/sec) nshards curregs curslabs nonfull_slabs regs pgs util nfills (#/sec) nflushes (#/sec) nslabs nreslabs (#/sec) n_lock_ops (#/sec) n_waiting (#/sec) n_spin_acq (#/sec) n_owner_switch (#/sec) total_wait_ns (#/sec) max_wait_ns max_n_thds
8 0 198920 163820 8 138955 6 119703 5 1 24865 56 19 512 1 0.867 6526 0 4008 0 96 26995 1 10990 0 0 0 0 0 1226 0 0 0 0 0
16 1 1802688 1143707 56 1031039 50 221165 10 1 112668 563 309 256 1 0.781 105471 5 82548 4 1942 80503 3 191126 9 0 0 14 0 4316 0 0 0 0 0
32 2 9954560 1867465 91 1556385 76 267993 13 1 311080 2614 503 128 1 0.929 177825 8 136745 6 7713 176923 8 325128 15 2 0 52 0 8139 0 0 0 0 1
48 3 35382816 3763756 185 3026614 148 300952 14 1 737142 2953 220 256 3 0.975 371881 18 283650 13 12022 60637 2 667997 32 2 0 17 0 2725 0 0 0 0 1
...... Note:
LOGGER_MEMCHECK_SAMPLE_NMD_INFO and LOGGER_MEMCHECK_DETIAL_INFO are jemalloc snapshots of a process. The differences are as follows:
LOGGER_MEMCHECK_SAMPLE_NMD_INFO: The maintenance and debugging sampling is performed twice consecutively at an interval of 5 minutes. The content contains four columns of memory application information, including size, allocated, nmalloc, and ndalloc.
LOGGER_MEMCHECK_DETIAL_INFO: The maintenance and debugging sampling is performed only once. The content contains complete jemalloc information of the process.
[h2]Memory Stack
Stack information log file: memleak-native-[process_name]-[pid]-[timestamp].txt
The 15-minute process memory trace captured after the leak is detected can be loaded to DevEco Studio for parsing by clicking Open File, as shown in the following figure.

To open the memleak-native-[process_name]-[pid]-[timestamp].txt file in DevEco Studio, change the file name extension to .nas.
Select All Heap to display the captured memory information, which records the stacks of system calls (such as malloc) hooked. Native logs display the call stack in the so. file and offset address (each line indicates the call stack of a memory allocation behavior). Further analysis is required based on the symbol table.
Click Call Trees to view the call stack of the captured process. Select Created & Existing to sort the memory blocks based on the proportion of unreleased memory. You can view the detailed process call information and preferentially check the stack with high memory usage.

Note:
- As shown in Created & Existing, since only the stack information and memory requests within 15 minutes are captured, the leaks of some stacks may not be large or much smaller than the detected peak memory usages. Actually, the leak accumulates over a long time period, which is measured in dozens or even hundreds of hours. As a result, the size of the reported leak is large.
Select All Anonymous VM to display the stack information of the hooked mmap system call.
If you select Created & Existing, the memory that is requested but not released of the hooked call is captured. The longer the length, the more the remaining memory is occupied. Check the longer process first.

[h2]native leak clustering rules
Leak problems generated by applications on the same or different versions at different time may be caused by the same cause. Developers can extract fault characteristics from fault logs and cluster multiple fault logs based on the fault characteristics to improve the efficiency of analyzing leak problems.
For a PSS_MEMORY fault, the system sends two fault logs to developers for analysis. Fault log 1 (memory maintenance and debugging) is used to store some lightweight information about the process, such as smaps, ashmem, and NMD. Fault log 2 (memory stack) is used to store stack information captured after the system detects a process pss leak.
Analyze the LOGGER_MEMCHECK_SMAPS_INFO information of the process in fault log 1, calculate the memory usage of each type based on the methods listed in the following table, and filter out the memory leak type with the highest memory usage.
| Memory Leak Type | Calculation Method |
| VM object leak | Search for the keyword "ArkTS" and calculate the percentage of the sum of the Pss and SwapPss columns to the total memory. |
| Heap memory leak | Search for the keyword "jemalloc" and calculate the percentage of the sum of the Pss and SwapPss columns to the total memory. |
| ashmem memory leak: | Search for the keyword "/dev/ashmem" and calculate the percentage of the sum of the Pss and SwapPss columns to the total memory. |
| Large anon memory | Search for the keyword "[anon]" and calculate the percentage of the sum of the values in the Pss and SwapPss columns to the total memory. |
Note:
The sum of the Pss and SwapPss columns in each row is the requested size of the corresponding memory block.
The Name column indicates the memory label of the memory block.
After the memory leak type with the highest proportion is filtered out, you can further extract the fault characteristics based on the following rules:
VM object: Filter the memory label with the largest memory application as the fault characteristic. For example, the fault label extracted from the following log is [anon:ArkTS Heapsemi space].
LOGGER_MEMCHECK_SMAPS_INFO
-------------------------------[memory]-------------------------------
Shared Shared Private Private
Size Rss Pss Clean Dirty Clean Dirty Swap SwapPss Counts Name
1662976 68744 68744 0 0 68744 0 0 0 525 [anon:ArkTS Heap]
5632 5600 2261 3452 0 2148 0 0 0 22 [anon:ArkTS Heapappspawn space]
98304 74012 74012 0 0 74012 0 0 0 307 [anon:ArkTS Heapsemi space]
... Heap memory: Filter the memory label with the maximum memory application as the fault characteristic. For example, the fault label extracted from the following log is [anon:native_heap:jemalloc].
LOGGER_MEMCHECK_SMAPS_INFO
-------------------------------[memory]-------------------------------
Shared Shared Private Private
Size Rss Pss Clean Dirty Clean Dirty Swap SwapPss Counts Name
327168 171464 146921 25416 0 146048 0 0 0 17 [anon:native_heap:jemalloc]
24600 3924 3586 348 0 3576 0 0 0 18 [anon:native_heap:jemalloc meta] If a memory call stack exists, find the memory range with the highest usage based on the NMD maintenance and debugging, and cluster the captured call stack maintenance and debugging to the specific code snippet or so. For details, see Native Leak Analysis Method.
ashmem memory: See ashmem clustering rules.
anon memory: Filter the memory label with the largest memory application as the fault characteristic. For example, the fault label extracted from the following log is [anon].
LOGGER_MEMCHECK_SMAPS_INFO
-------------------------------[memory]-------------------------------
Shared Shared Private Private
Size Rss Pss Clean Dirty Clean Dirty Swap SwapPss Counts Name
38760 528 524 4 0 524 0 0 0 56 [anon] If a memory call stack exists, analyze the clustering that accounts for a large proportion in the call stack to a specific code snippet or so. For details, see Native Leak Analysis Method.
For the no-log version, stack capture is disabled by default. Therefore, you are advised to perform preliminary clustering on the PSS memory usage types based on the smaps information.
Log Specifications of ashmem/ION/GPU/GPU_RS Memory Leaks
[h2]Memory Maintenance and Debugging
Log file: memleak-kernel-[module]-0-[timestamp].txt (Method 1).
| Field name. | Description |
| LOGGER_MEMCHECK_MEMINFO | Overview of the device memory information. |
| LOGGER_MEMCHECK_PROC_INFO | Information about the ashmem, ION, or GPU memory leak node. (The content varies according to the leak type.) |
| LOGGER_PROCESS_DMABUF_INFO | Special node content obtained when the ION memory leak occurs, which contains more memory block usage information. |
| LOGGER_MEMCHECK_RENDER_SERVICE_MEM | Memory usage of the Render_service process. |
When an ashmem, GPU or ION memory leak is detected, the ashmem, GPU or ION memory information of the entire device is captured. The specifications of ashmem and ION logs are the same as those of ashmem and dmabuf handle leak logs. For details, see ashmem and dmabuf handles.
Log header:
Generated by HiviewDFX @HarmonyOS
LOGGER_MEMCHECK_GERNAL_INFO
memoryName:ion
softThreshold:2800(MB)
hardThreshold:4200(MB)
appHardThreshold:4096(MB)
topMemory:0(KB)
*****************************
LOGGER_MEMCHECK_MEMINFO
MemTotal: 11738500 kB
MemFree: 116204 kB
MemAvailable: 95232 kB
Buffers: 0 kB
LOGGER_MEMCHECK_PROC_INFO in the log file records the memory information based on the memory leak type. The details are as follows:
ashmem memory leak:
LOGGER_MEMCHECK_PROC_INFO
realtime: 2025/05/30 19:52:42
Process ashmem overview info:
---------------------------------------------------------------------------------
Process_name Virtual_size Physical_size
Total ashmem of [XXXXXX] virtual size is 541, physical size is 4096
Total ashmem of [XXXXXX] virtual size is 299008, physical size is 299008
Total ashmem of [XXXXXX] virtual size is 37574896, physical size is 37470208
......
Process ashmem detail info:
---------------------------------------------------------------------------------
Process_name Process_ID Fd Cnode_idx Applicant_Pid Ashmem_name Virtual_size Physical_size magic
XXXXX 816 22 328234 816 dev/ashmem/PolicyVolumeMap 541 4096 7
......
---------------------------------------------------------------------------------
*****************************
LOGGER_MEMCHECK_RENDER_SERVICE_MEM
get info realtime: 2025/05/30 19:52:42
-------------------------------[ability]-------------------------------
----------------------------------RenderService----------------------------------
......
ION memory leak.
*****************************
LOGGER_MEMCHECK_PROC_INFO
MM_DMABUF_INFO
realtime: 2025/07/26 14:19:58
Process pid fd size_bytes ino exp_pid exp_task_comm buf_name exp_name buf_type
process1 1563 71 13926400 25690 11187 allocator_host 11563 mm_heap_helpers xcomponent
process1 1563 75 1024000000 21095 11187 allocator_host 11563 mm_heap_helpers NULL
process1 1563 77 1024000000 11557 11187 allocator_host 11563 mm_heap_helpers NULL
process1 1563 79 1024000000 26747 11187 allocator_host 11563 mm_heap_helpers NULL
************ endl ************
*****************************
LOGGER_MEMCHECK_RENDER_SERVICE_MEM
get info realtime: 2025/05/30 21:17:39
-------------------------------[ability]-------------------------------
----------------------------------RenderService----------------------------------
......
Since HarmonyOS 6.0.0, columns such as buf_name and leak_type are added to the ion memory maintenance and debugging information. The format is changed as follows:
*****************************
LOGGER_MEMCHECK_PROC_INFO
MM_DMABUF_INFO
Process pid fd size_bytes ino exp_pid exp_task_comm buf_name exp_name buf_type leak_type
process1 65141 268 274432 430936 42829 allocator_host 65141 mm_heap_helpers NULL NULL
......
************ endl ************
Field Description
| Field name. | Description |
| Process | Bundle name of the application process that holds the ION memory block (truncated to 16 characters). |
| pid | PID of the faulty process. |
| fd | Handle held by the process. |
| size_bytes | Size of the ION buffer held by the process, in bytes. |
| ino | Inode number of the file. |
| exp_pid | PID of the process that applies for the ION memory from the kernel. |
| exp_task_comm | Name of the process that applies for the ION memory from the kernel. |
| buf_name | Name of the ION buffer. |
| exp_name | Extension name of the ION buffer. |
| buf_type | Type of the ION buffer. |
| leak_type | Type of the ION buffer used for memory leak maintenance and debugging. |
GPU/GPU_RS memory leak:
LOGGER_MEMCHECK_PROC_INFO
GPU_PROCESS_INFO
render_service
ctx_1 1689 1455 used summary:3362426880 grow:0 driver:10432512 kmd:3260416 jit:131072
process1
Channel: xx default device (Total memory: 730594)
1: 2 / 2
6: 4 / 160
7: 6 / 384
8: 163 / 20928
9: 1573 / 604160
10: 48 / 24576
11: 2 / 2048
13: 2 / 12800
15: 4 / 65536
......
*****************************
LOGGER_MEMCHECK_RENDER_SERVICE_MEM
get info realtime: 2025/05/30 21:16:01
-------------------------------[ability]-------------------------------
----------------------------------RenderService----------------------------------
Field Description
- ''ctx_1 1689 1455 used summary:3362426880 grow:0 driver:10432512 kmd:3260416 jit:131072
process1 indicates that the context ctx_1 is created by process1. The process ID is 1455, the thread ID is 1689, and the total usage is 3362426880 bytes.
"Channel: xx default device (Total memory: 730594)" indicates that the size of the GPU memory of the "xx default device" type applied for by the process is 730594 bytes.
"15: 4 / 65536" indicates that memory blocks of 2^14 to 2^15 bytes are allocated four times, and a total of 65536 bytes of memory are allocated.
Note:
Differences between the GPU_RS memory leak and the GPU memory leak: The GPU memory leak is caused by application self-rendering, while the GPU_RS memory leak is caused by unified rendering through the render_service process.
In the resource leak information, ION, dmaheap, and dmabuf can be regarded as the same memory type.
The current log specifications may change in rows, columns, and paragraphs based on version issues and user feedback.
[h2]Memory Stack
Since HarmonyOS 6.0.0, the call stack of GPU memory allocation can be captured to analyze GPU memory leaks in processes. After a leak is detected, the GPU memory allocation trace within 15 minutes is collected. You can set up a local Smartperf environment and import the Profiler logs for parsing.
Log file name: memleak-kernel-[module]-[pid]-[timestamp].txt
[h2]ashmem/ion/gpu/gpu_rs clustering rules
Leakage issues of an application generated at different times in the same or different versions may be caused by the same reason. You can extract fault characteristics from fault logs and cluster multiple fault logs based on the fault characteristics to improve the analysis efficiency of leakage issues.
ashmem clustering rules
Extract the ashmem maintenance and debugging information from the fault logs for clustering.
Process_name Process_ID Fd Cnode_idx Applicant_Pid Ashmem_name Virtual_size Physical_size magic
XXXXX 816 22 328234 816 dev/ashmem/PolicyVolumeMap 541 4096 7
XXXXX 816 22 328234 816 dev/ashmem/PolicyVolumeMap 541 4096 7
XXXXX 816 22 328234 816 dev/ashmem/inputBuffer 541 1024 7
XXXXX 816 22 328234 816 dev/ashmem/outputBuffer 541 512 7
......
Analyze the Ashmem_name field in ashmem maintenance and debugging to check whether the buffer leak is of the same type. Use the buffer with the highest sum of values in the Physical_size column as the fault feature.
ion clustering rules
Extract the ion maintenance and debugging information from the fault logs for clustering.
*****************************
LOGGER_MEMCHECK_PROC_INFO
MM_DMABUF_INFO
Process pid fd size_bytes ino exp_pid exp_task_comm buf_name exp_name buf_type leak_type
process1 65141 246 278528 432510 42829 allocator_host 65141 mm_heap_helpers NULL NULL
process1 65141 247 266240 434225 42829 allocator_host 65141 mm_heap_helpers NULL NULL
process1 65141 248 274432 430933 42829 allocator_host 65141 mm_heap_helpers NULL NULL
process1 65141 264 14036992 432500 42829 allocator_host https://xxxx/xxxxx.png mm_heap_helpers pixelmap pixelmap
process1 65141 266 14036992 426988 42829 allocator_host https://xxxx/xxxxx.png mm_heap_helpers pixelmap pixelmap
process1 65141 268 14036992 430936 42829 allocator_host https://xxxx/xxxxx.png mm_heap_helpers pixelmap pixelmap
process1 65141 258 4493312 432499 42829 allocator_host srcImageSize-2160x2880-pixelMapSize-2160x2880-streamsize-761322-mimetype-webp mm_heap_helpers NULL NULL
process1 65141 260 4493312 426987 42829 allocator_host srcImageSize-2160x2880-pixelMapSize-2160x2880-streamsize-761322-mimetype-webp mm_heap_helpers NULL NULL
process1 65141 262 4493312 431689 42829 allocator_host srcImageSize-2160x2880-pixelMapSize-2160x2880-streamsize-761322-mimetype-webp mm_heap_helpers NULL NULL
process1 65141 254 4493312 430935 42829 allocator_host srcImageSize-2160x2880-pixelMapSize-2160x2880-streamsize-761322-mimetype-webp mm_heap_helpers NULL NULL
process1 65141 256 4493312 431688 42829 allocator_host srcImageSize-2160x2880-pixelMapSize-2160x2880-streamsize-761322-mimetype-webp mm_heap_helpers NULL NULL
process1 65141 250 4493312 432498 42829 allocator_host srcImageSize-2160x2880-pixelMapSize-2160x2880-streamsize-761322-mimetype-webp mm_heap_helpers NULL NULL
process1 65141 252 4493312 430934 42829 allocator_host srcImageSize-2160x2880-pixelMapSize-2160x2880-streamsize-761322-mimetype-webp mm_heap_helpers NULL NULL
************ endl ************
Classify buffers based on leak_type and buf_name, and extract the buf_name of the buffer with the highest proportion of the sum of size_bytes as the fault feature. For details about the analysis, see ION Leak Analysis Method.
Note:
If leak_type is NULL, there may be multiple types of buffers, which can be distinguished by buf_name.
gpu/gpu_rs clustering rules
Parse the GPU maintenance and debugging information provided in the fault log, collect statistics on the lines that contain the "Total memory:" field, parse the GPU memory usage of the corresponding type, and select the GPU memory type with the highest usage as the fault feature. For example, in the following maintenance and debugging information, the GPU memory usage of the host default memory type is 1789351 bytes, which can be used as a fault feature for clustering.
C: cq memory(not in total memory) (Total memory: 4096)
13: 1 / 4096
C: vulkan external memory(not in total memory) (Total memory: 0)
(empty)
C: host default memory (Total memory: 1789351)
5: 269 / 4304
6: 370 / 15792
7: 401 / 33088
8: 96 / 14240
9: 449 / 141696
10: 265 / 173143
11: 172 / 236391
12: 68 / 187012
13: 35 / 197576
14: 17 / 251573
15: 6 / 108304
16: 1 / 51736
17: 1 / 84184
19: 1 / 290312
After clustering to the GPU memory type, the memory segment with the largest usage is filtered out and clustering is performed.
The GPU representation varies depending on the chip platform.
C: host default memory (Total memory: 1789351).
Channel: Texture (Total memory: 1789351).
Kernel Management and Control Log Specifications
When kernel control is triggered, the system resources are insufficient to support the capture of maintenance and debugging information with high overhead. Therefore, only basic maintenance and debugging information can be provided to support preliminary demarcation and locating.
The general content of kernel control logs is as follows:
| Field name. | Description |
| pidNumber | PID of the leaked application. |
| processName | Leaked application process name. |
| killTime | Time when an application is killed. |
| RssMemory | RSS memory usage of the leaked application, in KB. |
| killReason | Reason why the app is killed. |
Generated by HiviewDFX @HarmonyOS
LOGGER_MEMCHECK_GERNAL_INFO
pidNumber: 2017
processName: process1
killTime: 20260512090030
killReason: RssThresholdKiller
RssMemory: 8350500
Description
RssMemory indicates the total RSS memory size displayed in the log after the application triggers RSS kernel control. Similarly, GpuMemory, IonMemory, and AshmemMemory indicate the memory size displayed in the kernel control logs.
[h2]GPU Kernel Control
Overview: When the GPU memory leak of an application exceeds 1/3 of the running memory of the entire system and the memory of the entire system is low, the GPU kernel control is triggered.
Log file: memleak-kernel-[module]-0-[timestamp].txt (method 1) or RESOURCE_OVERLIMIT_[TIMESTAMP]_[PID].log (method 3)
The GPU kernel control log content is the same as the maintenance and debugging content under the LOGGER_MEMCHECK_PROC_INFO field in GPU Memory Leak Log Specifications.
[h2]ashmem Kernel Control
Overview: When the ashmem memory leak exceeds 1/3 of the running memory of the entire system and the memory of the entire system is low, the ashmem kernel control is triggered.
Log file: memleak-kernel-[module]-0-[timestamp].txt (method 1) or RESOURCE_OVERLIMIT_[TIMESTAMP]_[PID].log (method 3)
The ashmem kernel management and control log is consistent with the maintenance and debugging information under the LOGGER_MEMCHECK_PROC_INFO field in ashmem Memory Leak Log Specifications.
[h2]Ion Kernel Control
Overview: When the application ion memory leak exceeds 1/3 of the running memory of the entire system and the entire system is in the low memory state, the ion kernel control is triggered.
Log file: memleak-kernel-[module]-0-[timestamp].txt (method 1) or RESOURCE_OVERLIMIT_[TIMESTAMP]_[PID].log (method 3)
The content of the ion kernel control log is the same as the maintenance and debugging content under the LOGGER_MEMCHECK_PROC_INFO field in ion Memory Leak Log Specifications.
[h2]Thread Kernel Control
Overview: If too many threads are applied for and the scheduling of the entire system is insufficient, thread kernel control is triggered.
Log file: threadleak-#{module}-#{pid}-log-#{timestamp}.txt (method 1) or RESOURCE_OVERLIMIT_[TIMESTAMP]_[PID].log (method 3)
The content of the thread kernel control log is as follows:
| Field name. | Description |
| pidNumber | PID of the leaked app. |
| processName | Leaked application process name. |
| killTime | Time when an application is killed. |
| foreGround | Application foreground and background status. The options are yes and no. |
| killReason | Reason why the app is killed. |
| threadCount | Total number of threads created by the app. |
Generated by HiviewDFX @HarmonyOS
LOGGER_MEMCHECK_GERNAL_INFO
pidNumber : 8387
processName : process1
killTime : 20260512090030
foreGround : no
killReason : ThreadKiller
threadCount : 3001
the process is killed by runnable thread threshold 3001 / 4124.
process1:2099
Thread_HI:9
Thread_GI:9
Thread_FI:9
Thread_DI:9
Thread_BI:9
Thread_EI:9
Thread_AI:9
Thread_CI:9
......
Description
Logs show the top 10 number of threads, such as "process1" and "Thread_HI," after clustering by thread name. process1:2099 indicates that the number of threads process1 is 2099.
In the preceding information, "the process is killed by runnable thread threshold 3001 / 4124." indicates that the total number of threads is 4124 and the total number of threads in the running and runnable states is 3001.