Memory leak detection method and device, medium, electronic equipment and program product

CN122963850APending Publication Date: 2026-10-23BEIJING ZITIAO NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611257128.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-18
Publication Date
2026-10-23

AI Technical Summary

Technical Problem

不同环境中的不同对象相互持有会引发跨环境循环引用,导致内存泄漏直至应用发生内存溢出(Out Of Memory,OOM)

Benefits of technology

[0009]通过上述技术方案,获取跨运行环境的对象间引用路径,并基于该引用关系进行内存泄漏检测,从而在不同编程语言混编场景下,能够有效识别跨环境的对象引用链路,将原本难以追踪的跨环境循环引用转化为可检测的引用关系,进而为内存泄漏的判定提供依据,有助于避免因跨环境循环引用导致的内存溢出问题,提升应用程序的稳定性和可靠性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122963850A_ABST
    Figure CN122963850A_ABST
Patent Text Reader

Abstract

A memory leakage detection method, device, medium, electronic equipment and program product, relating to the technical field of computer, the memory leakage detection method comprises: obtaining a reference relationship, the reference relationship represents the reference path between objects in an object set, the object set comprises a first object and a second object, the first object belongs to a first running environment, and the second object belongs to a second running environment; obtaining a detection result, the detection result is obtained based on the reference relationship for memory leakage detection. By obtaining the reference path between objects across the running environment and performing memory leakage detection based on the reference relationship, in the mixed programming language scene, the object reference link across the environment can be effectively identified, the cross-environment circular reference which is originally difficult to track is converted into a detectable reference relationship, and then a basis is provided for the judgment of memory leakage, which helps to avoid the memory overflow problem caused by the cross-environment circular reference, and improves the stability and reliability of the application program.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This content relates to the field of computer technology, specifically to a memory leak detection method, device, medium, electronic device, and program product. Background Technology

[0002] In scenarios where two different programming languages ​​are mixed, such as KMP (Kotlin Multiplatform) and Objective-C (Objective-C), cross-language interaction is required between the runtime environments of each language. Mutual references between objects in different environments can lead to cross-environment circular references, causing memory leaks and eventually resulting in Out of Memory (OOM) errors. Current technologies still present challenges in handling such cross-environment circular references. Summary of the Invention

[0003] This content section is provided to briefly introduce the concepts, which will be described in detail in the examples section later. This content section is not intended to identify key or essential features of the claimed technical solution, nor is it intended to limit the scope of the claimed technical solution.

[0004] Firstly, a memory leak detection method is provided, including: Obtain reference relationships, which represent reference paths between objects in an object set, the object set including a first object and a second object, the first object belonging to a first runtime environment, and the second object belonging to a second runtime environment; The detection results are obtained based on the reference relationship to detect memory leaks.

[0005] Secondly, a memory leak detection device is provided, comprising: The first obtaining module is used to obtain reference relationships, wherein the reference relationships represent reference paths between objects in an object set, the object set includes a first object and a second object, the first object belongs to a first runtime environment, and the second object belongs to a second runtime environment; The second obtaining module is used to obtain the detection result, which is obtained by memory leak detection based on the reference relationship.

[0006] Thirdly, a computer-readable medium is provided having a computer program stored thereon, wherein the computer program, when executed by a processing device, implements the steps of the memory leak detection method described in the first aspect.

[0007] Fourthly, an electronic device is provided, comprising: A storage device on which computer programs are stored; A processing device for executing the computer program in the storage device to implement the steps of the memory leak detection method of the first aspect.

[0008] Fifthly, a computer program product is provided, comprising a computer program, wherein when the computer program is executed by a processor, it implements the steps of the memory leak detection method described in the first aspect.

[0009] By using the above technical solution, the reference paths between objects across runtime environments can be obtained, and memory leak detection can be performed based on the reference relationship. In mixed programming scenarios, cross-environment object reference chains can be effectively identified, and the originally difficult-to-trace cross-environment circular references can be transformed into detectable reference relationships. This provides a basis for the determination of memory leaks, helps to avoid memory overflow problems caused by cross-environment circular references, and improves the stability and reliability of applications.

[0010] Other features and advantages of the technical solution will be described in detail in the following examples section. Attached Figure Description

[0011] The above and other features, advantages, and aspects of the technical solution will become more apparent when considered in conjunction with the accompanying drawings and the following examples. Throughout the drawings, the same or similar reference numerals denote the same or similar elements. It should be understood that the drawings are schematic, and the originals and elements are not necessarily drawn to scale. In the drawings: Figure 1 This is a schematic diagram illustrating application scenarios of memory leak detection methods based on certain situations.

[0012] Figure 2 This is a flowchart illustrating memory leak detection methods based on certain scenarios.

[0013] Figure 3 This is a global reference relationship diagram shown based on certain situations.

[0014] Figure 4 This is a schematic diagram illustrating memory leak detection methods based on certain scenarios.

[0015] Figure 5 This is a schematic diagram of a memory leak detection device shown under certain circumstances.

[0016] Figure 6 This is a schematic diagram of the module connections of an electronic device provided under certain circumstances. Detailed Implementation

[0017] The technical solution will now be described in more detail with reference to the accompanying drawings. Although certain scenarios are shown in the drawings, it should be understood that the technical solution can be implemented in various forms and should not be construed as limited to the scenarios described herein. Rather, these scenarios are provided to provide a more thorough and complete understanding of the technical solution. It should be understood that the accompanying drawings and the scenarios described are for illustrative purposes only and are not intended to limit the scope of protection of the technical solution.

[0018] It should be understood that the steps described in the method implementation may be performed in different orders and / or in parallel. Furthermore, the method implementation may include additional steps and / or omit the steps shown. The scope of the technical solution is not limited in this respect.

[0019] The term "comprising" and its variations as used herein can be open-ended, meaning "including but not limited to". The term "based on" can mean "at least partially based on". The term "one case" means "at least one case"; the term "another case" means "at least one additional case"; the term "some cases" means "at least some cases". Definitions of other terms will be given in the following description.

[0020] It should be noted that the concepts of "first" and "second" mentioned here are only used to distinguish different devices, modules or units, and are not used to limit the order of the functions performed by these devices, modules or units or their interdependencies.

[0021] It should be noted that the terms "one" and "more" used here are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise expressly indicated in the context, they should be understood as "one or more".

[0022] The names of the messages or information exchanged between the multiple devices in the implementation are for illustrative purposes only and are not intended to limit the scope of these messages or information.

[0023] It is understandable that before using the technical solutions provided here, users should be informed of the types, scope of use, and usage scenarios of the personal information involved in accordance with relevant laws and regulations, and their authorization should be obtained through appropriate means.

[0024] For example, upon receiving a user's active request, a prompt message is sent to the user to explicitly inform them that the requested operation will require the acquisition and use of the user's personal information. This allows the user to independently choose, based on the prompt message, whether to provide personal information to the software or hardware such as electronic devices, applications, servers, or storage media performing the operations described herein.

[0025] As an optional but non-limiting implementation, in response to a user's active request, sending a prompt message to the user can be done via a pop-up window, where the prompt message can be presented in text format. Furthermore, the pop-up window can also include a selection control allowing the user to choose "agree" or "disagree" to provide personal information to the electronic device.

[0026] It is understood that the above notification and user authorization process are merely illustrative and do not constitute a limitation on the implementation of the technical solution. Other methods that comply with relevant laws and regulations may also be applied to the implementation of the technical solution.

[0027] At the same time, it is understood that the data involved in the technical solution (including but not limited to the data itself, the acquisition or use of the data) should comply with the requirements of relevant laws, regulations and related provisions.

[0028] In scenarios where two different programming languages ​​are mixed (e.g., KMP and Objective-C mixed programming), cross-language interaction is required between the runtime environments corresponding to the different programming languages ​​(KMP environment and Objective-C environment).

