A memory processing method, apparatus, device, medium, and program product

By analyzing the memory node and connection attributes in memory snapshot files, the amount of reclaimable memory can be quickly calculated, solving the problem of memory leak detection in computer devices and improving memory management efficiency.

CN117009118BActive Publication Date: 2026-11-17TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211276708.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-17
Publication Date
2026-11-17
Estimated Expiration
2042-10-17

AI Technical Summary

Technical Problem

Existing technologies make it difficult to quickly detect and locate memory leaks in computer devices, leading to decreased operating efficiency and wasted memory.

Method used

By obtaining a memory snapshot file of the memory space, analyzing the node attributes and connection attributes of memory nodes, determining the connection relationships, calculating the amount of reclaimable memory, and quickly locating the memory leak.

Benefits of technology

It enables rapid and accurate location of memory leaks, improves memory reclamation efficiency, and avoids memory waste and performance degradation in computer devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117009118B_ABST
    Figure CN117009118B_ABST
Patent Text Reader

Abstract

This application discloses a memory processing method, apparatus, device, medium, and program product. The method includes: acquiring a memory snapshot file of the memory space and analyzing the memory snapshot file to obtain descriptive data of the memory space; determining the connection relationship between memory nodes based on the node attributes of each memory node and the edge attributes of each connecting edge; determining the root memory node, the target memory node that is reachable from the root memory node, and the reference memory node that is unreachable from the root memory node based on the connection relationship between the memory nodes; and calculating the amount of reclaimable memory of the target memory node based on the node attributes of the target memory node and the reference memory node. Using this application embodiment, the amount of reclaimable memory of each memory node can be quickly calculated, thereby rapidly locating the location of memory leaks.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a memory processing method, a memory processing device, a computer equipment, a computer-readable storage medium, and a computer program product. Background Technology

[0002] A memory leak occurs when dynamically allocated heap memory in a program (such as a server program or a client program) is not released or cannot be released for some reason. When a computer device has a memory leak problem, it may prevent other running programs from allocating memory, affecting the operating efficiency and speed of the computer device.

[0003] Therefore, how to quickly detect memory leaks in computer devices has become a hot research topic in the field of memory leak detection. Summary of the Invention

[0004] This application provides a memory processing method, apparatus, device, medium, and program product that can directly analyze memory snapshot files, quickly calculate the amount of reclaimable memory for each memory node, and thus locate the location of memory leaks relatively quickly.

[0005] On one hand, embodiments of this application provide a memory processing method, the method comprising:

[0006] Obtain a memory snapshot file of the memory space, and analyze and process the memory snapshot file to obtain the description data of the memory space. The description data includes: the node attributes of each memory node obtained by dividing the memory space, and the edge attributes of each edge connecting each memory node.

[0007] The connection relationships between memory nodes are determined based on the node attributes of each memory node and the edge attributes of each connected edge.

[0008] Based on the connection relationships between memory nodes, the root memory node, the target memory node that is reachable from the root memory node, and the reference memory node that is unreachable from the root memory node are determined from the memory nodes.

[0009] Based on the target memory node and the reference memory node that is unreachable from the root memory node, calculate the amount of reclaimable memory for the target memory node. The amount of reclaimable memory is used to characterize the amount of memory that can be reclaimed after the target memory node is released.

[0010] On the other hand, embodiments of this application provide a memory processing apparatus, the apparatus comprising:

[0011] The acquisition unit is used to acquire a memory snapshot file of the memory space and analyze and process the memory snapshot file to obtain the description data of the memory space. The description data includes: the node attributes of each memory node obtained by dividing the memory space, and the edge attributes of each edge connecting each memory node.

[0012] The processing unit is used to determine the connection relationship between memory nodes based on the node attributes of each memory node and the edge attributes of each connected edge.

[0013] The processing unit is also used to determine the root memory node, the target memory node that is reachable from the root memory node, and the reference memory node that is unreachable from the root memory node based on the connection relationship between the memory nodes.

[0014] The processing unit is also used to calculate the amount of reclaimable memory of the target memory node based on the target memory node and the reference memory nodes that are unreachable from the root memory node. The amount of reclaimable memory is used to characterize the amount of memory that can be reclaimed after the target memory node is released.

[0015] In one implementation, the node attributes of any memory node include an edge holding attribute, which is used to represent: when any memory node is a parent memory node, the connected edges associated with any memory node; the connected edges are directed edges, and the edge attributes of any connected edge include an edge pointing attribute, which is used to represent the child memory node pointed to by any connected edge.

[0016] The processing unit, used to determine the connection relationships between memory nodes based on the node attributes of each memory node and the edge attributes of each connected edge, specifically performs the following functions:

[0017] Based on the attribute values ​​held by the edges of each memory node, determine the parent memory node associated with each edge; and,

[0018] Based on the attribute value of the edge pointing attribute of each edge, determine the child memory node pointed to by each edge;

[0019] A memory graph of the memory space is constructed based on the parent memory node and the child memory node that each edge is associated with. The memory graph is a directed graph obtained by connecting each memory node with each edge. The memory graph can be used to represent the connection relationship between each memory node included in the memory space.

[0020] In one implementation, the node attributes of a memory node include the node's memory size, and the attribute value of the node's memory size is the memory size value; if the target memory node is the root memory node, then the reference memory nodes that are unreachable from the root memory node include: all memory nodes in the memory graph except the root memory node.

[0021] The processing unit, used to calculate the amount of reclaimable memory for a target memory node based on the node attributes of the target memory node and the node attributes of the reference memory node, specifically performs the following functions:

[0022] Add the memory value of the root memory node to the memory values ​​of all memory nodes in the memory graph except the root memory node to obtain the first summed memory value.

[0023] The first sum of memory amounts is used as the amount of reclaimable memory for the root memory node.

[0024] In one implementation, the node attributes of a memory node include the node memory amount, and the attribute value of the node memory amount is the memory amount value; if the target memory node is the end memory node in the memory graph, and the end memory node is a memory node in the memory graph that is not associated as a parent memory node as an edge, then there is no reference memory node that is unreachable from the root memory node.

[0025] The processing unit, used to calculate the amount of reclaimable memory for a target memory node based on the node attributes of the target memory node and the node attributes of the reference memory node, specifically performs the following functions:

[0026] The amount of memory in the target memory node is taken as the amount of reclaimable memory in the target memory node.

[0027] In one implementation, the target memory node is any memory node in the memory graph other than the root memory node and the terminal memory node; the terminal memory node is a memory node in the memory graph that is not associated with a parent memory node as an edge.

[0028] The processing unit, used to determine reference memory nodes that are unreachable from the root memory node from the memory graph, specifically performs the following functions:

[0029] Remove the target memory node from the memory graph to obtain the updated memory graph;

[0030] Starting from the root memory node in the updated memory graph, traverse each memory node in the updated memory graph along the connecting edges.

[0031] Memory nodes that are not traversed in the updated memory graph are used as reference memory nodes that are unreachable from the root memory node.

[0032] In one implementation, the node attributes of a memory node include the node's memory size, and the attribute value of the node's memory size is a numerical value of the memory size. The processing unit, when calculating the reclaimable memory size of the target memory node based on the node attributes of the target memory node and the node attributes of the reference memory node, specifically performs the following:

[0033] The memory value of the target memory node is added to the memory value of the reference memory node to obtain the second sum of memory values.

[0034] The second sum of memory amounts is used as the amount of reclaimable memory for the target memory node.

[0035] In one implementation, if there are edges of weak reference type in the memory graph, the processing unit is further used for:

[0036] During the traversal of the updated memory nodes along the edges, the memory nodes in the memory graph are not traversed along the edges of weak reference property types.

[0037] In one implementation, the description data further includes node attribute types for node attributes and edge types for each connected edge; the memory snapshot file includes node attribute fields, node attribute type fields, edge attribute fields, and edge type fields; the processing unit, used to analyze and process the memory snapshot file to obtain the description data of the memory space, specifically for:

[0038] Perform attribute analysis on the node attribute field to obtain the node attributes of each memory node in the memory space, and perform attribute type analysis on the node attribute type field to obtain the attribute type of the node attribute.

[0039] In addition, attribute analysis is performed on the edge attribute field to obtain the edge attributes of the connecting edges that connect each memory node, and type analysis is performed on the edge type field to obtain the edge type of the connecting edge.

[0040] The node attributes include at least one of the following: node type, node identifier, node number, node memory size, edge holding attribute, and node memory indicator identifier. The edge holding attribute is used to indicate the number of edges with the memory node as the parent memory node. The edge attributes include at least one of the following: edge type, edge identifier, and edge pointing attribute. The edge pointing attribute is used to indicate the child memory node pointed to by the edge.

[0041] In one implementation, the description data further includes attribute values ​​of node attributes of memory nodes and attribute values ​​of edge attributes of connected edges; the memory snapshot file also includes an attribute value array and a data query array, the attribute value array including attribute values ​​of the target attribute, and the data query array including query identifiers of the target attribute, wherein the target attribute is a node attribute or an edge attribute; the processing unit is further configured to:

[0042] Determine the query identifier associated with the target attribute from the data query array;

[0043] Generate index values ​​for target attributes based on query identifiers associated with target attributes;

[0044] Determine the attribute value of the target attribute from the attribute value array according to the index value of the target attribute.

[0045] In one implementation, the node attributes of a memory node include the node's memory size, and the attribute value of the node's memory size is a numerical value representing the memory size; the processing unit is further configured to:

[0046] Compare the node memory amount of the target memory node with the reclaimable memory amount of the target memory node to obtain the memory amount comparison result;

[0047] If the memory quantity comparison result meets the memory leak condition, then the target memory node is regarded as the leaking memory node with memory leak;

[0048] The conditions for memory leaks include: the difference between the value of the node memory of the target memory node and the amount of reclaimable memory of the target memory node is greater than the memory threshold.

[0049] In one implementation, the processing unit is further used for:

[0050] Output a node relationship graph, which is a directed graph obtained by connecting each memory node with edges based on the connection relationship between each memory node.

[0051] Visually highlight one or more leaking memory nodes in the node relationship graph.

[0052] In one implementation, the processing unit is further used for:

[0053] When any memory node in the node relationship graph is triggered, the node information of that memory node is displayed;

[0054] The node information of a memory node includes at least one of the following: node identifier, node number, node memory amount, child memory nodes associated with the node when it is a parent memory node, parent memory node associated with the node when it is a child memory node, and reclaimable memory amount.

[0055] On the other hand, embodiments of this application provide a computer device, the device comprising:

[0056] A processor is used to load and execute computer programs;

[0057] A computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described memory processing method.

[0058] On the other hand, embodiments of this application provide a computer-readable storage medium storing a computer program adapted to be loaded by a processor and executed by the above-described memory processing method.

[0059] On the other hand, embodiments of this application provide a computer program product or computer program that includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and when executed by the processor, the computer instructions implement the aforementioned memory processing method.

[0060] This application supports obtaining memory snapshot files of the memory space and directly analyzing and processing these files to obtain descriptive data of the memory space. This descriptive data may include node attributes of each memory node and edge attributes of the edges connecting each memory node. Based on these node attributes and edge attributes, the connection relationships between memory nodes can be determined. Then, based on these connection relationships, the root memory node, the target memory node reachable from the root memory node, and the reference memory node unreachable from the root memory node can be determined from each memory space. Finally, based on the target memory node and the reference memory nodes, the amount of reclaimable memory for the target memory node can be calculated. In this scheme, there is no need to convert the connection relationships between memory nodes in the memory snapshot file of the memory space; the amount of reclaimable memory for each memory node can be quickly calculated directly based on these connection relationships, thereby helping developers quickly locate memory nodes with memory leaks. Attached Figure Description

[0061] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0062] Figure 1 This is an overall flowchart of a memory processing scheme provided in an exemplary embodiment of this application;

[0063] Figure 2 This is a schematic diagram illustrating the generation of a Wasm file according to an exemplary embodiment of this application;

[0064] Figure 3 This is a flowchart illustrating a memory processing method provided in an exemplary embodiment of this application;

[0065] Figure 4a This is a schematic diagram illustrating an exemplary embodiment of this application for obtaining a memory snapshot file;

[0066] Figure 4bThis is a schematic diagram illustrating another method for obtaining a memory snapshot file, provided by an exemplary embodiment of this application.

[0067] Figure 5 This is a schematic diagram illustrating the connection relationship between memory nodes according to an exemplary embodiment of this application;

[0068] Figure 6 This is a schematic diagram illustrating the correspondence between memory nodes and connecting edges provided in an exemplary embodiment of this application;

[0069] Figure 7a This is a schematic diagram illustrating the calculation of the reclaimable memory amount of a target memory node, provided in an exemplary embodiment of this application.

[0070] Figure 7b This is a schematic diagram illustrating the calculation of the reclaimable memory amount of the root memory node when the target memory node is the root memory node, provided by an exemplary embodiment of this application.

[0071] Figure 7c This is a schematic diagram illustrating the calculation of the amount of reclaimable memory of a target memory node when the target memory node is an end memory node, provided by an exemplary embodiment of this application.

[0072] Figure 7d This is a schematic diagram illustrating the calculation of the reclaimable memory amount of an intermediate memory node when the target memory node is an intermediate memory node, provided by an exemplary embodiment of this application.

[0073] Figure 8 This is a flowchart illustrating another memory processing method provided in an exemplary embodiment of this application;

[0074] Figure 9 This is a schematic diagram of a node relationship diagram provided in an exemplary embodiment of this application;

[0075] Figure 10 This is a schematic diagram illustrating a method for visually highlighting a leaking memory node in a node relationship graph, provided by an exemplary embodiment of this application.

[0076] Figure 11 This is a schematic diagram illustrating how to view node information of any memory node in a node relationship graph, provided by an exemplary embodiment of this application.

[0077] Figure 12 This is a schematic diagram of the structure of a memory processing device provided in an exemplary embodiment of this application;

[0078] Figure 13 This is a schematic diagram of the structure of a computer device provided in an exemplary embodiment of this application. Detailed Implementation

[0079] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.

[0080] The following is a brief introduction to the technical terms and related concepts involved in the embodiments of this application, wherein:

[0081] (1) Memory Space.

[0082] Memory space is also called executable memory or storage space. Computer devices have memory space deployed in them; memory space can be used to store data processed by devices deployed in the computer device (such as graphics processing unit (GPU) and central processing unit (CPU)), as well as data exchanged with external memory space (which is relative to the internal memory space of the computer device), and so on.

[0083] Considering that the CPU may access different memory units at different times, it is supported to use memory nodes to describe the memory space. Specifically, the CPU is divided into multiple memory nodes, and the memory space is divided into multiple memory banks. Since each CPU corresponds to one memory space, it can be considered that one memory node corresponds to one memory bank. Each memory node is associated with a processor in the system. Each memory node in the system is linked to a linked list to obtain the connection relationship of each memory node. In this way, each memory node in the linked list can be used to represent the execution location of one or more objects in the program.

[0084] The memory lifecycle of the computer programming language JavaScript (or simply JS, a lightweight, interpreted or just-in-time compiled programming language with function priority, used as a scripting language for developing web pages) can include: allocating memory space required by the program → using the allocated memory space (such as reading and writing data in the memory space) → releasing or returning the memory space when it is no longer needed. Specifically: ① The first step in the memory lifecycle, "allocating memory space required by the program," refers to allocating the memory space needed for the program to run; this allocation of memory space for variables (or programs) is completed when JavaScript defines program variables. ② The second step in the memory lifecycle, "using the allocated memory space," refers to the ability to read and write data (including read and write operations) within the allocated memory space during program execution; the program automatically uses the allocated memory space based on its address. ③ The third step in the memory lifecycle, "releasing (or returning, reclaiming) memory space when no longer needed," refers to detecting variables or data that are no longer in use and then releasing the memory space they occupy. Memory space reclamation often relies on the automatic execution of the garbage collection mechanism. The garbage collection mechanism (or garbage collector) provides a mechanism for reclaiming memory space, supporting the intermittent reclamation of objects that have no references when memory space is idle or memory space usage (such as high utilization rate). Therefore, as can be seen from the above description of the memory lifecycle, memory space reclamation plays a crucial role in the operating speed and efficiency of computer equipment.

[0085] (2) Memory leak.

[0086] As described above regarding the memory lifecycle, it includes a memory reclamation step. By automatically reclaiming unused memory, it ensures that other programs running on the computer can request memory, thus maintaining the normal operation of the computer. However, for some reason, memory reclamation during the memory lifecycle may not execute properly, indicating a memory leak. In other words, a memory leak refers to the situation where, after dynamically allocating memory for a program (such as an application or service), the program fails to release the allocated memory for some reason.

[0087] It should be noted that the memory space mentioned in the embodiments of this application may refer to the heap memory dynamically allocated by a computer device (such as a server) for a program. Heap memory is a contiguous memory space (or memory region); it supports storing shared data or exchanged information in heap memory, so that when multiple programs run simultaneously, they can share data or information through this heap memory. Of course, memory space can also be the main memory space (physical address space) of a computer device. For ease of explanation, the embodiments of this application use heap memory allocated for an application as an example for illustration, which will be explained here.

[0088] In practical applications, with the increasing demands of computer applications, such as the growing variety and number of applications that servers need to run, the number of variables and data that computer devices need to process has also increased significantly. For example, servers need to run applications for extended periods, constantly processing requests from clients, resulting in a large number of variables and data being processed. If memory space is not effectively managed, memory leaks can occur with each processing request. Considering that front-end developers often lack server-side programming knowledge, especially when encountering memory leaks using Node.js, it can be difficult to pinpoint the location of the leak. This can lead to unused memory not being released in a timely manner, potentially preventing other running programs from allocating memory, resulting in wasted memory. This not only affects server performance but can also cause the entire system to crash. Node.js is a JavaScript runtime environment based on the Chrome V8 engine, using an event-driven and non-blocking I / O model, making it lightweight and efficient. V8 is an open-source JavaScript engine developed by Google, used in Google Chrome and Chromium, and is also the runtime engine for Node.js.

[0089] Based on this, this application provides a memory processing solution that supports direct analysis of memory snapshot files (or simply memory snapshots) of the memory space to quickly obtain useful information and help developers quickly locate memory leaks in server programs. A memory snapshot refers to recording all data in the memory space at a target time (such as any time) and saving it as a file on the hard drive. With a memory snapshot, even if the computer crashes, the full data in the memory space at the target time can still be recovered through the memory snapshot. In the case of heap memory, the memory snapshot can be simply referred to as a heap snapshot, and this application does not limit this terminology.

[0090] The memory processing scheme provided in this application's embodiments can be found in [reference needed]. Figure 1 ,like Figure 1 As shown, the general process of the memory processing solution includes: First, obtaining a memory snapshot file of the memory space. This snapshot file is unreadable, so it needs to be analyzed and processed to format it into a more readable structure. This analysis may include analyzing one or more memory nodes (such as node attributes) and the edges connecting the memory nodes (such as edge attributes). Then, based on the analysis results, the unreadable memory snapshot is serialized into a more readable JSON (JavaScript Object Notation) structure. JSON is the data exchange format of JavaScript mentioned above, which helps to better analyze the relationships between memory nodes. Second, based on the connection relationships between memory nodes expressed in the more readable JSON structure, the amount of reclaimable memory (retained_size) for each memory node is calculated. This reclaimable memory amount represents the amount of memory (or memory quantity) that can be reclaimed by the garbage collection mechanism after the target memory node is released. Finally, based on the amount of reclaimable memory for each memory node and its own node memory, the system identifies leaking memory nodes from one or more memory nodes within the memory space. This allows for the proactive release of leaking memory nodes, resolving memory leaks and achieving efficient memory reclamation.

[0091] The memory processing solution provided in this application does not require conversion of the connection relationships between memory nodes in the memory snapshot file of the memory space. It can directly calculate the amount of reclaimable memory for each memory node based on the connection relationships between memory nodes in the memory space, helping developers to quickly locate memory nodes with memory leaks.

[0092] Based on the above brief description of the memory processing scheme provided in the embodiments of this application, the following points are worth noting:

[0093] ① To improve the detection speed of memory leaks, this application embodiment supports using a target programming language to write the analysis logic code for the memory processing scheme, thereby achieving high-performance analysis. For example, if the target programming language is Rust, a general-purpose compiled programming language that follows design principles such as "safety, concurrency, and practicality," and supports functional, parallel, procedural, and object-oriented programming styles, then using Rust instead of JavaScript can improve computation speed and achieve higher analysis performance. Furthermore, considering that current browsers do not support running code encoded in Rust, after writing the target code for the memory processing scheme in Rust, a compilation tool is needed to compile the Rust-encoded code into a Wasm file that can be run in a browser. This allows the browser to call the Wasm file to implement the memory processing scheme provided in this application embodiment, improving analysis performance. The exemplary process for generating the Wasm file can be found in [reference needed]. Figure 2 The compilation tools can include WebAssembly, a client-side application used within the browser. It is a portable abstract syntax tree designed to provide faster compilation and execution than JavaScript. WebAssembly allows developers to compile their projects using familiar programming languages ​​(such as Rust or C) and then execute them within the browser by a virtual machine engine, achieving efficient compilation.

[0094] ② The computer device used to execute the memory processing scheme in this application embodiment may include a server; such as the backend server corresponding to a browser, which triggers the server to execute the memory processing scheme provided in this application embodiment by calling the aforementioned wasm file in the browser. The server may be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms; this application embodiment does not limit the specific type of server.

[0095] Based on the memory processing scheme described above, this application proposes a more detailed memory processing method. The memory processing method proposed in this application will be described in detail below with reference to the accompanying drawings.

[0096] Figure 3 The illustration shows a flowchart of a memory processing method provided in an exemplary embodiment of this application; the memory processing method can be executed by the aforementioned computer device, and the memory processing method may include, but is not limited to, steps S301-S304:

[0097] S301. Obtain a memory snapshot file of the memory space, and analyze and process the memory snapshot file to obtain descriptive data of the memory space.

[0098] In specific implementation, when a developer needs to detect the location of a memory leak in the memory space, a memory snapshot file of the memory space at a target time can be obtained. This target time refers to the moment when the developer wants to determine the existence of a memory leak, often the moment the developer triggers the acquisition of the memory snapshot file. The memory snapshot file is then analyzed and processed by calling a Wasm file in the browser to obtain descriptive data about the memory space at the target time. The developer may need to analyze the location of a memory leak when they determine that the system is running slowly, has high memory usage, or is experiencing system lag. This application embodiment does not limit the specific needs of the developer to analyze the location of memory leaks.