[0029] When an object in a KMP environment (KMP object) and an object in an Objective-C environment (Objective-C object) need to communicate with each other, the runtime creates wrapper objects for each other to ensure type compatibility and method calls. Specifically: 1. Passing KMP objects to the Objective-C environment: K / N (a technology that compiles Kotlin code into native binaries that can run without a virtual machine) creates an Objective-C type wrapper object (OCWrapper) at runtime, which holds a reference to the original KMP object.

[0030] 2. Passing Objective-C objects to the KMP environment: The K / N runtime also creates a wrapper object of type KMP (KMPWrapper), which internally holds a reference to the original Objective-C object.

[0031] When KMP objects in a KMP environment and OC objects in an OC environment mutually hold each other's references, a cross-environment circular reference is formed, causing memory to fail to be released, leading to memory leaks and eventually an OutOfMemoryError (OOM) in the application. Current technologies still present difficulties in handling such cross-environment circular references.

[0032] Specifically, when an application runs on a computer, there are situations where one object references another object (which can also be called a memory storage object or node), and each object occupies memory on the computer. When an object is no longer referenced by any other object, that is, when the object is no longer needed, it should be released. However, in the case of circular references across environments, the objects that are mutually held continue to reference each other, preventing them from being properly released and thus causing memory leaks.

[0033] In view of this, the technical solution provides a memory leak detection method, device, medium, electronic device and program product to solve the above-mentioned technical problems.

[0034] The memory leak detection method provided by the technical solution can be executed by an electronic device, which can be at least one of a terminal device and a server. Figure 1 This is a schematic diagram illustrating application scenarios of memory leak detection methods based on certain situations. For example... Figure 1 As shown, the application scenarios may include terminal device 101 and server 102.

[0035] For example, terminal device 101 has an application installed for memory leak detection. Server 102 is the background server for the application, providing background services for the application.

[0036] For example, after the application on terminal device 101 performs memory leak detection, the reference relationships can be displayed on terminal device 101. Memory leak detection can be completed on terminal device 101, or data can be collected on terminal device 101 and then sent to server 102 for subsequent data processing to complete the memory leak detection.

[0037] The terminal device 101 can be at least one of the following: a smartphone, a smartwatch, a desktop computer, a laptop, a virtual reality terminal, an augmented reality terminal, a wireless terminal, and a laptop computer. The terminal device 101 has communication capabilities and can access wired or wireless networks. The term "terminal device 101" can refer to one of multiple terminal devices; those skilled in the art will understand that the number of such terminal devices can be greater or less. The server 102 can be a single physical server, a server cluster consisting of multiple physical servers, or a distributed file system. It can also be a cloud server providing 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 artificial intelligence platforms.

[0038] For example, server 102 and terminal device 101 are connected directly or indirectly via wired or wireless communication, without limitation.

[0039] Optionally, the number of servers 102 can be more or less, and there is no limitation thereto. Of course, servers 102 may also include other functional servers to provide more comprehensive and diversified services. Specifically, server 102 undertakes the main computing work, and terminal device 101 undertakes secondary computing work; or, server 102 undertakes secondary computing work, and terminal device 101 undertakes the main computing work; or, server 102 or terminal device 101 can each independently undertake computing work, and there is no limitation thereto.

[0040] Figure 2 This is a flowchart illustrating memory leak detection methods based on certain scenarios. For example... Figure 2 As shown, the technical solution provides a memory leak detection method, which can be executed by a memory leak detection device, which can be implemented by software and / or hardware. Figure 2 As shown, the method may include the following steps.

[0041] S201: Obtain the reference relationship.

[0042] Reference relationships can represent the reference paths between objects in a collection of objects. The collection of objects can include a first object and a second object. The first object belongs to a first runtime environment, and the second object belongs to a second runtime environment.

[0043] Here, the primary runtime environment can refer to the execution environment of a programming language, such as a platform-specific development environment or a cross-platform shared logic environment. For example, a platform-specific development environment could be an Objective-C environment, and a cross-platform shared logic environment could be a KMP environment.

[0044] The second runtime environment can refer to the execution environment of another programming language that is different from the first runtime environment.

[0045] The first object can refer to a memory object belonging to a first runtime environment, such as a KMP object in a KMP environment or an OC object in an OC environment. The second object can refer to a memory object belonging to a second runtime environment.

[0046] For example, if the first runtime environment is a KMP environment, the first object is a KMP object; if the second runtime environment is an Objective-C environment, the second object is an Objective-C object; conversely, if the first runtime environment is an Objective-C environment, the first object is an Objective-C object; and if the second runtime environment is a KMP environment, the second object is a KMP object. A reference relationship can be, for example, that object A points to object B, and object B points to object A.

[0047] For example, consider a hybrid project running both a KMP environment and an Objective-C environment. In the KMP environment, there is an object A (the first object), and in the Objective-C environment, there is an object B (the second object). We can first obtain the memory data of object A, which includes its address 0x1000, its type identifier KMP_Object, and its list of references. From this, we find that object A holds a reference to address 0x2000. Then, based on address 0x2000, we search in memory to obtain object B, and identify that object B belongs to the Objective-C environment. Based on this process, we can obtain the reference relationship between object A and object B. Using the same method, if object B also points to object A, then a circular reference across environments is confirmed.

[0048] By performing the above steps, you can obtain a reference relationship between an Objective-C object and a KMP object, or a reference relationship between a KMP object and an Objective-C object.

[0049] In some cases, reference relationships can include first, second, third, and fourth reference relationships. Specifically, a first reference relationship indicates that a first object holds a second object; a second reference relationship indicates that a second object holds a first object; a third reference relationship indicates that one second object holds another second object (i.e., second objects mutually hold each other); and a fourth reference relationship indicates that one first object holds another first object (i.e., first objects mutually hold each other).

[0050] S201, which obtains reference relationships, can be understood as traversing a collection of objects, acquiring reference dependency information between objects, and generating reference relationships to represent the reference paths between objects. Specifically, each object in the collection can be used as a starting node to resolve the object's attribute fields, member variables, closure capture lists, and reference targets stored in associative containers (such as collections, dictionaries, etc.). For each valid reference, it can be recorded as a directed edge from the source object to the target object, and the runtime environment type corresponding to the reference can be labeled.

[0051] S202: Obtain the test results.

[0052] The detection results can be obtained by detecting memory leaks based on reference relationships.

[0053] The detection result can refer to the set of circular reference paths found after traversing the directed edges of the reference relationships, starting from each object in the object collection. If the set is empty, it means that there is currently no memory leak caused by circular references; if it is not empty, each path is a potential leak point.

[0054] A memory leak can refer to the phenomenon where objects that are no longer needed cannot be released because they are still referenced by other objects, resulting in continuous memory usage.

[0055] S202 obtains the detection result, which can be understood as taking the reference relationship data obtained in S201 as input, taking each object in the object set as the starting node, traversing along the directed edges in the reference relationship, and detecting whether there is a circular reference path in the object set.

[0056] A circular reference path can be a closed reference chain that starts from a given object, follows one or more directed reference edges, and eventually returns to the original object. By obtaining reference paths between objects across runtime environments and performing memory leak detection based on these reference relationships, cross-environment object reference chains can be effectively identified in mixed programming language scenarios. This transforms previously difficult-to-trace cross-environment circular references into detectable reference relationships, thus providing a basis for determining memory leaks. This helps avoid memory overflow problems caused by cross-environment circular references and improves the stability and reliability of applications.

[0057] Next, we will provide a detailed explanation of memory leak detection methods.

[0058] In the case where the first runtime environment may include a platform-specific development environment (such as an Objective-C environment), and the second runtime environment may include a cross-platform shared logic environment (such as a KMP environment), the reference relationship may include a first reference relationship representing that the first object holds a second object.

[0059] S201 obtains reference relationships, which may include: A1: Obtain the first data.

[0060] The first data can represent the memory data of the first object.

[0061] The first data can refer to data used to describe the state, attributes, or structure of the first object in memory, such as the memory address, member variable information, or memory snapshot of the first object.

[0062] For example, if the first runtime environment is an Objective-C environment, the first data can be memory snapshot data of the Objective-C object, which contains memory layout information of the Objective-C object, such as the offset of instance variables (Ivar), property names, property codes, and the contents of reference storage structures (such as refHolder).

[0063] A1 obtaining the first data can be understood as acquiring the memory data of the first object belonging to the first runtime environment. This first data can provide a foundation for subsequent identification of objects across environments.

[0064] A2: Based on the first data, obtain the second object.

[0065] This can be understood as extracting or deriving a second object related to the first object from the first data obtained in A1. The second object belongs to a second runtime environment, that is, it comes from a different programming language environment than the first object.

[0066] A3: Based on the first object and the second object, obtain the first reference relationship.

[0067] The first reference relationship can represent that the first object holds the second object, that is, a directed reference edge from the first object belonging to the first runtime environment to the second object belonging to the second runtime environment.

[0068] If the first runtime environment is an Objective-C environment and the first object is an Objective-C object, and the second runtime environment is a KMP environment and the second object is a KMP object, then the first reference relationship can be characterized as follows: the Objective-C object holds a reference to the KMP object.

[0069] A3 obtains the first reference relationship, which can be understood as obtaining the reference relationship between the first object and the second object based on the reference path between the first object and the second object.

[0070] By obtaining the memory data of the first object from the first runtime environment and extracting the second object associated with the first object in the second runtime environment based on the memory data, the first reference relationship between the first object and the second object is obtained, thus achieving accurate identification of cross-environment references from the OC environment side.

[0071] The above A2, based on the first data, obtains the second object, which may include: A21: Obtain the reference storage structure.

[0072] The reference storage structure can be obtained based on the first data.

[0073] Here, the reference storage structure refers to a specific data structure within the first object used to store cross-environment reference information. In the Objective-C environment, this reference storage structure can be represented as a `refHolder` member variable, used to wrap the reference information of the Objective-C object pointing to the KMP object. This reference storage structure can contain at least two parts of information: a type identifier and a memory address.

[0074] A22: Obtain the first memory address.

[0075] The first memory address can be obtained based on the type identifier of the reference storage structure, and the first memory address can be used to identify the second object.

[0076] A type identifier can be a field in a reference storage structure used to distinguish the reference type. This type identifier can indicate what type of reference information is stored internally, such as distinguishing between permanent references (PermanentRef) and regular references (RegularRef). Different type identifiers can correspond to different methods of retrieving memory addresses.

[0077] The first memory address can be the actual memory address of the KMP object, used to identify the second object.

[0078] A22 obtaining the first memory address can be understood as reading the type identifier field in the reference storage structure to determine whether the current type identifier is in a permanent reference state or a regular reference state. Depending on the state, the corresponding address extraction method is used: if it is in a permanent reference state, the first method can be used to extract the address from the reference storage structure; if it is in a regular reference state, the second method can be used. The final obtained first memory address is the actual memory address of the referenced KMP object, used to identify the second object.

[0079] By obtaining the reference storage structure based on the first data and distinguishing different states according to the type identifier in the reference storage structure, and then using different address extraction methods (the first method or the second method) for different states to obtain the first memory address, the second object can be accurately located. On the one hand, the type identifier differentiation mechanism can adaptively handle cross-environment references with different storage formats, avoiding address extraction failures caused by differences in reference storage structures; on the other hand, obtaining the actual memory address of the KMP object can provide reliable basic data for subsequent detection of cross-environment circular references. Therefore, in scenarios where Objective-C and KMP are mixed, the compatibility and accuracy of cross-environment reference resolution can be improved, thereby effectively supporting the detection of memory leak risks and improving the memory management efficiency and stability of applications.

[0080] In one scenario, the reference storage structure obtained by A21 above may include: A211: Iterate through the instance variables in the first data to obtain the location information.

[0081] Location information can be used to characterize the location of instance variables.

[0082] Instance variables can be member variables defined in a class or object in Objective-C. Each instance variable occupies a specific location in the memory layout of the first object.

[0083] Location information can be a set of information used to uniquely identify the location of an instance variable in the object's memory. Location information can include one or more combinations of offset, attribute name, and attribute code.

[0084] A211 iterates through the instance variables in the first data to obtain location information. This can be understood as parsing the first data obtained by A1 and using the Objective-C Runtime mechanism to iterate through all instance variables defined in the first object. For each instance variable iterates through, it obtains its offset, attribute name, attribute code, and other information, using this information as location information to uniquely identify the location of the instance variable in the memory of the first object.

[0085] A212: Obtain the reference storage structure based on the location information of the instance variable.

[0086] Based on the location information obtained from A211, the corresponding location in the memory of the first object is located, and the content stored at that location is read. The read content is the reference storage structure. For example, this content can be a structure or object of type RefHolder, which contains information such as type identifier and memory address.

[0087] By accurately pinpointing the memory location of target instance variables using multi-dimensional location information, ambiguity caused by name matching is avoided; the memory content is read to obtain the reference storage structure, which is logically clear and efficient, providing a reliable data foundation for subsequent cross-environment circular reference detection.

[0088] In one scenario, obtaining the first memory address via A22 may include: A221: Get the first stored value, which represents the pointer value stored in the reference storage structure.

[0089] A222: When the type identifier of the referenced storage structure is the first type identifier, the first storage value is used as the first memory address.

[0090] The first type of identifier can represent a permanent reference state, in which the reference storage structure directly stores the actual memory address of the KMP object.

[0091] When the type identifier of the referenced storage structure is the first type identifier, the first memory address can be obtained by direct reading, that is, the first storage value is directly used as the first memory address.

[0092] For example, when reading the type identifier in the reference storage structure and determining that it is the first type identifier (PermanentRef), a direct read method is used, that is, the first stored value is directly read from the reference storage structure and this value is used as the first memory address. A223: When the type identifier of the reference storage structure is the second type identifier, the memory address corresponding to the first stored value is obtained and used as the first memory address.

[0093] The second type of identifier can represent a normal reference state, in which the reference storage structure stores an intermediate pointer, and dereferencing is required to obtain the real memory address of the KMP object.

[0094] When the type identifier of the reference storage structure is a second type identifier, the first memory address can be obtained through indirect dereferencing. That is, the memory address corresponding to the first stored value is obtained and used as the first memory address. For example, the indirect dereferencing method can be to use the first stored value stored in the reference storage structure as an intermediate pointer, perform a dereferencing operation on this pointer, and use the memory address obtained after dereferencing as the first memory address.

[0095] For example, when reading the type identifier in the reference storage structure and determining that it is the second type identifier (RegularRef), an indirect dereference method is used. That is, the first storage value is read from the reference storage structure, which is an intermediate pointer. Then, a dereference operation is performed on the pointer, and the memory address obtained after dereferencing is used as the first memory address.

[0096] For example, for the reference storage structure `refHolder`, read the memory at offset 8 bytes from `refHolder` to obtain the first stored value `rawPtr`; read the memory at offset 24 bytes from `refHolder` to obtain the index type value, where 0 corresponds to the second type identifier (RegularRef) and 1 corresponds to the first type identifier (PermanentRef). If the index type is 1 (first type identifier, PermanentRef), a direct read method is used, taking the first stored value `rawPtr` itself as the first memory address, which is the actual memory address of the KMP object; if the index type is 0 (second type identifier, RegularRef), an indirect dereference method is used, first reading the first stored value `rawPtr`, then reading the value stored at the memory address pointed to by `rawPtr`, which is the actual memory address of the KMP object, and using it as the first memory address.