[0099] As described above, the embodiments of this application use Rust to write the analysis logic code for the memory processing scheme. Therefore, Rust can be used to call the V8 runtime engine interface to obtain a memory snapshot file of the memory space. The code snippet of Rust calling the V8 runtime engine is as follows:

[0100] Pub unsafe fn get_current()->0wnedIsolate{

[0101] 0wnedIsolate::new(v8__Isolate__GetCurrent())

[0102] }

[0103] In practical applications, this application does not limit the method of obtaining memory snapshot files of memory space. Two exemplary methods for obtaining memory snapshot files of memory space are given below with reference to the accompanying drawings:

[0104] (1) The computer device supports receiving memory snapshot files of the memory space sent by the development object, and executes subsequent memory processing schemes based on the received memory snapshot files. In other words, the memory snapshot file of the memory space can be obtained by the development object at any time; when the development object has the ability to locate the location of the memory leak in the memory space at any given time, the development object can use the memory snapshot file as input to the Wasm file to enable the computer device to obtain the memory snapshot file. This method of obtaining memory snapshot files ensures that the memory snapshot file analyzed each time is the memory snapshot file that the development object needs to analyze, thus meeting the development object's need for targeted analysis of memory leaks.

[0105] like Figure 4a As shown, assuming the computer device 401 used by the development object and the computer device 402 that deploys the analysis logic of the memory processing scheme (or stores the Wasm file) are different devices, in this implementation, when the development object needs to analyze the location of memory leaks, the development object can send the memory snapshot file to the computer device 402 through the computer device 401 so that the computer device 402 can perform subsequent memory analysis steps. Of course, the computer device 401 used by the development object and the computer device 402 that deploys the analysis logic of the memory processing scheme (or stores the Wasm file) can also be the same device; in this implementation, the computer device can directly call the stored memory snapshot file in memory to obtain the memory snapshot file of the memory space.

[0106] (2) The computer device automatically generates a memory snapshot file of the memory space and executes subsequent memory processing schemes based on the generated memory snapshot file. In other words, this embodiment supports the computer device automatically generating a memory snapshot file of the memory space when a potential memory leak is detected, thus enabling the acquisition of the memory snapshot file. For example, when the computer device detects that the duration of system lag exceeds a duration threshold, it can automatically generate a memory snapshot file. This duration threshold can be customized by the developer based on business needs or generated by the computer device based on experience. Furthermore, the computer device can periodically generate memory snapshot files of the memory space, such as generating a corresponding memory snapshot file at target time intervals. This target time interval can be preset by the developer based on business needs. This method of obtaining memory snapshot files eliminates the need for the developer to perform additional memory snapshot file acquisition operations, reducing the workload of the developer while also enabling real-time monitoring of memory operation and improving the timeliness of memory leak analysis.

[0107] like Figure 4b As shown, assuming the computer device automatically executes at target time intervals, it retrieves a memory snapshot file of the memory space at the current moment. The target time interval is one hour. After generating a memory snapshot file for 7:00 AM, a memory snapshot file for 8:00 AM can be generated at 8:00 AM. Then, based on business needs, subsequent analysis and processing can be performed on the memory snapshot files generated at each moment or at any one or more moments.

[0108] It should be noted that the above are only two exemplary methods for obtaining memory snapshot files given in the embodiments of this application; in practical applications, the specific implementation process for obtaining memory snapshot files of memory space may also change, and this is not limited.

[0109] Furthermore, the memory snapshot file (or heapdump file, saved using the heapdump tool) obtained by the computer device is unreadable. Therefore, after obtaining the memory snapshot file, the computer device needs to format it into a more readable structure to facilitate subsequent operations. Specifically, after obtaining the memory snapshot file, the computer device analyzes and processes it to obtain descriptive data about the memory space. This is done by reading the source code of the V8 runtime engine, first defining the specifications for memory snapshot files, and then analyzing and processing the memory snapshot file according to these specifications to obtain the descriptive data about the memory space.

[0110] Considering that the topological structure of objects in memory space needs to be represented using a graph data structure (such as a graph data structure), the descriptive data of the analyzed memory space may include, but is not limited to: the node attributes and attribute types of each memory node obtained from the memory space partitioning, and the edge attributes of each edge connecting the memory nodes. In practical applications, the memory snapshot file includes the node attribute fields and node attribute type resources for each memory node, as well as the edge attribute fields and edge attribute type fields for each edge. This allows for attribute analysis of the node attribute fields to obtain the node attributes of each memory node; similarly, attribute type analysis of the node attribute type fields yields the attribute types of the nodes; and attribute analysis of the edge attribute fields yields the edge attributes of the edges connecting the memory nodes, and attribute type analysis of the edge attribute type fields yields the attribute types of the edges. The following is a description of each of the fields given above.

[0111] 1) Regarding the node attribute field and node attribute type field of memory nodes.

[0112] The node attributes of a memory node are defined in the node attribute field `node_fields`, specifically: `{"snapshot":{"meta":{"node_fields":["type","name","id","self_size","edge_count","trace_node_id"]`. This node attribute field defines the list of attributes possessed by the memory node. Therefore, a memory node can have a total of six node attributes, and any memory node can have at least one of the following: node type (`type`), node identifier (`name`), node number (`id`), node memory size (`self_size`), edge attribute (`edge_count`), and node memory indicator (`trace_node_id`). Among them, the node attribute "node type" can be used to indicate the node type to which the memory node belongs; the node attributes "node identifier" and "node number" can be used to uniquely identify the identity of the memory node; the node attribute "node memory size" is used to indicate the size of the memory contained in the memory node itself; the node attribute "edge holding attribute" can be used to indicate the number of edges that have the memory node as a parent memory node, that is, the number of edges that the memory node has; the node attribute "node memory indicator" can be used to indicate the memory address corresponding to the memory node in the browser (if it is an empty placeholder).

[0113] Each node attribute of a memory node has a fixed node attribute type, defined in the node attribute type field `node_types`, specifically: `node_types: [["hidden", "array", "string", "object", "code", "closure", "regexp", "number", "native", "synthetic", "concatenated string", "sliced ​​string", "symbol", "bigint"], "string", "number", "number", "number", "number", "number", "number"]`. This node attribute type field defines a total of 14 node attribute types, and memory nodes have a total of 2 node types (such as array type and number type). The 14 node attribute types can include: boolean type `hidden`, data type `array`, reference type `string`, object type `object`, program type `code`, function type `closure`, reference type `regexp`, number type `number`, basic data type `native`, synthetic data type `synthetic`, function concatenation type `concatenated string`, etc.

[0114] 2) Regarding the node attribute fields and node attribute type fields of memory nodes.

[0115] The edge attributes of a connection are defined in the edge attribute field edge_fields. The edge attributes defined in the edge_fields field may include: edge type, edge identifier, and edge pointing attribute. The edge attribute "edge type" can be used to indicate the edge type to which the connection belongs, the edge attribute "edge identifier" can be used to uniquely identify the identity of the connection, and the edge attribute "edge pointing attribute" can be used to indicate the child memory node that the connection points to, that is, the memory node adjacent to the end of the connection containing the arrow.

[0116] Each edge connecting the memory nodes also has a different edge type. The edge type can be defined in the edge type field edge_types, specifically: "edge_types": ["contex", "element", "property", "internal", "hidden", "shortcut", "weak"]. This edge type field defines a total of 7 edge type attributes: function attribute contex, array attribute element, object attribute property, inaccessible internal attribute internal, hidden attribute invisible to the user, shortcut attribute ignored when calculating size, and weak reference attribute weak.

[0117] It should be noted that, based on the above description, the node attributes and node attribute types of each memory node in one or more memory nodes included in the memory space, as well as the edge attributes and edge types of the edges connecting (or linking) each memory node, can be obtained. This application embodiment does not limit the specific attributes of the node attributes of the memory nodes and the edge attributes of the edges mentioned above; similarly, it does not limit the specific types of the node attribute types of the memory nodes and the edge types of the edges; furthermore, it does not limit the number of node attribute types contained in any memory node.

[0118] It should also be noted that, in addition to the node attributes and attribute types of memory nodes, and the edge attributes and types of connected edges mentioned above, the description data of memory space may also include the attribute values ​​of memory node attributes and the attribute values ​​of connected edges. For example, the attribute value of the node attribute "Node Memory Size" of a memory node is the specific memory size of the memory node; another example is that the attribute value of the node attribute "Node Identifier" of a memory node can be the specific name of the memory node.

[0119] For memory space considerations, the generated memory snapshot file does not directly record the attribute values ​​of memory nodes or the attribute values ​​of connected edges. Instead, it stores a series of numbers (or a string of numbers). For ease of explanation, a target attribute is used to represent a node attribute of a memory node or an edge attribute of a connected edge; that is, the target attribute is either a node attribute or an edge attribute. For example, when the target attribute is a node attribute, a series of numbers can be used to represent each node attribute of the memory node. This series of numbers is stored in the memory snapshot file, and the attribute value of the target attribute is associated with its order in the series of numbers. Any number in the aforementioned series of numbers can be called the query identifier (or query subscript) of the corresponding attribute. As described above, the node attributes of a memory node can include six, arranged in order: node type, node identifier, node number, node memory size, edge holding attribute, and node memory indicator. The number string 9, 1, 1, 1, 8, 0 can be used to represent the node attributes "node type, node identifier, node number, node memory size, edge holding attribute, and node memory indicator", respectively. In this case, the number 9 can be called the query subscript of the node attribute "node type", the number 1 can be called the query subscript of the node attribute "node identifier", and so on.

[0120] In practice, the memory snapshot file also includes an attribute value array and a data query array. The contents of the attribute value array and the data query array differ depending on whether the target attribute is a node attribute of a memory node or an edge attribute of a connected edge. For example, when the target attribute is a node attribute of a memory node, the attribute value array can be used to store the attribute value of each memory attribute of each memory node; specifically, this attribute value array includes the attribute value of the target attribute. The data query array can be used to store the query identifier of each memory attribute of each memory node; specifically, this data query array includes the query identifier of the target attribute. The following describes the specific implementation process of obtaining the attribute value of the target attribute, taking querying the attribute value of the target attribute as an example. This process may include steps s11-s13:

[0121] s11: Determine the query identifier associated with the target attribute from the data query array. Taking the data query array as the query array of memory nodes, with 8 memory nodes in the memory space as an example, as described above, the node attributes of the memory nodes include 3: node type, node identifier, node number, node memory size, edge-held attribute t, and the node's memory indicator. Therefore, the data query array of the memory nodes can be represented as:

[0122] “nodes”:[9,1,1,0,8,0

[0123] ,9,2,3,0,23,0

[0124] ,9,3,5,0,1,0

[0125] ,9,4,7,0,79,0

[0126] ,9,5,9,5,555,0

[0127] ,9,6,11,0,75,0

[0128] ,9,7,13,0,0,0

[0129] ,9,8,15,0,0,0]