[0097] By distinguishing between permanent and regular references using type identifiers, and adaptively employing either direct reading or indirect dereferencing address extraction methods for different states, this approach is compatible with cross-environment references of different storage formats. It accurately obtains the real memory address of KMP objects, avoiding address extraction errors caused by differences in storage methods, and provides a unified and reliable address information foundation for detecting cross-environment circular references.

[0098] In the case where the first runtime environment may include a platform-specific development environment (such as an Objective-C environment), and the second runtime environment may include a cross-platform shared logic environment (such as a KMP environment), the reference relationship may include a second reference relationship representing that the second object holds a first object.

[0099] S201 obtains reference relationships, which may include: B1: Obtain the second data.

[0100] The second data can represent the memory data of the second object.

[0101] The second data can refer to data used to describe the state, attributes, or structure of the second object in memory, such as the memory address, member variable information, or memory snapshot of the second object.

[0102] For example, the second data can be KMP Dump (exported) data, which can contain memory node metadata of the KMP environment, such as the address, type identifier, reference offset, etc. of KMP objects.

[0103] B1 obtaining the second data can be understood as acquiring the memory data of a second object belonging to a second runtime environment. This second data can provide a foundation for subsequent cross-environment object identification.

[0104] B2: Obtain the first object based on the second data.

[0105] This can be understood as extracting or deriving a first object that is related to the second object from the second data obtained in B1. The first object belongs to the first runtime environment, that is, it comes from a different programming language environment than the second object.

[0106] B3: Obtain the second reference relationship based on the first and second objects.

[0107] The second reference relationship can represent that the second object holds the first object, that is, a directed reference edge from the second object belonging to the second runtime environment to the first object belonging to the first runtime environment.

[0108] If the first runtime environment is an Objective-C environment and the first object is an Objective-C object, and the second runtime environment is a KMP environment and the second object is a KMP object, then the second reference relationship can be characterized as follows: the KMP object holds a reference to the Objective-C object.

[0109] B3 obtains the second reference relationship, which can be understood as obtaining the reference relationship between the second object and the first object based on the reference path between the first object and the second object.

[0110] By obtaining the memory data of the second object from the second runtime environment and extracting the first object in the first runtime environment associated with the second object based on the memory data, the second reference relationship held by the second object to the first object is obtained, thus realizing the accurate identification of cross-environment references from the KMP environment side.

[0111] The above B2, based on the second data, obtains the first object, which may include: B21: Obtain the first data segment.

[0112] The first data segment can be a data segment that represents the second data segment with a third type identifier.

[0113] The third type identifier can be a specific type identifier field applied to the first perspective (the first runtime environment is an Objective-C environment, and the second runtime environment is a KMP environment). It is used to mark the data segment storing cross-environment reference information in the memory data of an Objective-C object. This identifier points to the KMP object held by the Objective-C object, i.e., a cross-environment reference. For example, the third type identifier could be TAG_EXTRA_OBJECT, used to identify the reference storage structure in the Objective-C object that points to the KMP object.

[0114] B21 obtains the first data segment, which can be understood as parsing the second data of the second object (KMP object), searching for the data segment with the third type identifier in its metadata, and obtaining the first data segment.

[0115] For example, look for the data segment with the tag field value TAG_EXTRA_OBJECT; this data segment is the first data segment. This data segment records cross-environment reference information, including the memory address of the reference source (KMP object) and the memory address of the reference target (OC object).

[0116] B22: Obtain the second memory address based on the first data segment.

[0117] The second memory address can be used to identify the first object. The second memory address can be the memory address of the Objective-C object extracted from the first data segment.

[0118] From the first data segment obtained from B21, the memory address of the reference target, i.e. the memory address of the OC object, is extracted and used as the second memory address. This address can be used to identify the first object (OC object).

[0119] By parsing specific type identifiers in KMP object metadata, cross-environment reference information can be accurately located, and the address of OC object can be actively extracted to provide a data foundation for subsequent construction of reference relationships between KMP objects and OC objects, thereby providing bidirectional reference data support for the complete detection of cross-environment circular references.

[0120] In the case where the first runtime environment may include a platform-specific development environment (such as an Objective-C environment), and the corresponding second runtime environment may include a cross-platform shared logic environment (such as a KMP environment), the reference relationship may include a third reference relationship representing that one second object holds another second object.

[0121] To obtain the reference relationships between multiple KMP objects in a KMP environment, the second runtime environment may include a KMP environment, and the second object may include a first sub-object and a second sub-object; the second object is a KMP object, and the first and second sub-objects are also KMP objects. The first sub-object can be one of the KMP sub-objects in the second object (KMP object) as the source node of the reference relationship, and the second sub-object can be the target KMP object referenced by the first sub-object as the target node of the reference relationship.

[0122] In one scenario, S201 obtaining a reference relationship may include: C1: Obtain the second data.

[0123] The second data can represent the memory data of the second object.

[0124] The second data can refer to data used to describe the state, attributes, or structure of the second object in memory, such as the memory address, member variable information, or memory snapshot of the second object.

[0125] For example, the second data can be KMP Dump (exported) data, which can contain memory node metadata of the KMP environment, such as the address, type identifier, reference offset, etc. of KMP objects.

[0126] C1 obtaining the second data can be understood as acquiring the memory data of a second object belonging to a second runtime environment. This second data can provide a foundation for subsequent cross-environment object identification.

[0127] C2: Obtain the second data segment.

[0128] The second data segment can represent the data segment in the second data that has a fourth type identifier.

[0129] The fourth type identifier can be a specific type identifier field applied within the KMP environment. It is used to mark data segments in the KMPDump data that store reference relationships between KMP objects. This identifier points to a reference within a KMP object to other KMP objects, i.e., a reference within the same environment. For example, the fourth type identifier may include TAG_TYPE, TAG_OBJECT, and TAG_ARRAY, used to mark data segments such as type information, object nodes, and array nodes, respectively.

[0130] The second data segment can be a data segment in the first data that has a fourth type identifier. Depending on the type identifier, the second data segment can be, for example, a type information (TAG_TYPE) data segment, an object node (TAG_OBJECT) data segment, or an array node (TAG_ARRAY) data segment.

[0131] C2 obtains the second data segment, which can be understood as streaming the second data (KMP Dump data), parsing it according to a specific data structure, classifying and parsing the values ​​of specific field tags, and searching for data segments with a fourth type identifier.

[0132] Specifically, when a data segment with a tag value of TAG_TYPE, TAG_OBJECT, or TAG_ARRAY is encountered, this data segment is treated as the second data segment.

[0133] C3: Based on the second data segment, obtain the third and fourth memory addresses.

[0134] The third memory address can be used to identify the first sub-object, and the fourth memory address can be used to identify the second sub-object.

[0135] The third memory address can be the memory address (obj_id) of the first sub-object extracted from the second data segment, used to identify the first sub-object that serves as the reference source.

[0136] The fourth memory address can be the memory address (ref_id) of the second sub-object extracted from the second data segment, used to identify the second sub-object that is the target of the reference, representing the target KMP object referenced by the first sub-object.

[0137] C3 obtains the third and fourth memory addresses based on the second data segment. This can be understood as extracting the source address and target address from the second data segment obtained by C1. Specifically, the memory address of the first sub-object is extracted from the second data segment as the third memory address, and the memory address of the second sub-object referenced by the first sub-object is extracted from the second data segment as the fourth memory address.

[0138] C4: Obtain a third reference relationship based on the first sub-object and the second sub-object.

[0139] The third reference relationship can represent that the first sub-object holds the second sub-object, that is, a directed reference edge from the first sub-object belonging to the second runtime environment to the second sub-object belonging to the second runtime environment.

[0140] If the first runtime environment is an Objective-C environment and the first object is an Objective-C object, and the second runtime environment is a KMP environment and the second object is a KMP object, then the third reference relationship can be characterized as: a KMP object holds a reference to another KMP object.

[0141] In C3 above, there is a reference relationship between the first sub-object corresponding to the third memory address and the second sub-object corresponding to the fourth memory address. Therefore, we can subsequently obtain the addresses of the two objects in the reference relationship between the first sub-object and the second sub-object. This leads to the reference relationship between one KMP object and another KMP object.

[0142] C4 obtains the third reference relationship, which can be understood as obtaining the reference relationship between the first and second child objects based on the reference path between the first and second child objects.

[0143] By performing streaming parsing on the first data, identifying fourth-type identifiers such as TAG_TYPE, TAG_OBJECT, and TAG_ARRAY, it is possible to extract object node addresses and reference target addresses from metadata that originally did not contain a reference relationship graph. This provides the address data foundation for subsequently constructing the reference relationship within the KMP environment, thereby making up for the deficiency of existing KMP Dumps in providing a reference relationship graph and providing internal reference chain data support from the KMP side for the complete detection of cross-environment circular references.

[0144] In actual parsing, different types of fourth-type identifiers carry different information. Therefore, a fourth-type identifier can include a first subtype identifier and a second subtype identifier, and a second data segment can include a first sub-data segment and a second sub-data segment. The first sub-data segment can represent a data segment with a first subtype identifier, and the second sub-data segment can represent a data segment with a second subtype identifier.

[0145] The first subtype identifier can be one of the fourth type identifiers, used to mark the data segment storing KMP object node information and reference relationship information. For example, the first subtype identifier may include TAG_OBJECT and TAG_ARRAY, where TAG_OBJECT represents the object node data segment and TAG_ARRAY represents the array node data segment.

[0146] The second subtype identifier can be one of the fourth type identifiers, used to mark the data segment storing KMP object type information. For example, the second subtype identifier can be TAG_TYPE, representing the type information data segment, which contains the correspondence between type identifiers and offsets, etc.

[0147] The first sub-data segment can be a data segment in the first data that has a first subtype identifier, such as the TAG_OBJECT data segment, the TAG_ARRAY data segment, etc. Among them, the TAG_OBJECT data segment can be used to record information about KMP object nodes, and can at least include the object's memory address (obj_id) and type identifier (type_id).

[0148] For example, the layout of the TAG_OBJECT data segment can be shown in Table 1: Table 1

[0149] The second sub-data segment can be a data segment in the first data segment that has a second sub-type identifier, such as the TAG_TYPE data segment, which is used to record the type information of KMP objects, including the correspondence between the type identifier (type_id) and the memory offset (object_offsets) held by the type.

[0150] For example, the layout of the TAG_OBJECT data segment can be shown in Table 2: Table 2

[0151] Based on this, C3 obtains the third and fourth memory addresses according to the second data segment, which may include: C31: Obtain the third memory address based on the first sub-data segment.

[0152] The third memory address can be the memory address (obj_id) of the first sub-object extracted from the first sub-data segment, used to identify the first sub-object that serves as the reference source.

[0153] C31 obtains the third memory address based on the first sub-data segment. This can be understood as extracting the memory address (obj_id) of the object node from the first sub-data segment (TAG_OBJECT data segment) and using that address as the third memory address. This address is used to identify the first child object, i.e., the source object of the reference relationship.

[0154] C32: Obtain the fourth memory address based on the first sub-data segment, the second sub-data segment, and the third memory address.

[0155] The fourth memory address can be used to identify the second child object that is the target of the reference.

[0156] C32 obtains the fourth memory address based on the first sub-data segment, the second sub-data segment, and the third memory address. This can be understood as follows: the type identifier of the first sub-object is determined based on the first sub-data segment; the memory offset corresponding to the type identifier is determined based on the second sub-data segment; and the stored value is read from the corresponding position in the memory of the first sub-object based on the third memory address (the memory address of the first sub-object) and the memory offset, and this value is used as the fourth memory address.

[0157] By distinguishing between the first subtype identifier and the second subtype identifier, the object node address and type offset information are obtained respectively. Then, the reference target address is accurately read from the corresponding position in the memory of the first sub-object. This realizes the classification and extraction of reference source address and reference target address from KMP Dump data, providing a data foundation for the subsequent construction of reference relationships within the KMP environment, thereby making up for the deficiency of existing KMP Dump in not being able to provide a reference relationship graph.

[0158] To more clearly describe the process of obtaining the fourth memory address, C32 obtains the fourth memory address based on the first sub-data segment, the second sub-data segment, and the third memory address, which may include: C321: Determine the memory offset based on the second sub-data segment.

[0159] Memory offsets can be used to represent the byte offset of the position of the first child object holding a reference field in its memory layout relative to the object's starting address.

[0160] C321 determines the memory offset based on the second sub-data segment. This can be understood as searching for the corresponding type information in the second sub-data segment (TAG_TYPE data segment) based on the type identifier of the first sub-object, and determining the memory offset (object_offsets) of the reference held by that type. This offset represents the position of the referenced field in the memory layout of the first sub-object.

[0161] C322: Obtain the fourth memory address based on the memory offset and the third memory address.

[0162] This can be understood as follows: based on the memory offset determined by C321 and the third memory address (the starting address of the first sub-object) already obtained in C31, the specific memory location (i.e., the third memory address + memory offset) holding the reference field in the first sub-object is calculated. Then, the value stored at that location is read and used as the fourth memory address. This address is used to identify the second sub-object, i.e., the target object of the reference relationship.

[0163] For example, based on the first sub-data segment, we know that the address of object A is 0x1000 and its type identifier is 100; based on the TAG_TYPE data in the second sub-data segment, we find that this type holds a reference at memory offset 16 by querying type_id=100; we read the value stored at memory address 0x1000 of object A plus memory offset 16 (i.e., address 0x1010) to get 0x2000; we use 0x2000 as the fourth memory address to identify the second sub-object (object B).

[0164] By obtaining the offset information corresponding to the type through the second sub-data segment (TAG_TYPE) and combining it with the address of the first sub-object obtained in C31, the reference target address is accurately located and read. This avoids the large amount of redundant data required to directly store the reference relationship, and realizes the address extraction of the internal reference relationship of the KMP environment with a small metadata overhead, providing an efficient and accurate data foundation for the subsequent construction of the KMP memory reference relationship graph.

[0165] Circular references across environments can prevent a large number of objects from being released, causing application memory usage to gradually increase. If left unchecked, this will eventually lead to a memory leak. To avoid this, a safety threshold can be set in advance, allowing for early intervention before memory usage approaches a dangerous level, thus preventing the risk of memory leaks.

[0166] In the case where the first runtime environment may include a platform-specific development environment (such as an Objective-C environment), and the corresponding second runtime environment may include a cross-platform shared logic environment (such as a KMP environment), the reference relationship may include a fourth reference relationship representing that one first object holds another first object.

[0167] To obtain the reference relationships between multiple Objective-C objects in an Objective-C environment, the first runtime environment may include the Objective-C environment, and the first object may include a third sub-object and a fourth sub-object; the first object is an Objective-C object, and the third and fourth sub-objects are also Objective-C objects. The third sub-object can be an Objective-C sub-object of the first object (Objective-C object), serving as the source node of the reference relationship, and the fourth sub-object can be the target Objective-C object referenced by the third sub-object, serving as the target node of the reference relationship.

[0168] In one scenario, S201 obtaining a reference relationship may include: D1: Get the first data.

[0169] The first data can represent the memory data of the first object.