[0130] Therefore, the `nodes` array, representing the node attributes of a memory node, is a one-dimensional array. Each row represents a memory node in the memory space, specifically the lookup identifier of the attribute values ​​for the six node attributes of that memory node in the attribute value array. For example, the first row of the `nodes` array might be the string 9,1,1,0,8,0, indicating that the lookup identifier for the "node type" attribute of memory node 1 in the memory space is 9, the "node identifier" attribute is 1, the "node number" attribute is 1, and so on. Based on this, according to which memory node the target attribute belongs to, the lookup identifier associated with that target attribute can be retrieved from the data lookup array. The lookup identifier associated with the target attribute refers to the lookup identifier of the target attribute's value in the attribute value array.

[0131] Similarly, taking a query array with 8 edges as an example, as described above, the edge attributes include three aspects: edge type, edge identifier, and edge pointer attribute. Therefore, the data query array of the edges can be represented as follows:

[0132] “edges”:[1,1,6

[0133] ,5,5742,13332

[0134] ,1,3,174438

[0135] ,1,4,174444

[0136] ,1,5,174450

[0137] ,1,6,174456

[0138] ,1,7,174462

[0139] ,1,8,174468]

[0140] Similar to the node attribute data query array described above, the edge attribute data query array `edges` is a one-dimensional array. Each row represents an edge, specifically the query index of the attribute values ​​of the three edge attributes in the attribute value array. By recording the query index of the attribute values ​​of the edge attributes in the data query array `edges`, the position of each edge attribute in the attribute value array can be found, thus obtaining the attribute value of the edge attribute. This will not be elaborated further here.

[0141] It is understood that the data query arrays given above (such as the numbers contained in the data query array) are merely exemplary, and the embodiments of this application do not limit them.

[0142] s12: Generate the index value of the target attribute based on the query identifier associated with the target attribute. Specifically, it generates the index value of the target attribute based on the query identifier associated with the target attribute and the order of the query identifier in the data query array. The attribute value of the target attribute can be found in the attribute value array based on this index value. The formula for calculating the index value is: query identifier * number of columns + offset of the query identifier in the current row.

[0143] For example, assuming the target attribute is the node type of memory node 1, the query identifier associated with the target attribute can be obtained from the data query array given above as 9, and the query identifier is located in the first column of the first row in the data query array. Then, according to the index value calculation formula, the index value associated with the target attribute can be obtained as: 9*1+0=9.

[0144] s13: Determine the attribute value of the target attribute from the attribute value array according to the index value of the target attribute. The attribute value array of the memory node can be represented as:

[0145] “strings”:[“ <dummy>,

[0146] "",

[0147] "(GC roots)"

[0148] "(Internalized strings)",

[0149] "(External strings)",

[0150] "(Read-only roots)"

[0151] "(Strong roots)"

[0152] "(smi roots)"

[0153] "(Bootstrapper)"

[0154] "(Isolate)"

[0155] "(Relocatable)"

[0156] "(Debugger)"

[0157] …]

[0158] Therefore, the attribute value array `strings` includes multiple attribute values. Based on the index value of the target attribute determined in step s12, the attribute value of the target attribute can be determined from the attribute value array `strings`. Specifically, it is necessary to refer to the attribute type and index value of the target attribute to determine the attribute value of the target attribute from the attribute value array `strings`. It is understood that this application embodiment does not limit the number and specific content of the attribute values ​​contained in the attribute value array `strings`, which is hereby stated.

[0159] In summary, based on the specific implementation process shown in steps s11-s13 above, the attribute value of the target attribute can be obtained. This method of obtaining attribute values ​​through indexing can avoid directly recording the attribute values ​​to the memory snapshot file, which can save memory space to a certain extent and thus improve the operating efficiency of computer equipment.

[0160] S302. Determine the connection relationships between memory nodes based on the node attributes of each memory node and the edge attributes of each connected edge.

[0161] As described above, the node attributes of any memory node may include an edge holding attribute, which can be used to characterize the number of edges associated with that memory node when it is used as a parent memory node. Similarly, the edge attributes of any edge may include an edge pointing attribute, which is used to characterize the child memory node pointed to by that edge. Based on this, the parent memory node associated with each edge can be determined according to the attribute value of the edge holding attribute of each memory node; and the child memory node pointed to by each edge can be determined according to the attribute value of the edge pointing attribute of each edge; then, based on the parent memory node associated with each edge and the child memory node pointed to by each edge, the connection relationship between the memory nodes included in the memory space can be obtained.

[0162] The connections between memory nodes within the memory space can be obtained by constructing a memory graph. Specifically, this is done by connecting the memory nodes according to the parent memory node and the child memory node pointed to by each edge, thus obtaining the memory graph. This memory graph can be called a graph data structure, and it can be used to represent the connections between one or more memory nodes within the memory space. A schematic diagram illustrating the connections between memory nodes can be found here. Figure 5 ,like Figure 5 As shown, the memory space includes memory nodes A, B, and C. Each edge connects memory nodes A, B, and C according to their associated parent and child nodes, forming a graph data structure that represents the connections between the memory nodes. For a detailed description of memory nodes, please refer to the preceding descriptions. An edge is a directed edge connecting two memory nodes; a directed edge is an edge that points in a direction (i.e., has an arrow). In other words, this memory graph is a directed graph obtained by connecting memory nodes with edges. The memory node connected to the end of a directed edge without an arrow is called the parent memory node associated with that directed edge (e.g., memory node A). Similarly, the memory node pointed to by the arrow of the directed edge is called the child memory node (e.g., memory node B).

[0163] Since a memory node can have multiple edges, such as a memory node extending multiple edges from its parent memory node, the exemplary relationships between the memory nodes and their edges can be found in [reference needed]. Figure 6 .like Figure 6 As shown, assuming the memory space includes memory nodes node0 and node1, and the edge holding attribute of memory node0 indicates that node0 has 2 edges (i.e., 2 edges extending from node0 as its parent), and the edge holding attribute of memory node1 indicates that node1 has 3 edges (i.e., 3 edges extending from node1 as its parent), then based on the "edge holding attribute" of each memory node, we can know the number of edges each memory node has, thereby determining the starting position of each edge (i.e., the parent memory node corresponding to the edge). Furthermore, based on the "edge pointing attribute" of each edge, we can determine the ending position of the edge (i.e., the child memory node the edge points to). In summary, by determining the parent memory node associated with each edge and the child memory node it points to, the connection relationships between the memory nodes can naturally be obtained.

[0164] It is not hard to understand that Figure 5 This is merely an exemplary memory diagram provided in this application embodiment. Figure 6 This is merely an exemplary correspondence between memory nodes and edges provided in this application embodiment; depending on the number of memory nodes, the parent memory node associated with the edge and the child memory node it points to will be different. Figure 5 and Figure 6 This can also change, which is explained here. Furthermore, in practical applications, code is used to represent the connections between memory nodes; that is, the computer device stores the code corresponding to the connections between memory nodes, and the computer device may not actually construct a visual memory graph. The structural diagram of the memory graph given above is only for the reader's better understanding and is explained here.

[0165] S303. Based on the connection relationship between each memory node, determine the root memory node, the target memory node that is reachable from the root memory node, and the reference memory node that is unreachable from the root memory node.

[0166] S304. Calculate the amount of reclaimable memory for the target memory node based on the node attributes of the target memory node and the node attributes of the reference memory node.

[0167] In steps S303-S304, based on the specific implementation process shown in steps S301-S302 above, after obtaining the connection relationship between each memory node included in the memory space, this application embodiment can calculate the amount of reclaimable memory retained_size for each memory node based on the connection relationship. The amount of reclaimable memory of a memory node can be used to characterize the amount of memory that can be reclaimed after the memory node is released. Thus, based on the amount of reclaimable memory of a memory node, it is possible to determine the suspicious memory nodes that may have memory leaks, and then determine the objects corresponding to the suspicious memory nodes that need to be manually released (such as variables that read and write to suspicious memory objects). This can help developers quickly locate the location of memory leaks.

[0168] The amount of reclaimable memory in a memory node is a crucial indicator for analyzing memory leaks. This indicator is not directly recorded in the heap snapshot (i.e., the aforementioned memory snapshot file) and must be calculated manually by the developer. Garbage collection algorithms are typically used to calculate the amount of reclaimable memory in a memory node. These algorithms include, but are not limited to, Mark-Sweep, Copying, Mark-Compact, and generational garbage collection. For ease of explanation, this application's embodiments use any memory node within the memory space as the target memory node, and take the calculation of the reclaimable memory in the target memory node as an example to illustrate the calculation process:

[0169] First, after identifying the root memory node among all memory nodes, target memory nodes that are reachable from the root memory node can be determined. These target memory nodes are those that can be traversed from the root memory node; for ease of explanation, they can be called reachable memory nodes. Furthermore, the system supports coloring target memory nodes to mark the reachable ones that have been found.

[0170] Then, based on the determination that the target memory node is reachable, reference memory nodes that are unreachable from the root memory node are identified. These reference memory nodes can be those that, after deleting the target memory node from the memory graph, cannot be traversed from the root memory node; for ease of explanation, they can be referred to as unreachable memory nodes. Specifically, the method for determining reference memory nodes based on the identified target memory node can include: removing the target memory node from the memory graph to obtain an updated memory graph; then, using the root memory node in this updated memory graph as the traversal starting point, identifying memory nodes that cannot be traversed (or are inaccessible) as reference memory nodes, thus determining that these reference memory nodes are unreachable from the root memory node.

[0171] Finally, based on the attribute value "Memory Amount" of the target memory node's node attribute "Node Memory Amount" and the attribute value "Memory Amount" of the reference memory node's node attribute "Node Memory Amount", the amount of reclaimable memory for the target memory node is calculated.

[0172] The following is in conjunction with the appendix Figure 7a Taking any memory node included in the memory space as the target memory node, and using the calculation of the reclaimable memory amount of the target memory node as an example, the calculation process of the reclaimable memory amount provided in this application embodiment is given. Specifically, it is assumed that the memory space includes the following memory nodes: memory node 1, memory node 2, memory node 3, memory node 4, memory node 5, and memory node 6, and the connection relationship between these 6 memory nodes is as follows: Figure 7a As shown. Figure 7a The memory graph shown can be divided into three memory nodes from top to bottom: root memory node, intermediate memory nodes, and terminal memory nodes. Memory node 1 is the root memory node, extending downwards to include intermediate memory nodes 2, 3, and 4, and further downwards to include terminal memory nodes 5 and 6. The method for determining the reclaimable memory amount of the target memory node (such as any memory node) differs depending on whether it is the root, intermediate, or terminal memory node. The specific process for determining the reclaimable memory amount when the target memory node is the root, intermediate, or terminal memory node is described below:

[0173] (1) If the target memory node is the root memory node in the memory graph, such as the target memory node is Figure 7a The memory node 1 shown above, based on the aforementioned method for determining reference memory nodes, can be determined that, with the target memory node being the root memory node, the reference memory nodes that are unreachable from the root memory node include: all memory nodes in the memory graph except the root memory node.