[0170] The first data can refer to data used to describe the state, attributes, or structure of the first object in memory, such as the memory address, member variable information, or memory snapshot of the first object.

[0171] For example, if the first runtime environment is an Objective-C environment, the first data can be memory snapshot data of the Objective-C object, which contains memory layout information of the Objective-C object, such as the offset of instance variables (Ivar), property names, property codes, and the contents of reference storage structures (such as refHolder).

[0172] D1 obtaining the first data can be understood as acquiring the memory data of the first object belonging to the first runtime environment. The first data can provide a foundation for the subsequent identification of objects across environments.

[0173] D2: Obtain the third data segment.

[0174] The third data segment can be a data segment representing the first data segment that has a fifth type identifier. This fifth type identifier can be a specific type identifier field applied within the Objective-C environment, used to mark data segments storing reference relationships between Objective-C objects in the object's memory data.

[0175] For example, the fifth type of identifier may include property information, instance variable information, or associated object information in the Objective-C runtime, used to identify that an Objective-C object holds references to other Objective-C objects.

[0176] D3: Based on the third data segment, obtain the fifth memory address and the sixth memory address.

[0177] The fifth memory address can be used to identify the third sub-object, and the sixth memory address can be used to identify the fourth sub-object. Specifically, the fifth memory address can be the memory address of the third sub-object extracted from the third data segment, used to identify the third sub-object that serves as the source of the reference; the sixth memory address can be the memory address of the fourth sub-object extracted from the third data segment, used to identify the fourth sub-object that serves as the target of the reference, representing the target Objective-C object referenced by the third sub-object.

[0178] D4: Based on the third sub-object and the fourth sub-object, obtain the fourth reference relationship.

[0179] The fourth reference relationship can represent a directed reference edge from a third sub-object to a fourth sub-object belonging to the first runtime environment.

[0180] If the first runtime environment is an Objective-C environment and the first object is an Objective-C object, and the second runtime environment is a KMP environment and the second object is a KMP object, then the fourth reference relationship can be characterized as: an Objective-C object holds a reference to another Objective-C object.

[0181] In D3 above, there is a reference relationship between the third sub-object corresponding to the fifth memory address and the fourth sub-object corresponding to the sixth memory address. Therefore, we can subsequently obtain the addresses of the two objects in the reference relationship between the third sub-object and the fourth sub-object. Furthermore, we can obtain a reference relationship between one Objective-C object and another Objective-C object.

[0182] D4 obtains the fourth reference relationship, which can be understood as obtaining the reference relationship between the third and fourth sub-objects based on the reference path between the third and fourth sub-objects.

[0183] In another scenario, a memory detection tool may be used to obtain a reference relationship graph between OC objects, and other reference relationships are superimposed on the basis of this graph to obtain a global reference relationship graph.

[0184] By supplementing the reference relationships inside the OC environment, the finally constructed global reference relationships include not only cross-environment references but also object references inside the OC environment, thereby improving the completeness of the reference relationships and providing a more complete data basis for comprehensive detection of cross-environment circular references.

[0185] Based on this, the above memory leak detection method may further comprise: In response to the current memory usage exceeding a preset threshold, acquiring first data.

[0186] The current memory usage may refer to the actual memory size occupied by the application program during current operation, which may be acquired in real time through a system interface or a memory detection tool.

[0187] The preset threshold may be a pre-set safety threshold for memory usage, configured to determine whether the current memory usage is close to a dangerous level. The preset threshold may be configured according to the actual operation situation of the application program and the memory capacity of the device, for example, set to 80% of the total memory of the device or 70% of the maximum available memory of the application program.

[0188] The current memory usage of the application program is detected in real time, and when it is detected that the current memory usage exceeds the pre-set safety threshold, the memory leak detection process is automatically triggered to acquire the first data. The first data will be used as an input for subsequent steps, for analyzing whether a cross-environment circular reference exists.

[0189] Triggering only when the memory usage reaches the preset safety threshold can not only discover potential memory leak risks in time, but also avoid performance overhead caused by frequent detection. Meanwhile, since the threshold is pre-set, intervention can be performed in advance before the memory usage reaches the dangerous level, so as to play a preventive role. In one scenario, the acquired first data may be used when the application program starts next time, that is, subsequent steps A2 to A3 are executed at the next startup. Specifically, when the application program is started for the second time, the saved first data is read, subsequent steps such as A2 to A3 are executed to analyze whether a cross-environment circular reference exists therein, and cache objects that may cause memory leaks are released before the application is started based on the analysis result, so as to prevent memory leak risks in advance.

[0190] In other scenarios, acquiring the first data may also be performed at preset time intervals, for example, every 5 minutes.

[0191] In another scenario, the above memory leak detection method may further comprise: In response to the current memory usage exceeding a preset threshold, second data is retrieved.

[0192] The preset threshold can be a pre-set safe threshold for memory usage, used to determine whether the current memory usage is approaching a dangerous level. The preset threshold can be configured according to the actual running status of the application and the device's memory capacity, for example, set to 80% of the device's total memory or 70% of the application's maximum available memory.

[0193] By repeatedly executing the above steps, we can obtain reference relationships between Objective-C objects, including one Objective-C object pointing to another, one Objective-C object pointing to a KMP object, one KMP object pointing to another, and one KMP object pointing to an Objective-C object. Based on these cross-environment and intra-environment reference relationships, a global reference graph encompassing both Objective-C and KMP environments can be constructed. This graph fully reflects the reference chains between all objects in the application, providing a data foundation for comprehensive detection of cross-environment circular references.

[0194] For example, Figure 3 A global reference graph is provided, in which there are KMP object 1 and KMP object 0 in the KMP environment, and OC object 1 and OC object 0 in the OC environment. KMP object 1 points to OC object 1, OC object 1 points to OC object 0, OC object 0 points to KMP object 0, and KMP object 0 points to KMP object 1, forming a circular reference relationship.

[0195] After obtaining the reference relationship between the first and second objects, if the reference relationship is a two-way reference, it indicates a risk of a cross-environment circular reference. To help developers intuitively locate the root cause of the problem, the above memory leak detection method may also include: E1: Obtain the circular reference ring.

[0196] A circular reference ring is obtained based on reference relationships. A circular reference ring represents a circular reference path formed between a first object and a second object.

[0197] Based on one or more existing reference relationships, determine whether a circular reference path exists. A circular reference cycle is not limited to a bidirectional reference between two cross-environment objects; it can also include a closed reference loop formed by three or more cross-environment objects. For example, object ① points to object ②, object ② points to object ③, and object ③ points to object ①, thus forming a circular reference cycle. A complete circular reference cycle can be generated based on these reference relationships, recording the name, memory address, runtime environment, and reference paths between each object in the cycle.

[0198] E2: Displays a circular reference ring.

[0199] Display the circular reference rings obtained by E1 in a developer-readable format. For example, output the circular reference rings to a log file, print them to the console, display the reference chain diagram graphically, or generate a memory leak analysis report. By displaying the circular reference rings, developers can visually understand which objects form circular references, thus quickly locating the root cause of the problem and fixing it.

[0200] For example, a circular reference cycle with both a first object and a second object is highlighted in the reference graph for easy viewing by users or developers.

[0201] A circular reference loop can comprehensively record multiple objects involved in cross-environment circular references and their reference paths, intuitively demonstrating the closed reference loop formed between the Objective-C and KMP environments. By displaying the circular reference loop in the form of logs, console commands, graphical interfaces, or analysis reports, developers can clearly understand the full picture of cross-environment circular references, quickly locate the root cause of circular references between Objective-C and KMP objects, and thus effectively improve the efficiency of troubleshooting and fixing cross-environment memory leak problems.