[0174] In this implementation, the process of calculating the reclaimable memory amount of the target memory node based on the node attributes of the target memory node and the reference memory node may include: adding the memory value of the root memory node to the memory values ​​of all memory nodes in the memory graph except the root memory node, to obtain a first summed memory amount; using this first summed memory amount as the reclaimable memory amount of the root memory node. In other words, when the target memory node is the root memory node, the reclaimable memory amount of the root memory node can be considered as the sum of the memory values ​​of all memory nodes. Figure 7b As shown, the amount of reclaimable memory for the root memory node "Memory Node 1" = the total memory of Memory Node 1 + the total memory of Memory Node 2 + the total memory of Memory Node 3 + the total memory of Memory Node 4 + the total memory of Memory Node 5 + the total memory of Memory Node 6.

[0175] (2) If the target memory node is the end memory node in the memory graph, then the end memory node is a memory node in the memory graph that is not associated with a parent memory node as a connecting edge. For example, if the end memory node is... Figure 7a Based on the aforementioned method for determining reference memory nodes, memory nodes 5 and 6 in the memory graph shown can be determined that, given that the target memory node is the terminal memory node, there is no reference memory node that is unreachable from the root memory node.

[0176] In this implementation, the process of calculating the reclaimable memory amount of the target memory node based on the node attributes of the target memory node and the reference memory node may include: using the memory value of the target memory node's "node memory amount" as the reclaimable memory amount of the target memory node. That is, using the attribute value of the "node memory amount" attribute of the terminating memory node itself as the reclaimable memory amount of that terminating memory node. See also... Figure 7b The amount of reclaimable memory for the terminal memory node "Memory Node 5" is equal to the amount of memory in the node memory of Memory Node 5; similarly, the amount of reclaimable memory for the terminal memory node "Memory Node 6" is equal to the amount of memory in the node memory of Memory Node 6.

[0177] (3) If the target memory node is any memory node in the memory graph other than the root memory node and the terminal memory node, such as the target memory node is Figure 7a In the memory graph shown, memory node 2 (or memory node 3 or memory node 4) can be considered as a reference memory node, based on the aforementioned method for determining reference memory nodes. Given that the target memory node is memory node 2, memory node 4 can be considered as a reference memory node that is unreachable from the root memory node. For details on the process of determining reference memory nodes, please refer to [link to relevant documentation]. Figure 7c ,like Figure 7c As shown: First, remove the target memory node (e.g., memory node 2) from the memory graph. Specifically, remove memory node 2 and every edge connected to it (e.g., edge 2 and edge 3), resulting in an updated memory graph. Then, using the root memory node in the updated memory graph as the starting point (traversal starting point), traverse each memory node in the updated memory graph along the edges; as shown... Figure 7c As shown, starting from the root memory node "memory node 1", we can traverse to memory node 3 along edge 1, continue along edge 5 to traverse to memory node 5, and follow edge 4 to traverse to memory node 6. We cannot traverse to memory node 4 along any edge. Therefore, the memory node that has not been traversed in the updated memory graph (i.e., memory node 4) is regarded as a reference memory node that is unreachable from the root memory node.

[0178] In this implementation, the process of calculating the reclaimable memory amount of the target memory node based on the node attributes of the target memory node and the reference memory node may include: adding the memory value of the target memory node's "node memory amount" to the memory value of the reference memory node's "node memory amount" to obtain a second summed memory amount; using this second summed memory amount as the reclaimable memory amount of the target memory node. That is, considering that after memory node 2 is released or reclaimed, the reference memory node linked to memory node 2 but not linked to any other memory node can no longer be used (or accessed), therefore this reference memory node also needs to be released. Thus, after memory node 2 is released, the reclaimable memory amount is: the value of the target memory node's own "node memory amount" attribute "memory value" minus the value of the reference memory node's "node memory amount" attribute "memory value". See also... Figure 7c The amount of reclaimable memory for the target memory node "Memory Node 2" = the amount of memory in Memory Node 2 + the amount of memory in Memory Node 4.

[0179] It should be noted that the specific logic for calculating the amount of reclaimable memory for each memory node using the garbage collection algorithm described above can be written in the following code snippet:

[0180]

[0181]

[0182] It should also be noted that: ① The above description uses the calculation of the reclaimable memory amount of the target memory node in each memory node as an example. In practical applications, this application embodiment supports calculating the reclaimable memory amount of each memory node. Each memory node can obtain its corresponding reclaimable memory amount according to its position in the memory graph in the above-described manner. This application embodiment will not elaborate on this in detail here. ② When the target memory node is an intermediate memory node in the memory graph, there may not be any reference memory node that is unreachable from the root memory node. In this case, the reclaimable memory amount of the target memory node is the attribute value "memory amount value" of the node attribute "node memory amount". ③ In the edges between memory nodes, if there are edges with a weak reference attribute type "weak", then the reference relationship needs to be ignored when calculating garbage collection. That is, it can be considered that the edge is in a disconnected (or impassable) state in the memory graph. In the process of traversing each memory node in the updated memory graph along the edge, the memory nodes in the memory graph are not traversed along the edges with weak reference attributes. Figure 7d As shown, after removing memory node 2 in the memory graph, although there is an edge 4 between memory node 3 and memory node 6, considering that edge 4 is a weak reference type, it is considered that edge 4 is broken. At this time, it can be determined that the reference memory nodes that are unreachable from the root memory node include memory node 4 and memory node 6. Then, the amount of reclaimable memory of memory node 2 = the memory value of memory node 2 + the memory value of memory node 4 + the memory value of memory node 6.

[0183] Based on the above description, the amount of reclaimable memory for each memory node in one or more memory nodes in the memory space can be calculated based on the connection relationship between each memory node. This is helpful in using the amount of reclaimable memory for each memory node to identify suspicious memory nodes in one or more memory nodes that may have memory leaks.

[0184] In this embodiment, it is supported to obtain memory snapshot files of the memory space and directly analyze and process them to obtain descriptive data of the memory space. This descriptive data may include node attributes of each memory node and edge attributes of the edges connecting each memory node. Based on these node attributes and edge attributes, the connection relationships between memory nodes can be determined. Then, based on these connection relationships, the root memory node, the target memory node reachable from the root memory node, and the reference memory node unreachable from the root memory node can be determined from each memory space. Finally, based on the target memory node and the reference memory node, the amount of reclaimable memory for the target memory node can be calculated. In the above scheme, there is no need to convert the connection relationships between memory nodes in the memory snapshot file of the memory space; the amount of reclaimable memory for each memory node can be quickly calculated directly based on these connection relationships, thereby helping developers quickly locate memory nodes with memory leaks.

[0185] The above Figure 3 The example primarily illustrates the specific implementation process of directly analyzing and processing memory snapshot files, and quickly calculating the amount of reclaimable memory for each memory node based on the analysis results. The following section combines... Figure 8 The key point is to provide the specific implementation process for identifying leaking memory nodes (or suspected memory nodes) from one or more memory nodes in the memory space based on the amount of reclaimable memory for each memory node.

[0186] Please see Figure 8 , Figure 8 A flowchart illustrating another memory processing method provided in an exemplary embodiment of this application is shown. This memory processing method can be executed by the aforementioned computer device, and the method may include steps S801-S805:

[0187] S801. Obtain a memory snapshot file of the memory space, and analyze and process the memory snapshot file to obtain descriptive data of the memory space.

[0188] It should be noted that the specific implementation process shown in step S801 can be found in [reference needed]. Figure 3 The specific implementation process shown in step S301 of the illustrated embodiment will not be repeated here.

[0189] As described above, memory snapshot files have poor readability. Therefore, after analyzing and processing the memory snapshot file based on the specific implementation steps shown in step S801 to obtain the description data of the memory space, this application embodiment also supports parsing the memory snapshot file into a more readable Rust object based on the analyzed description data. Specifically, it defines the structure type of each memory node in the Rust language as follows:

[0190]

[0191]

[0192] It is particularly important to note that this structure type additionally records the parent memory node associated with each edge, in order to better assist in the subsequent analysis of the connection relationships between memory nodes.

[0193] Furthermore, based on the generated Rust object, the memory snapshot file can be serialized into a more readable JSON structure, as follows:

[0194]

[0195]

[0196] Based on the above-mentioned JSON structure with good readability, on the one hand, it is beneficial for front-end developers to analyze the connection relationship between memory nodes, and on the other hand, browsers also support running JSON structures written in JS language.

[0197] S802. Determine the connection relationships between memory nodes based on the node attributes of each memory node and the edge attributes of each connected edge.

[0198] S803. Based on the connection relationship between each memory node, determine the root memory node, the target memory node that is reachable from the root memory node, and the reference memory node that is unreachable from the root memory node.

[0199] S804. Calculate the amount of reclaimable memory for the target memory node based on the node attributes of the target memory node and the node attributes of the reference memory node.

[0200] It should be noted that the specific implementation process shown in steps S802-S804 can be found in the aforementioned... Figure 3 The specific implementation process shown in steps S302-S304 of the illustrated embodiment will not be repeated here.

[0201] In addition, after obtaining the amount of reclaimable memory for the target memory node, the complete attributes of the target memory node can be obtained, as follows:

[0202]

[0203] The code above fully records the attribute values ​​of each node attribute of the target memory node, as well as the amount of reclaimable memory of the target memory node.

[0204] S805. Compare the memory amount of the target memory node with the reclaimable memory amount of the target memory node, and determine whether the target memory node is a leaking memory node with memory leaks.

[0205] Based on the specific implementation process shown in steps S801-S804 above, the amount of reclaimable memory of each memory node included in the memory space can be obtained. Furthermore, this application embodiment also supports identifying some memory nodes with memory leaks from each memory node based on the amount of reclaimable memory of each memory node and the corresponding node attribute "node memory amount". These memory nodes can be called suspicious memory nodes or leaking memory nodes, without limitation.

[0206] For ease of explanation, this application embodiment still takes the determination of whether a target memory node is a suspicious memory node based on the reclaimable memory amount and node memory amount of the target memory node as an example to introduce the specific judgment process of leaking memory nodes; the judgment process of whether other memory nodes are leaking memory nodes is similar to that of the target memory node. In specific implementation, after obtaining the reclaimable memory amount of the target memory node, we can know the amount of memory that the garbage collection mechanism can reclaim after the target memory node is released; in addition, the target memory node itself also has node memory amount, which represents the memory size of the target memory node itself. Then, we can compare the memory amount value of the node memory amount of the target memory node with the reclaimable memory amount of the target memory node to obtain the memory amount comparison result; if the memory amount comparison result meets the memory leak condition, then the target memory node is regarded as a leaking memory node with memory leak. The memory leak condition includes: the memory amount difference between the node memory amount value of the target memory node and the reclaimable memory amount of the target memory node is greater than the memory amount threshold.

[0207] In other words, if the memory size comparison result is large, it indicates a significant gap between the target memory node and the amount of reclaimable memory compared to the node's memory size. This further suggests that the target memory node may reference other memory nodes that are no longer in use. That is, after the target memory node is released, in addition to the memory size of the target memory node itself, the memory size of other memory nodes it references can also be recovered. Therefore, it is determined that the target memory node has a memory leak. Conversely, if the memory size comparison result is small, it indicates a small gap between the target memory node and the amount of reclaimable memory compared to the node's memory size. This further suggests that after the target memory node is reclaimed, only its own memory size can be released. Therefore, it is determined that the target memory node has a memory leak. From the memory leak conditions described above, it can be seen that memory nodes identified as leaking memory nodes often have the following characteristics: the memory node itself has a small memory size, but a large amount of memory can be released after it is reclaimed.