[0202] In one scenario, the reference graph can be traversed using algorithms such as Depth-First Search (DFS), Breadth-First Search (BFS), and Tarjan's strongly connected component algorithm to find memory nodes with circular references. Circular reference cycles containing both Objective-C and KMP objects can then be selected for display. To further ensure the consistency and accuracy of the initial data collection, the aforementioned memory leak detection method may also include: F1: Determine the first thread, which is used to acquire the first data.

[0203] F2: Obtain first data through the first thread while the second thread is suspended, where the second thread represents a thread other than the first thread in the application in which the first thread resides.

[0204] The first thread represents the thread used to perform memory data acquisition and is responsible for obtaining the first data. The first thread can be determined when the application starts or specified when memory detection is triggered.

[0205] The second thread can be any thread in the application other than the first thread. These threads may modify the memory state during memory data acquisition, affecting data consistency.

[0206] With the second thread already suspended, the first thread retrieves the first data. Because the second thread is suspended, it cannot modify the memory state during data acquisition, thus ensuring the consistency and accuracy of the first data.

[0207] In one embodiment, see Figure 4 Memory leak detection methods may include: S401: Current memory usage exceeds the preset threshold.

[0208] S402: Suspend the second thread.

[0209] S403: Obtain the first data through the first thread.

[0210] S404: Obtain the reference relationship between the OC object and the KMP object.

[0211] S405: Obtain the reference relationship between OC objects.

[0212] S406: The application is launched for the second time.

[0213] S407: Obtain the reference relationship between KMP objects and other KMP objects.

[0214] S408: Obtain the reference relationship between the KMP object and the OC object.

[0215] S409: Obtain the global reference graph.

[0216] S410: Get and display the circular reference relationship ring.

[0217] It should be noted that the specific implementation process of steps S401 to S410 can be found in the description of the above steps, and will not be repeated here in this embodiment. Among them, S401 to S405 can be implemented on the terminal device, and S406 to S410 can be implemented on the terminal device or on the server.

[0218] Using the memory leak detection methods described above, when memory leaks caused by circular references between Objective-C and KMP occur online, a global reference graph can be quickly constructed to find the circular reference loops holding Objective-C and KMP objects, helping developers to quickly locate and fix the problem.

[0219] Figure 5 This is a schematic diagram illustrating the structure of a memory leak detection device based on certain scenarios. Please refer to [link / reference]. Figure 5 The memory leak detection device 500 may include: The first obtaining module 501 is used to obtain reference relationships, wherein the reference relationships represent reference paths between objects in an object set, the object set includes a first object and a second object, the first object belongs to a first runtime environment, and the second object belongs to a second runtime environment; The second obtaining module 502 is used to obtain the detection result, which is obtained by memory leak detection based on the reference relationship.

[0220] In some cases, the first obtaining module 501 includes: The first sub-acquisition module is used to acquire first data, which represents the memory data of the first object; The second sub-acquisition module is used to obtain the second object based on the first data; The third sub-acquisition module is used to obtain a first reference relationship based on the first object and the second object, wherein the first reference relationship indicates that the first object holds the second object.

[0221] In some cases, the second sub-acquisition module includes: A first processing unit is configured to obtain a reference storage structure, the reference storage structure being obtained based on the first data; The second processing unit is used to obtain a first memory address, which is obtained based on the type identifier of the reference storage structure, and the first memory address is used to identify the second object.

[0222] In some cases, the first processing unit is specifically used for: Traverse the instance variables in the first data to obtain location information, which is used to characterize the location of the instance variables; Based on the location information of the instance variable, the reference storage structure is obtained.

[0223] In some cases, the second processing unit is specifically used for: Obtain the first stored value, which represents the pointer value stored in the reference storage structure; When the type identifier of the referenced storage structure is a first type identifier, the first storage value is used as the first memory address; If the type identifier of the referenced storage structure is a second type identifier, obtain the memory address corresponding to the first storage value and use the memory address as the first memory address.

[0224] In some cases, the first obtaining module 501 includes: The fourth sub-acquisition module is used to acquire second data, which represents the memory data of the second object; The fifth sub-module is used to obtain the first object based on the second data; The sixth sub-module is used to obtain a second reference relationship based on the first object and the second object, wherein the second reference relationship indicates that the second object holds the first object.

[0225] In some cases, the fifth sub-acquisition module includes: The third processing unit is used to obtain a first data segment, wherein the first data segment represents a data segment in the second data that has a third type identifier; The fourth processing unit is configured to obtain a second memory address based on the first data segment, wherein the second memory address is used to identify the first object.

[0226] In some cases, the second object includes a first sub-object and a second sub-object; the first obtaining module 501 includes: The seventh sub-module is used to obtain second data, which represents the memory data of the second object. The eighth sub-module is used to obtain a second data segment, which represents a data segment in the second data that has a fourth type identifier; The ninth sub-object acquisition module is used to obtain a third memory address and a fourth memory address based on the second data segment, wherein the third memory address is used to identify the first sub-object and the fourth memory address is used to identify the second sub-object; The tenth sub-object acquisition module is used to obtain a third reference relationship based on the first sub-object and the second sub-object, wherein the third reference relationship indicates that the first sub-object holds the second sub-object.

[0227] In some cases, the fourth type identifier includes a first subtype identifier and a second subtype identifier, and the second data segment includes a first subdata segment and a second subdata segment, wherein the first subdata segment represents a data segment having a first subtype identifier and the second subdata segment represents a data segment having a second subtype identifier; The ninth sub-acquisition module includes: The fifth processing unit is used to obtain the third memory address based on the first sub-data segment; The sixth processing unit is used to obtain the fourth memory address based on the first sub-data segment, the second sub-data segment, and the third memory address.

[0228] In some cases, the memory leak detection device 500 may further include: The acquisition module is used to acquire the first data in response to the current memory usage exceeding a preset threshold.

[0229] In some cases, the memory leak detection device 500 may further include: The third obtaining module is used to obtain a circular reference ring, which is obtained based on the reference relationship, and the circular reference ring represents the circular reference path formed between the first object and the second object; The display module is used to display the circular reference ring.

[0230] The method logic executed by each functional module of the aforementioned memory leak detection device has been explained in detail in the section on memory leak detection methods, and will not be repeated here.

[0231] Based on the same concept, this technical solution also provides a computer-readable medium having a computer program stored thereon, wherein the computer program, when executed by a processing device, implements the steps of any of the above-described memory leak detection methods.

[0232] Based on the same concept, this technical solution also provides an electronic device, which may include: A storage device on which computer programs are stored; A processing device for executing the computer program in the storage device to implement the steps of any of the memory leak detection methods described above.

[0233] Based on the same concept, this technical solution also provides a computer program product, including a computer program, wherein when the computer program is executed by a processor, it implements the steps of any of the above-described memory leak detection methods.

[0234] The following is for reference. Figure 6 It shows an electronic device suitable for implementing the above-mentioned technical solution (e.g. Figure 1 The diagram below shows the structure of the terminal device or server 600. The terminal device may include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Tablet Personal Computers), PMPs (Portable Media Players), in-vehicle terminals (such as in-vehicle navigation terminals), and fixed terminals such as digital TVs (Televisions), desktop computers, etc. Figure 6 The electronic device shown is merely an example and should not be construed as limiting its functionality or scope of use.

[0235] like Figure 6As shown, electronic device 600 may include a processing unit (e.g., a central processing unit, a graphics processing unit, etc.) 601, which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 602 or a program loaded from storage device 608 into random access memory (RAM) 603. The random access memory 603 also stores various programs and data required for the operation of electronic device 600. The processing unit 601, ROM 602, and RAM 603 are interconnected via bus 604. An input / output (I / O) interface 605 is also connected to bus 604.