[0208] By performing the aforementioned judgment process on each memory node within the memory space, one or more leaky memory nodes can be identified within each memory node. Furthermore, based on the various information analyzed or calculated in the preceding steps, including but not limited to: the connection relationships between memory nodes, node attributes, and the amount of reclaimable memory, a node relationship graph of the memory space can be constructed. This node relationship graph is a directed graph obtained by connecting memory nodes using edges based on the connection relationships between them; its structure is similar to the memory graph described above, but it adds a section to label leaky memory nodes. A schematic diagram of an exemplary node relationship graph can be found [link to diagram]. Figure 9 ,like Figure 9 As shown, based on the connection relationship between memory nodes, edges are used to connect the memory nodes to obtain the node relationship graph of the memory space. This node relationship graph records various information of each memory node, including but not limited to: node name, node ID, node memory amount, reclaimable memory amount, and connected child memory nodes, etc.

[0209] S806, Output node relationship diagram.

[0210] After constructing the node relationship graph of the memory space, this application embodiment also supports outputting the node relationship graph; by visually outputting the node relationship graph, it is beneficial to help the developer quickly locate the memory problems existing in the server program based on the highly readable node relationship graph.

[0211] In specific implementation, after directly analyzing and processing the memory snapshot file of the memory space to obtain the node relationship graph of the memory space, the node relationship graph can be output to the terminal device used by the development object; and one or more automatically identified leaky memory nodes are visually highlighted in the node relationship graph. The purpose of visually highlighting leaky memory nodes is to give them a different visual appearance than other memory nodes, thereby providing a different visual effect for the development object and intuitively informing them which memory nodes are leaky. This embodiment does not limit the display method of visually highlighting leaky memory nodes, and includes, but is not limited to: highlighting (e.g., increasing display brightness or using different colors) the leaky memory node (or the area where the leaky memory node is located); or increasing the node size of the leaky memory node; or adding annotations to the leaky memory node; etc.

[0212] A diagram illustrating the node relationship of the output memory space, and visually highlighting one or more leaky memory nodes within the node relationship diagram, can be found here. Figure 10 ;like Figure 10 As shown, assuming the memory space includes memory node 1, memory node 2, memory node 3, ..., memory node 6, and memory node 3 is identified as a leaking memory node; then in the node relationship graph formed by linking memory nodes 1, 2, 3, ..., 6, memory node 3 can be colored (e.g., a darker grayscale compared to other memory nodes) to distinguish it from other memory nodes, thus quickly finding the leaking memory node among multiple memory nodes. Of course, the method of visually highlighting leaking memory nodes in the node relationship graph is not limited to... Figure 10 This is to clarify.

[0213] As described above, the node relationship graph records various information about each memory node. Therefore, this application embodiment also supports developers to quickly locate various information about each memory node through the output node relationship graph, such as the node memory amount (i.e., node memory size), which parent memory nodes reference the memory node, which child memory nodes the memory node references, and the amount of reclaimable memory of the memory node, etc.

[0214] In the specific implementation, during the process of displaying the node relationship graph of the memory space on the terminal device used by the development object, when the development object needs to view various information of any memory node, it can trigger that memory node. At this time, the terminal device detects that when any memory node in the node relationship graph is triggered, it can display the node information of that memory node (i.e., the various information of the memory node mentioned above) for the development object to view. The node information of the memory node includes at least one of the following: node identifier, node number, node memory amount, child memory nodes associated with the node when it is a parent memory node, parent memory node associated with the node when it is a child memory node, and reclaimable memory amount, etc.

[0215] An exemplary procedure for triggering the display of node information for any memory node in a node relationship graph can be found in [reference needed]. Figure 11 ;like Figure 11 As shown, a node relationship diagram of memory nodes is displayed in the service interface provided by the terminal device. When any memory node in the node relationship diagram, such as memory node 3, is triggered, an information display window 1101 can be output, and the node information of memory node 3 is displayed in the information display window 1101. In this embodiment, the specific display position of the information display window 1101 in the service interface is not limited; for example, the information display window 1101 can be displayed in a fixed position in the service interface (such as the lower right corner, the middle position, or the upper left corner, etc.), or, for example, the information display window 1101 can be displayed in the position associated with the triggered memory node (such as the position adjacent to the memory node), etc.

[0216] It is worth noting that the specific style of the information display window, as well as the display position and style of the various information contained within the information display window, are not limited to... Figure 10 As shown.

[0217] In this embodiment, on the one hand, there is no need to convert the connection relationships between memory nodes in the memory snapshot file of the memory space. The amount of reclaimable memory for each memory node can be quickly calculated directly based on the connection relationships between memory nodes in the memory space. On the other hand, this embodiment also supports identifying leaky memory nodes from among the memory nodes included in the memory space based on the amount of reclaimable memory for each memory node and the corresponding node memory amount. Leaky memory nodes are visually highlighted in the node relationship graph to intuitively inform developers, thereby helping them quickly locate memory nodes with memory leaks. Furthermore, this embodiment uses the Rust language for writing the analysis logic, which achieves high analysis performance and improves the calculation speed of the reclaimable memory amount of memory nodes, thus helping developers locate leaky memory nodes faster and more accurately, and improving the JavaScript ecosystem.

[0218] The methods of the embodiments of this application have been described in detail above. In order to facilitate better implementation of the above solutions of the embodiments of this application, the apparatus of the embodiments of this application is provided below.

[0219] Figure 12 This illustration shows a schematic diagram of a memory processing apparatus provided in an exemplary embodiment of this application; the memory processing apparatus can be used as a computer program (including program code) running in a computer device; the memory processing apparatus can be used to execute... Figure 3 as well as Figure 8 Some or all of the steps in the method embodiments shown. Please refer to [link / reference]. Figure 12 The memory processing device includes the following units:

[0220] The acquisition unit 1201 is used to acquire a memory snapshot file of the memory space and analyze and process the memory snapshot file to obtain the description data of the memory space. The description data includes: the node attributes of each memory node obtained by dividing the memory space, and the edge attributes of each edge connecting each memory node.

[0221] The processing unit 1202 is used to determine the connection relationship between memory nodes based on the node attributes of each memory node and the edge attributes of each connected edge.

[0222] The processing unit 1202 is also used to determine, based on the connection relationship between each memory node, the root memory node, the target memory node that is reachable from the root memory node, and the reference memory node that is unreachable from the root memory node.

[0223] The processing unit 1202 is also used to calculate the amount of reclaimable memory of the target memory node based on the target memory node and the reference memory node that is unreachable from the root memory node. The amount of reclaimable memory is used to characterize the amount of memory that can be reclaimed after the target memory node is released.

[0224] In one implementation, the node attributes of any memory node include an edge holding attribute, which is used to represent: when any memory node is a parent memory node, the connected edges associated with any memory node; the connected edges are directed edges, and the edge attributes of any connected edge include an edge pointing attribute, which is used to represent the child memory node pointed to by any connected edge.

[0225] Processing unit 1202, when determining the connection relationship between memory nodes based on the node attributes of each memory node and the edge attributes of each connected edge, specifically performs the following functions:

[0226] Based on the attribute values ​​held by the edges of each memory node, determine the parent memory node associated with each edge; and,

[0227] Based on the attribute value of the edge pointing attribute of each edge, determine the child memory node pointed to by each edge;

[0228] A memory graph of the memory space is constructed based on the parent memory node and the child memory node that each edge is associated with. The memory graph is a directed graph obtained by connecting each memory node with each edge. The memory graph can be used to represent the connection relationship between each memory node included in the memory space.

[0229] In one implementation, the node attributes of a memory node include the node's memory size, and the attribute value of the node's memory size is the memory size value; if the target memory node is the root memory node, then the reference memory nodes that are unreachable from the root memory node include: all memory nodes in the memory graph except the root memory node.

[0230] Processing unit 1202, when calculating the amount of reclaimable memory for a target memory node based on the node attributes of the target memory node and the node attributes of the reference memory node, specifically performs the following:

[0231] Add the memory value of the root memory node to the memory values ​​of all memory nodes in the memory graph except the root memory node to obtain the first summed memory value.

[0232] The first sum of memory amounts is used as the amount of reclaimable memory for the root memory node.

[0233] In one implementation, the node attributes of a memory node include the node memory amount, and the attribute value of the node memory amount is the memory amount value; if the target memory node is the end memory node in the memory graph, and the end memory node is a memory node in the memory graph that is not associated as a parent memory node as an edge, then there is no reference memory node that is unreachable from the root memory node.

[0234] Processing unit 1202, when calculating the amount of reclaimable memory for a target memory node based on the node attributes of the target memory node and the node attributes of the reference memory node, specifically performs the following:

[0235] The amount of memory in the target memory node is taken as the amount of reclaimable memory in the target memory node.

[0236] In one implementation, the target memory node is any memory node in the memory graph other than the root memory node and the terminal memory node; the terminal memory node is a memory node in the memory graph that is not associated with a parent memory node as an edge.

[0237] Processing unit 1202, when determining a reference memory node from the memory graph that is unreachable from the root memory node, specifically performs the following functions:

[0238] Remove the target memory node from the memory graph to obtain the updated memory graph;

[0239] Starting from the root memory node in the updated memory graph, traverse each memory node in the updated memory graph along the connecting edges.

[0240] Memory nodes that are not traversed in the updated memory graph are used as reference memory nodes that are unreachable from the root memory node.

[0241] In one implementation, the node attributes of a memory node include the node's memory size, and the attribute value of the node's memory size is a numerical value of the memory size. The processing unit 1202, when calculating the reclaimable memory size of the target memory node based on the node attributes of the target memory node and the node attributes of the reference memory node, specifically performs the following:

[0242] The memory value of the target memory node is added to the memory value of the reference memory node to obtain the second sum of memory values.

[0243] The second sum of memory amounts is used as the amount of reclaimable memory for the target memory node.

[0244] In one implementation, if there are edges of weak reference type in the memory graph, then processing unit 1202 is further used for:

[0245] During the traversal of the updated memory nodes along the edges, the memory nodes in the memory graph are not traversed along the edges of weak reference property types.

[0246] In one implementation, the description data further includes node attribute types for node attributes and edge types for each connected edge; the memory snapshot file includes node attribute fields, node attribute type fields, edge attribute fields, and edge type fields; the processing unit 1202, used to analyze and process the memory snapshot file to obtain the description data of the memory space, specifically for:

[0247] Perform attribute analysis on the node attribute field to obtain the node attributes of each memory node in the memory space, and perform attribute type analysis on the node attribute type field to obtain the attribute type of the node attribute.

[0248] In addition, attribute analysis is performed on the edge attribute field to obtain the edge attributes of the connecting edges that connect each memory node, and type analysis is performed on the edge type field to obtain the edge type of the connecting edge.

[0249] The node attributes include at least one of the following: node type, node identifier, node number, node memory size, edge holding attribute, and node memory indicator identifier. The edge holding attribute is used to indicate the number of edges with the memory node as the parent memory node. The edge attributes include at least one of the following: edge type, edge identifier, and edge pointing attribute. The edge pointing attribute is used to indicate the child memory node pointed to by the edge.

[0250] In one implementation, the description data further includes attribute values ​​of node attributes of memory nodes and attribute values ​​of edge attributes of connected edges; the memory snapshot file also includes an attribute value array and a data query array, the attribute value array including attribute values ​​of the target attribute, and the data query array including query identifiers of the target attribute, wherein the target attribute is a node attribute or an edge attribute; the processing unit 1202 is further configured to:

[0251] Determine the query identifier associated with the target attribute from the data query array;

[0252] Generate index values ​​for target attributes based on query identifiers associated with target attributes;

[0253] Determine the attribute value of the target attribute from the attribute value array according to the index value of the target attribute.

[0254] In one implementation, the node attributes of the memory node include the node memory amount, and the attribute value of the node memory amount is the memory amount value; the processing unit 1202 is further configured to:

[0255] Compare the node memory amount of the target memory node with the reclaimable memory amount of the target memory node to obtain the memory amount comparison result;

[0256] If the memory quantity comparison result meets the memory leak condition, then the target memory node is regarded as the leaking memory node with memory leak;

[0257] The conditions for memory leaks include: the difference between the value of the node memory of the target memory node and the amount of reclaimable memory of the target memory node is greater than the memory threshold.

[0258] In one implementation, the processing unit 1202 is further configured to:

[0259] Output a node relationship graph, which is a directed graph obtained by connecting each memory node with edges based on the connection relationship between each memory node.

[0260] Visually highlight one or more leaking memory nodes in the node relationship graph.

[0261] In one implementation, the processing unit 1202 is further configured to:

[0262] When any memory node in the node relationship graph is triggered, the node information of that memory node is displayed;

[0263] The node information of a memory node includes at least one of the following: node identifier, node number, node memory amount, child memory nodes associated with the node when it is a parent memory node, parent memory node associated with the node when it is a child memory node, and reclaimable memory amount.

[0264] According to one embodiment of this application, Figure 12 The memory processing device shown can be constructed by combining each unit individually or entirely into one or more other units, or one or more of the units can be further divided into multiple functionally smaller units. This can achieve the same operation without affecting the technical effect of the embodiments of this application. The above units are based on logical function division. In practical applications, the function of one unit can also be implemented by multiple units, or the function of multiple units can be implemented by one unit. In other embodiments of this application, the memory processing device may also include other units. In practical applications, these functions can also be implemented with the assistance of other units, and can be implemented by multiple units working together. According to another embodiment of this application, the memory processing device can be executed by running on a general-purpose computing device, such as a computer, which includes processing elements and storage elements such as a central processing unit (CPU), random access storage medium (RAM), and read-only storage medium (ROM), and is capable of performing functions such as... Figure 3 and Figure 8 The computer program (including program code) for each step involved in the corresponding method shown, to construct such... Figure 12 The memory processing apparatus shown herein, and the memory processing method for implementing the embodiments of this application, are described. A computer program may be recorded on, for example, a computer-readable recording medium, loaded onto the aforementioned computing device via the computer-readable recording medium, and executed therein.

[0265] In this embodiment, it is supported to obtain memory snapshot files of the memory space and directly analyze and process them to obtain descriptive data of the memory space. This descriptive data may include node attributes of each memory node and edge attributes of the edges connecting each memory node. Based on these node attributes and edge attributes, the connection relationships between memory nodes can be determined. Then, based on these connection relationships, the root memory node, the target memory node reachable from the root memory node, and the reference memory node unreachable from the root memory node can be determined from each memory space. Finally, based on the target memory node and the reference memory node, the amount of reclaimable memory for the target memory node can be calculated. In the above scheme, there is no need to convert the connection relationships between memory nodes in the memory snapshot file of the memory space; the amount of reclaimable memory for each memory node can be quickly calculated directly based on these connection relationships, thereby helping developers quickly locate memory nodes with memory leaks.

[0266] Figure 13 A schematic diagram of the structure of a computer device provided in an exemplary embodiment of this application is shown. Please refer to... Figure 13 The computer device includes a processor 1301, a communication interface 1302, and a computer-readable storage medium 1303. The processor 1301, communication interface 1302, and computer-readable storage medium 1303 can be connected via a bus or other means. The communication interface 1302 is used to receive and send data. The computer-readable storage medium 1303 can be stored in the computer device's memory and is used to store computer programs, including program instructions. The processor 1301 is used to execute the program instructions stored in the computer-readable storage medium 1303. The processor 1301 (or CPU (Central Processing Unit)) is the computing and control core of the computer device, suitable for implementing one or more instructions, specifically suitable for loading and executing one or more instructions to achieve corresponding method flows or corresponding functions.

[0267] This application embodiment also provides a computer-readable storage medium (Memory), which is a memory device in a computer device used to store programs and data. It is understood that the computer-readable storage medium here can include both the built-in storage medium in the computer device and extended storage media supported by the computer device. The computer-readable storage medium provides storage space that stores the processing system of the computer device. Furthermore, the storage space also stores one or more instructions suitable for loading and execution by the processor 1301, which may be one or more computer programs (including program code). It should be noted that the computer-readable storage medium here can be high-speed RAM memory or non-volatile memory, such as at least one disk storage device; optionally, it can also be at least one computer-readable storage medium located remotely from the aforementioned processor.

[0268] In one embodiment, the computer-readable storage medium stores one or more instructions; the processor 1301 loads and executes one or more instructions stored in the computer-readable storage medium to implement the corresponding steps in the above-described memory processing method embodiment; specifically, the one or more instructions in the computer-readable storage medium are loaded by the processor 1301 and executed as follows:

[0269] Obtain a memory snapshot file of the memory space, and analyze and process the memory snapshot file to obtain the description data of the memory space. The description data includes: the node attributes of each memory node obtained by dividing the memory space, and the edge attributes of each edge connecting each memory node.

[0270] The connection relationships between memory nodes are determined based on the node attributes of each memory node and the edge attributes of each connected edge.

[0271] Based on the connection relationships between memory nodes, the root memory node, the target memory node that is reachable from the root memory node, and the reference memory node that is unreachable from the root memory node are determined from the memory nodes.

[0272] Based on the target memory node and the reference memory node that is unreachable from the root memory node, calculate the amount of reclaimable memory for the target memory node. The amount of reclaimable memory is used to characterize the amount of memory that can be reclaimed after the target memory node is released.

[0273] In one implementation, the node attributes of any memory node include an edge holding attribute, which is used to represent: when any memory node is a parent memory node, the connected edges associated with any memory node; the connected edges are directed edges, and the edge attributes of any connected edge include an edge pointing attribute, which is used to represent the child memory node pointed to by any connected edge.

[0274] When one or more instructions in a computer-readable storage medium are loaded by processor 1301 and executed to determine the connection relationship between memory nodes based on the node attributes of each memory node and the edge attributes of each connected edge, the following steps are specifically performed:

[0275] Based on the attribute values ​​held by the edges of each memory node, determine the parent memory node associated with each edge; and,

[0276] Based on the attribute value of the edge pointing attribute of each edge, determine the child memory node pointed to by each edge;

[0277] A memory graph of the memory space is constructed based on the parent memory node and the child memory node that each edge is associated with. The memory graph is a directed graph obtained by connecting each memory node with each edge. The memory graph can be used to represent the connection relationship between each memory node included in the memory space.

[0278] In one implementation, the node attributes of a memory node include the node's memory size, and the attribute value of the node's memory size is the memory size value; if the target memory node is the root memory node, then the reference memory nodes that are unreachable from the root memory node include: all memory nodes in the memory graph except the root memory node.

[0279] When one or more instructions in a computer-readable storage medium are loaded by processor 1301 and executed to calculate the amount of reclaimable memory in a target memory node based on the node attributes of the target memory node and the node attributes of a reference memory node, the following steps are specifically performed:

[0280] Add the memory value of the root memory node to the memory values ​​of all memory nodes in the memory graph except the root memory node to obtain the first summed memory value.

[0281] The first sum of memory amounts is used as the amount of reclaimable memory for the root memory node.

[0282] In one implementation, the node attributes of a memory node include the node memory amount, and the attribute value of the node memory amount is the memory amount value; if the target memory node is the end memory node in the memory graph, and the end memory node is a memory node in the memory graph that is not associated as a parent memory node as an edge, then there is no reference memory node that is unreachable from the root memory node.

[0283] When one or more instructions in a computer-readable storage medium are loaded by processor 1301 and executed to calculate the amount of reclaimable memory in a target memory node based on the node attributes of the target memory node and the node attributes of a reference memory node, the following steps are specifically performed:

[0284] The amount of memory in the target memory node is taken as the amount of reclaimable memory in the target memory node.

[0285] In one implementation, the target memory node is any memory node in the memory graph other than the root memory node and the terminal memory node; the terminal memory node is a memory node in the memory graph that is not associated with a parent memory node as an edge.

[0286] When one or more instructions in a computer-readable storage medium are loaded by processor 1301 and executed to determine a reference memory node that is unreachable from the root memory node from the memory graph, the following steps are specifically performed:

[0287] Remove the target memory node from the memory graph to obtain the updated memory graph;

[0288] Starting from the root memory node in the updated memory graph, traverse each memory node in the updated memory graph along the connecting edges.

[0289] Memory nodes that are not traversed in the updated memory graph are used as reference memory nodes that are unreachable from the root memory node.

[0290] In one implementation, the node attributes of a memory node include the amount of memory in the node, and the attribute value of the amount of memory is a numerical value of the amount of memory. When one or more instructions in the computer-readable storage medium are loaded by the processor 1301 and executed to calculate the amount of reclaimable memory in the target memory node based on the node attributes of the target memory node and the node attributes of the reference memory node, the following steps are specifically performed:

[0291] The memory value of the target memory node is added to the memory value of the reference memory node to obtain the second sum of memory values.

[0292] The second sum of memory amounts is used as the amount of reclaimable memory for the target memory node.

[0293] In one implementation, if there are edges of weak reference type in the memory graph, one or more instructions in the computer-readable storage medium are loaded by processor 1301 and the following steps are also executed:

[0294] During the traversal of the updated memory nodes along the edges, the memory nodes in the memory graph are not traversed along the edges of weak reference property types.

[0295] In one implementation, the description data also includes node attribute types for node attributes and edge types for each connected edge; the memory snapshot file includes node attribute fields, node attribute type fields, edge attribute fields, and edge type fields; when one or more instructions in the computer-readable storage medium are loaded and executed by the processor 1301 to analyze and process the memory snapshot file to obtain the description data of the memory space, the following steps are specifically performed:

[0296] Perform attribute analysis on the node attribute field to obtain the node attributes of each memory node in the memory space, and perform attribute type analysis on the node attribute type field to obtain the attribute type of the node attribute.

[0297] In addition, attribute analysis is performed on the edge attribute field to obtain the edge attributes of the connecting edges that connect each memory node, and type analysis is performed on the edge type field to obtain the edge type of the connecting edge.

[0298] The node attributes include at least one of the following: node type, node identifier, node number, node memory size, edge holding attribute, and node memory indicator identifier. The edge holding attribute is used to indicate the number of edges with the memory node as the parent memory node. The edge attributes include at least one of the following: edge type, edge identifier, and edge pointing attribute. The edge pointing attribute is used to indicate the child memory node pointed to by the edge.

[0299] In one implementation, the description data further includes attribute values ​​of node attributes of memory nodes and attribute values ​​of edge attributes of connected edges; the memory snapshot file also includes an attribute value array and a data query array, the attribute value array including attribute values ​​of the target attribute, and the data query array including query identifiers of the target attribute, wherein the target attribute is a node attribute or an edge attribute; one or more instructions in the computer-readable storage medium are loaded by the processor 1301 and further execute the following steps:

[0300] Determine the query identifier associated with the target attribute from the data query array;

[0301] Generate index values ​​for target attributes based on query identifiers associated with target attributes;

[0302] Determine the attribute value of the target attribute from the attribute value array according to the index value of the target attribute.

[0303] In one implementation, the node attributes of a memory node include the amount of memory in the node, and the attribute value of the amount of memory is a numerical value of the amount of memory; one or more instructions in the computer-readable storage medium are loaded by the processor 1301 and the following steps are also executed:

[0304] Compare the node memory amount of the target memory node with the reclaimable memory amount of the target memory node to obtain the memory amount comparison result;

[0305] If the memory quantity comparison result meets the memory leak condition, then the target memory node is regarded as the leaking memory node with memory leak;

[0306] The conditions for memory leaks include: the difference between the value of the node memory of the target memory node and the amount of reclaimable memory of the target memory node is greater than the memory threshold.

[0307] In one implementation, one or more instructions in a computer-readable storage medium are loaded by processor 1301 and the following steps are also performed:

[0308] Output a node relationship graph, which is a directed graph obtained by connecting each memory node with edges based on the connection relationship between each memory node.

[0309] Visually highlight one or more leaking memory nodes in the node relationship graph.

[0310] In one implementation, one or more instructions in a computer-readable storage medium are loaded by processor 1301 and the following steps are also performed:

[0311] When any memory node in the node relationship graph is triggered, the node information of that memory node is displayed;

[0312] The node information of a memory node includes at least one of the following: node identifier, node number, node memory amount, child memory nodes associated with the node when it is a parent memory node, parent memory node associated with the node when it is a child memory node, and reclaimable memory amount.

[0313] In this embodiment, it is supported to obtain memory snapshot files of the memory space and directly analyze and process them to obtain descriptive data of the memory space. This descriptive data may include node attributes of each memory node and edge attributes of the edges connecting each memory node. Based on these node attributes and edge attributes, the connection relationships between memory nodes can be determined. Then, based on these connection relationships, the root memory node, the target memory node reachable from the root memory node, and the reference memory node unreachable from the root memory node can be determined from each memory space. Finally, based on the target memory node and the reference memory node, the amount of reclaimable memory for the target memory node can be calculated. In the above scheme, there is no need to convert the connection relationships between memory nodes in the memory snapshot file of the memory space; the amount of reclaimable memory for each memory node can be quickly calculated directly based on these connection relationships, thereby helping developers quickly locate memory nodes with memory leaks.

[0314] This application also provides a computer program product or computer program that includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the aforementioned memory processing method.

[0315] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed in this application can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0316] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. A computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present invention are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in or transmitted through a computer-readable storage medium. The computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state disk (SSD)).

[0317] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in this invention should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.< / dummy>

Claims

1. A memory processing method, characterized in that, include: Obtain a memory snapshot file of the memory space, and analyze and process the memory snapshot file to obtain the description data of the memory space. The description data includes: the node attributes of each memory node obtained by dividing the memory space, and the edge attributes of each connecting edge of each memory node. The connection relationships between the memory nodes are determined based on the node attributes of each memory node and the edge attributes of each connecting edge. Based on the connection relationships between the memory nodes, a root memory node, a target memory node that is reachable from the root memory node, and a reference memory node that is unreachable from the root memory node are determined from the memory nodes. Based on the memory value corresponding to the node memory value of the target memory node and the memory value corresponding to the node memory value of the reference memory node, the reclaimable memory value of the target memory node is calculated. The reclaimable memory value is used to characterize the amount of memory that can be reclaimed after the target memory node is released. The memory quantity of the target memory node is compared with the reclaimable memory of the target memory node to obtain the memory quantity comparison result. If the memory quantity comparison result meets the memory leak condition, then the target memory node is regarded as a leaking memory node with a memory leak. The memory leak condition includes: the difference between the node memory amount of the target memory node and the reclaimable memory amount of the target memory node is greater than a memory amount threshold.

2. The method as described in claim 1, characterized in that, The node attributes of any memory node include an edge holding attribute, which is used to characterize the connecting edges associated with the memory node when the memory node is used as the parent memory node; the connecting edges are directed edges, and the edge attributes of any connecting edge include an edge pointing attribute, which is used to characterize the child memory node pointed to by the connecting edge. Determining the connection relationships between memory nodes based on the node attributes of each memory node and the edge attributes of each connecting edge includes: Based on the attribute values ​​of the edges held by each memory node, determine the parent memory node associated with each connecting edge; and, Based on the attribute value of the edge pointing attribute of each edge, the sub-memory node pointed to by each edge is determined; A memory graph of the memory space is constructed based on the parent memory node associated with each edge and the child memory node it points to; the memory graph is a directed graph obtained by connecting each memory node with each edge, and the memory graph can be used to represent the connection relationship between each memory node included in the memory space.

3. The method as described in claim 2, characterized in that, If the target memory node is the root memory node, then the reference memory nodes that are unreachable from the root memory node include: all memory nodes in the memory graph except the root memory node; The step of calculating the reclaimable memory amount of the target memory node based on the memory amount value corresponding to the node memory amount of the target memory node and the memory amount value corresponding to the node memory amount of the reference memory node includes: The memory value of the root memory node is added to the memory value of all memory nodes in the memory graph except the root memory node to obtain the first summed memory value. The sum of the first memory amounts is taken as the amount of reclaimable memory for the root memory node.

4. The method as described in claim 2, characterized in that, If the target memory node is the end memory node in the memory graph, and the end memory node is a memory node in the memory graph that is not associated as a parent memory node with an edge, then there is no reference memory node that is unreachable from the root memory node. The step of calculating the reclaimable memory amount of the target memory node based on the memory amount value corresponding to the node memory amount of the target memory node and the memory amount value corresponding to the node memory amount of the reference memory node includes: The memory amount of the target memory node is taken as the amount of reclaimable memory of the target memory node.

5. The method as described in claim 2, characterized in that, The target memory node is any memory node in the memory graph other than the root memory node and the end memory node; the end memory node is a memory node in the memory graph that is not associated as a parent memory node with an edge. Determining reference memory nodes that are unreachable from the root memory node from the memory graph includes: Remove the target memory node from the memory graph to obtain an updated memory graph; Starting from the root memory node in the updated memory graph, traverse each memory node in the updated memory graph along the connecting edges. Memory nodes that are not traversed in the updated memory graph are used as reference memory nodes that are unreachable from the root memory node.

6. The method as described in claim 5, characterized in that, The step of calculating the reclaimable memory amount of the target memory node based on the memory amount value corresponding to the node memory amount of the target memory node and the memory amount value corresponding to the node memory amount of the reference memory node includes: The memory value of the target memory node is added to the memory value of the reference memory node to obtain the second summed memory value; The second summed memory amount is taken as the reclaimable memory amount of the target memory node.

7. The method as described in claim 5, characterized in that, If the memory graph contains edges of weak reference type, the method further includes: During the traversal of the memory nodes in the updated memory graph along the edges, the memory nodes in the memory graph are not traversed along the edges of the weak reference property type.

8. The method as described in claim 1, characterized in that, The description data also includes the node attribute type of the node attributes, and the edge type of each connected edge; the memory snapshot file includes node attribute fields, node attribute type fields, edge attribute fields, and edge type fields; The step of analyzing and processing the memory snapshot file to obtain descriptive data of the memory space includes: Attribute analysis is performed on the node attribute field to obtain the node attributes of each memory node in the memory space, and attribute type analysis is performed on the node attribute type field to obtain the attribute type of the node attribute. In addition, attribute analysis is performed on the edge attribute field to obtain the edge attributes of the connecting edges that connect each memory node, and type analysis is performed on the edge type field to obtain the edge type of the connecting edge. The node attributes include at least one of the following: node type, node identifier, node number, node memory size, edge holding attribute, and node memory indicator identifier. The edge holding attribute is used to indicate the number of edges with the memory node as the parent memory node. The edge attributes include at least one of the following: edge type, edge identifier, and edge pointing attribute. The edge pointing attribute is used to indicate the child memory node pointed to by the edge.

9. The method as described in claim 8, characterized in that, The description data also includes attribute values ​​of node attributes of memory nodes and attribute values ​​of edge attributes of connected edges; the memory snapshot file also includes an attribute value array and a data query array, the attribute value array including attribute values ​​of target attributes, and the data query array including query identifiers of target attributes, wherein the target attribute is a node attribute or an edge attribute; the method further includes: Determine the query identifier associated with the target attribute from the data query array; An index value for the target attribute is generated based on the query identifier associated with the target attribute; The attribute value of the target attribute is determined from the attribute value array according to the index value of the target attribute.

10. The method as described in claim 1, characterized in that, The method further includes: Output a node relationship graph, which is a directed graph obtained by connecting the memory nodes with the edges based on the connection relationship of each memory node; One or more leaking memory nodes are visually highlighted in the node relationship diagram.

11. The method as described in claim 10, characterized in that, The method further includes: When any memory node in the node relationship graph is triggered, the node information of that memory node is displayed; The node information of a memory node includes at least one of the following: node identifier, node number, node memory amount, child memory nodes associated with the node when it is a parent memory node, parent memory node associated with the node when it is a child memory node, and reclaimable memory amount.

12. A memory processing device, characterized in that, include: The acquisition unit is used to acquire a memory snapshot file of the memory space and analyze and process the memory snapshot file to obtain the description data of the memory space. The description data includes: the node attributes of each memory node obtained by dividing the memory space, and the edge attributes of each connecting edge of each memory node. The processing unit is configured to determine the connection relationship between the memory nodes based on the node attributes of each memory node and the edge attributes of each connecting edge. The processing unit is further configured to determine, based on the connection relationship between the memory nodes, a root memory node, a target memory node that is reachable from the root memory node, and a reference memory node that is unreachable from the root memory node. The processing unit is further configured to calculate the amount of reclaimable memory of the target memory node based on the memory value corresponding to the node memory value of the target memory node and the memory value corresponding to the node memory value of the reference memory node. The amount of reclaimable memory is used to characterize the amount of memory that can be reclaimed after the target memory node is released. The processing unit is further configured to compare the memory quantity value of the target memory node with the reclaimable memory quantity of the target memory node to obtain a memory quantity comparison result; if the memory quantity comparison result meets the memory leak condition, then the target memory node is designated as a leaking memory node with a memory leak; wherein, the memory leak condition includes: the memory quantity difference between the memory quantity value of the target memory node and the reclaimable memory quantity of the target memory node is greater than a memory quantity threshold.

13. A computer device, characterized in that, include: A processor, adapted to execute computer programs; A computer-readable storage medium storing a computer program that, when executed by the processor, implements the memory processing method as described in any one of claims 1-11.

14. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program adapted to be loaded by a processor and executed as described in any one of claims 1-11.

15. A computer program product, characterized in that, The computer program product includes computer instructions that, when executed by a processor, implement the memory processing method as described in any one of claims 1-11.

Citation Information

Patent Citations

  • Embedded software memory management system

    CN108132842A

  • Memory space management method and apparatus

    CN108628753A