[0236] Typically, the following devices can be connected to the input / output interface 605: input devices 606 including, for example, a touchscreen, touchpad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; output devices 607 including, for example, a liquid crystal display (LCD), speaker, vibrator, etc.; storage devices 608 including, for example, magnetic tape, hard disk, etc.; and communication devices 609. Communication device 609 allows electronic device 600 to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 6 An electronic device 600 with various devices is shown; however, it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed alternatively.

[0237] In particular, depending on certain circumstances, the processes described in the flowchart above can be implemented as computer software programs. For example, a computer program product is provided, comprising a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for performing the methods shown in the flowchart. This computer program can be downloaded and installed from a network via communication device 609, or installed from storage device 608, or installed from read-only memory 602. When the computer program is executed by processing device 601, it performs the functions defined in the above-described methods.

[0238] It should be noted that the aforementioned computer-readable medium may be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium may be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM, or flash memory), optical fiber, portable compact disc read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In one case, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In another case, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. The transmitted data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. The computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (Radio Frequency), etc., or any suitable combination thereof.

[0239] In some implementations, clients and servers can communicate using any currently known or future-developed network protocol, such as HTTP (Hypertext Transfer Protocol), and can interconnect with digital data communication (e.g., communication networks) of any form or medium. Examples of communication networks include local area networks (LANs), wide area networks (WANs), the internet (e.g., the Internet), and peer-to-peer networks (e.g., ad-hoc peer-to-peer networks), as well as any currently known or future-developed networks.

[0240] The aforementioned computer-readable medium may be included in the aforementioned electronic device; or it may exist independently and not assembled into the electronic device.

[0241] The aforementioned computer-readable medium carries one or more programs that, when executed by the electronic device, cause the electronic device to: obtain reference relationships, wherein the reference relationships characterize reference paths between objects in a set of objects, the set of objects including a first object and a second object, the first object belonging to a first runtime environment and the second object belonging to a second runtime environment; and obtain detection results, wherein the detection results are obtained by performing memory leak detection based on the reference relationships. Computer program code for performing the above operations can be written in one or more programming languages ​​or a combination thereof, including but not limited to object-oriented programming languages, as well as conventional procedural programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0242] The flowcharts and block diagrams in the accompanying figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products under various scenarios. In this respect, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the figures. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0243] The modules mentioned above can be implemented in software or hardware. In some cases, the name of a module does not necessarily limit the functionality of that module.

[0244] The functions described above can be performed, at least in part, by one or more hardware logic components. For example, exemplary types of hardware logic components that can be used, without limitation, include: Field-Programmable Gate Arrays (FPGAs), Application-Specific Integrated Circuits (ASICs), Application-Specific Standard Parts (ASSPs), Systems on Chips (SoCs), Complex Programmable Logic Devices (CPLDs), and so on.

[0245] In this context, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0246] The above description is merely illustrative and explains the technical principles employed. Those skilled in the art should understand that the scope of the technical solution is not limited to specific combinations of the above-described technical features, but also includes other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above concept. For example, technical solutions formed by substituting the above-described features with (but not limited to) technical features provided herein that have similar functions.

[0247] Furthermore, while the operations are described in a specific order, this should not be construed as requiring these operations to be performed in the specific order shown or in a sequential order. Multitasking and parallel processing may be advantageous in certain environments. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limitations on the scope of the technical solution. Certain features described in the context of a single example can also be implemented in combination in a single example. Conversely, various features described in the context of a single example can also be implemented individually or in any suitable sub-combination in multiple examples.

[0248] Although the technical solution has been described using language specific to structural features and / or methodological logic, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. Rather, the specific features and actions described above are merely illustrative examples of implementing the claims. Regarding the aforementioned apparatus, the specific manner in which each module performs its operation has already been described in detail in the section concerning the method, and will not be elaborated upon here.

Claims

1. A method for detecting memory leaks, comprising: Obtain reference relationships, which represent reference paths between objects in an object set, the object set including a first object and a second object, the first object belonging to a first runtime environment, and the second object belonging to a second runtime environment; The detection results are obtained based on the reference relationship to detect memory leaks.

2. The method according to claim 1, wherein obtaining the reference relationship includes: Obtain first data, which represents the memory data of the first object; Based on the first data, the second object is obtained; Based on the first object and the second object, a first reference relationship is obtained, wherein the first reference relationship indicates that the first object holds the second object.

3. The method according to claim 2, wherein obtaining the second object based on the first data comprises: Obtain a reference storage structure, which is obtained based on the first data; A first memory address is obtained, which is based on the type identifier of the reference storage structure and is used to identify the second object.

4. The method according to claim 3, wherein obtaining the reference storage structure comprises: Traverse the instance variables in the first data to obtain location information, which is used to characterize the location of the instance variables; Based on the location information of the instance variable, a reference storage structure is obtained.

5. The method according to claim 3, wherein obtaining the first memory address comprises: Obtain the first stored value, which represents the pointer value stored in the reference storage structure; When the type identifier of the referenced storage structure is a first type identifier, the first storage value is used as the first memory address; If the type identifier of the referenced storage structure is a second type identifier, obtain the memory address corresponding to the first storage value and use the memory address as the first memory address.

6. The method according to claim 1, wherein obtaining the reference relationship includes: Obtain second data, which represents the memory data of the second object; Based on the second data, the first object is obtained; Based on the first object and the second object, a second reference relationship is obtained, which indicates that the second object holds the first object.

7. The method according to claim 6, wherein obtaining the first object based on the second data comprises: Obtain a first data segment, which represents a data segment in the second data that has a third type identifier; Based on the first data segment, a second memory address is obtained, which is used to identify the first object.

8. The method according to claim 1, wherein the second object comprises a first sub-object and a second sub-object; The process of obtaining the reference relationship includes: Obtain second data, which represents the memory data of the second object; Obtain a second data segment, which represents a data segment in the second data that has a fourth type identifier; Based on the second data segment, a third memory address and a fourth memory address are obtained, wherein the third memory address is used to identify the first sub-object and the fourth memory address is used to identify the second sub-object; Based on the first sub-object and the second sub-object, a third reference relationship is obtained, wherein the third reference relationship indicates that the first sub-object holds the second sub-object.

9. The method according to claim 8, wherein the fourth type identifier includes a first subtype identifier and a second subtype identifier, the second data segment includes a first subdata segment and a second subdata segment, the first subdata segment represents a data segment having a first subtype identifier, and the second subdata segment represents a data segment having a second subtype identifier; Based on the second data segment, the third and fourth memory addresses are obtained, including: Based on the first sub-data segment, obtain the third memory address; The fourth memory address is obtained based on the first sub-data segment, the second sub-data segment, and the third memory address.

10. The method according to claim 2, further comprising: In response to the current memory usage exceeding a preset threshold, the first data is retrieved.

11. The method according to any one of claims 1-10, wherein the method further comprises: A circular reference ring is obtained, which is based on the reference relationship and represents the circular reference path formed between the first object and the second object; The circular reference ring is shown.

12. A memory leak detection device, comprising: The first obtaining module is used to obtain reference relationships, wherein the reference relationships represent reference paths between objects in an object set, the object set includes a first object and a second object, the first object belongs to a first runtime environment, and the second object belongs to a second runtime environment; The second obtaining module is used to obtain the detection result, which is obtained by memory leak detection based on the reference relationship.

13. A computer-readable medium having a computer program stored thereon, wherein, When the computer program is executed by the processing device, it implements the steps of the memory leak detection method according to any one of claims 1-11.

14. An electronic device comprising: A storage device on which computer programs are stored; A processing device for executing the computer program in the storage device to implement the steps of the memory leak detection method according to any one of claims 1-11.

15. A computer program product comprising a computer program, wherein, When executed by a processor, the computer program implements the steps of the memory leak detection method according to any one of claims 1-11.