Memory leak detection method, device, electronic device, and storage medium

By gradually reading the memory object linked list in multiple frame cycles and combining class information to detect memory leaks, the problem of excessive CPU resource usage in the existing technology is solved, and real-time detection of memory leaks and improved server stability are achieved.

CN119537167BActive Publication Date: 2025-09-30DUOYI NETWORK CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411438599.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-15
Publication Date
2025-09-30
Estimated Expiration
2044-10-15

AI Technical Summary

Technical Problem

Existing technologies consume a large amount of CPU resources when detecting memory leaks, affecting the stability of server operation.

Method used

By gradually reading the memory object list in multiple frame loops, only a certain number of objects are read in each frame loop, and memory leak detection is performed in combination with the object class information to avoid reading all objects at once.

Benefits of technology

It reduces CPU resource usage, avoids interference with server operations, and achieves real-time detection of memory leaks and improved server stability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119537167B_ABST
    Figure CN119537167B_ABST
Patent Text Reader

Abstract

The present application relates to a memory leak detection method, apparatus, electronic device, and storage medium. This method reads objects through multiple frame cycles. Since each frame cycle only reads a certain number of objects, rather than reading all objects in a single frame cycle, it only consumes a small portion of CPU resources, thus avoiding affecting the normal operation of the server and improving the stability of the server. Furthermore, memory leak detection can be completed during the frame cycle without interrupting the program, achieving real-time detection of memory leaks.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a memory leak detection method, device, electronic device and storage medium. Background Art

[0002] A memory leak occurs when a program fails to properly release memory after allocating it, preventing the system from reusing it. This can cause the program to run slowly or even crash. Therefore, it's important to avoid memory leaks to ensure proper program operation.

[0003] In the process of realizing the present invention, the inventors found that in the related art, when performing memory leak detection, a large amount of CPU resources will be consumed, affecting the operation of the server. Summary of the Invention

[0004] Based on this, the purpose of the present invention is to provide a memory leak detection method, device, electronic device and storage medium, which have the advantages of not interfering with server operation and detecting memory leaks in real time.

[0005] According to a first aspect of an embodiment of the present application, a memory leak detection method is provided, comprising the following steps:

[0006] Reading objects in a first memory object linked list loaded in the current frame loop in sequence within the current frame loop, and if the number of objects read within the current frame loop is greater than or equal to a preset number threshold, obtaining class information of the read objects, and stopping reading the first memory object linked list within the current frame loop;

[0007] In a frame loop next to the current frame loop, objects in a second memory object linked list loaded in a frame loop next to the current frame loop are read; if, in a frame loop next to the current frame loop, the number of objects read is greater than or equal to a preset number threshold, but reading of all objects in the second memory object linked list is not completed, in a subsequent frame loop next to the current frame loop, objects in the memory object linked list of the corresponding frame loop are continued to be read until all objects in the corresponding memory object linked list are read; wherein the second memory object linked list is determined based on the first memory object linked list and object change data of the frame loop next to the current frame loop compared to the current frame loop;

[0008] According to the class information of the read objects, determine the number of objects corresponding to each class;

[0009] The number of objects corresponding to each class is arranged from large to small, and a preset number of classes with the highest number of objects are tested for memory leaks to obtain memory leak detection results.

[0010] According to a second aspect of an embodiment of the present application, a memory leak detection device is provided, comprising:

[0011] a class information acquisition module, configured to sequentially read objects in a first memory object linked list loaded in the current frame loop within a current frame loop; if the number of objects read in the current frame loop is greater than or equal to a preset number threshold, acquire class information of the read objects and stop reading the first memory object linked list within the current frame loop;

[0012] An object reading module is configured to read, in a frame cycle next to the current frame cycle, objects in a second memory object linked list loaded in a frame cycle next to the current frame cycle; if, in a frame cycle next to the current frame cycle, the number of objects read is greater than or equal to a preset number threshold, but reading of all objects in the second memory object linked list has not been completed, continue to read objects in the memory object linked list of the corresponding frame cycle in a subsequent frame cycle next to the current frame cycle until all objects in the corresponding memory object linked list are read; wherein the second memory object linked list is determined based on the first memory object linked list and object change data of the frame cycle next to the current frame cycle compared to the current frame cycle;

[0013] An object quantity determination module is used to determine the number of objects corresponding to each class based on the class information of the read objects;

[0014] The memory leak detection result acquisition module is used to arrange the number of objects corresponding to each class from large to small, perform memory leak detection on a preset number of classes with the highest number of objects, and obtain memory leak detection results.

[0015] According to a third aspect of an embodiment of the present application, an electronic device is provided, comprising: a processor and a memory; wherein the memory stores a computer program, and the computer program is suitable for being loaded by the processor and executing any one of the memory leak detection methods described above.

[0016] According to a fourth aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the memory leak detection method as described above is implemented.

[0017] The embodiment of the present application sequentially reads the objects in the first memory object list loaded in the current frame loop in the current frame loop. If the number of objects read in the current frame loop is greater than or equal to a preset number threshold, the class information of the read objects is obtained, and the reading of the first memory object list in the current frame loop is stopped. In the next frame loop of the current frame loop, the objects in the second memory object list loaded in the next frame loop of the current frame loop are read. If in the next frame loop of the current frame loop, the number of objects read is greater than or equal to the preset number threshold, but the reading of all the second memory object lists is not completed, The object is read, and in the subsequent frame loop of the next frame loop of the current frame loop, the object reading of the memory object list of the corresponding frame loop is continued until all the objects in the corresponding memory object list are read; wherein, the second memory object list is determined according to the first memory object list and the object change data of the next frame loop of the current frame loop compared with the current frame loop; according to the class information of the read object, the number of objects corresponding to each class is determined; the number of objects corresponding to each class is arranged from large to small, and the classes with a preset number of objects ranked at the top are subjected to memory leak detection to obtain memory leak detection results. The present application reads the objects through multiple frame loops. Since each frame loop only reads a certain number of objects, instead of reading all objects in one frame loop, it only takes up a very small part of the CPU resources, thus avoiding affecting the normal operation of the server and improving the stability of the server. At the same time, there is no need to interrupt the program, and memory leak detection can be completed during the frame loop, realizing real-time detection of memory leaks.

[0018] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application.

[0019] For better understanding and implementation, the present invention is described in detail below with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] Figure 1 A flowchart of a memory leak detection method provided in one embodiment of the present application;

[0021] Figure 2 A structural block diagram of a memory leak detection device provided in one embodiment of the present application;

[0022] Figure 3 A schematic block diagram of the structure of an electronic device provided in one embodiment of the present application. DETAILED DESCRIPTION

[0023] In order to make the objectives, technical solutions and advantages of the present application clearer, the embodiments of the present application will be described in further detail below with reference to the accompanying drawings.

[0024] It should be clear that the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.

[0025] The terms used in the embodiments of the present application are for the purpose of describing specific embodiments only and are not intended to limit the embodiments of the present application. The singular forms "a," "the," and "the" used in the embodiments of the present application and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.

[0026] When the following description refers to the accompanying drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. On the contrary, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims. In the description of the present application, it should be understood that the terms "first", "second", "third", etc. are only used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence, nor can they be understood as indicating or implying relative importance. For those of ordinary skill in the art, the specific meanings of the above terms in the present application can be understood according to the specific circumstances.

[0027] In this application, unless otherwise specified, "plurality" refers to two or more. "And / or" describes a relationship between associated objects, indicating that three possible relationships exist. For example, "A and / or B" can mean: A exists alone, A and B exist simultaneously, or B exists alone. The character " / " generally indicates that the associated objects are in an "or" relationship.

[0028] The memory leak detection method provided in the embodiments of the present application can be performed by a memory leak detection device. The memory leak detection device can be implemented via software and / or hardware. The memory leak detection device can be composed of two or more physical entities, or a single physical entity. The memory leak detection device can be any electronic device installed with data processing software, such as a computer, mobile phone, tablet, or other smart device.

[0029] In the process of implementing the present invention, the inventors found that in the related art, the objgraph module is used to view the reference relationships between all objects in the program. Due to the large number of objects in the program, viewing the reference relationships between all objects in the program will consume a large amount of CPU resources, resulting in insufficient performance, thereby affecting the normal operation of the server.

[0030] To this end, this application reads all objects through multiple frame loops. Since each frame loop only reads a certain number of objects, rather than reading all objects in a single frame loop, only a small portion of CPU resources is used, avoiding impacting normal server operation and improving server stability. Furthermore, memory leak detection can be completed during the frame loop without interrupting the program, achieving real-time detection of memory leaks.

[0031] See also Figure 1 , which is a flow chart of a memory leak detection method provided by an embodiment of the present application. The memory leak detection method provided by the embodiment of the present application includes the following steps:

[0032] S10: Read the objects in the first memory object linked list loaded in the current frame loop in sequence within the current frame loop. If the number of objects read within the current frame loop is greater than or equal to a preset number threshold, obtain the class information of the read objects and stop reading the first memory object linked list within the current frame loop.

[0033] During the game, the game program runs the entire game logic on the main thread, completing a frame loop. During each frame loop, the game engine processes user input, handles timed events, and performs drawing operations according to the game logic. A frame loop can be considered the process of rendering a single frame of game screen (drawing). Multiple frame loops can execute multiple drawing operations, thus keeping the game going until the game ends.

[0034] The current frame cycle is a frame cycle for which memory leak detection is to be performed.

[0035] The preset number threshold can be manually set according to actual needs. Generally, the preset number threshold is less than the total number of objects in the memory object list. For example, the preset number threshold is 200.

[0036] The memory object linked list is composed of object nodes connected one by one, and each object node stores object information and an address pointing to the next object node.

[0037] Among them, the class is the template of the object, and the object is the specific instance of the class. A class can have multiple objects, but an object can only belong to one class.

[0038] In an embodiment of the present application, the game server will continuously loop after startup. Each frame loop needs to process events such as network requests, timers, and game battles. In the process of processing these events, some objects will apply to occupy memory, and some objects will release memory, so the number of objects recorded in the memory object list will change.

[0039] After processing network requests, timers, game battles and other events in the current frame loop, the game server loads a memory object list (i.e., a first memory object list) and reads objects in the first memory object list. When the number of objects read exceeds a preset threshold, the game server stops reading objects in the first memory object list.

[0040] S20: In the next frame loop of the current frame loop, read the objects in the second memory object linked list loaded in the next frame loop of the current frame loop; if in the next frame loop of the current frame loop, the number of objects read is greater than or equal to the preset number threshold, but the reading of all objects in the second memory object linked list is not completed, in the subsequent frame loop of the next frame loop of the current frame loop, continue to read objects in the memory object linked list of the corresponding frame loop until all objects in the corresponding memory object linked list are read; wherein, the second memory object linked list is determined based on the first memory object linked list and the object change data of the next frame loop of the current frame loop compared with the current frame loop.

[0041] Among them, the second memory object linked list is the memory object linked list loaded in the next frame loop of the current frame loop. Since the network requests, timers, game battles and other events that the game server needs to process may be different in each frame loop, the objects recorded in the second memory object linked list may also be different from the objects recorded in the first memory object linked list. Specifically, the objects recorded in the second memory object linked list are based on the objects recorded in the first memory object linked list. Add or subtract some objects. For example, the number of objects recorded in the first memory object linked list is 1000, and the number of objects recorded in the second memory object linked list is 1010.

[0042] In an embodiment of the present application, only some objects in the first memory object list are read in the current frame loop, and the objects that have not been read in the first memory object list need to be read again in the next frame loop of the current frame loop. In the next frame loop of the current frame loop, the game server also needs to process events such as network requests, timers, and game battles, and will update the first memory object list to the second memory object list. The second memory object list is loaded, and the objects in the second memory object list are read. When the number of objects read exceeds a preset number threshold, the reading of the objects in the second memory object list is stopped. In the subsequent frame loop of the next frame loop of the current frame loop, the above process is repeated until all objects in the corresponding memory object list are read.

[0043] S30: Determine the number of objects corresponding to each class according to the class information of the read objects.

[0044] In the embodiment of the present application, since each object can only belong to one class, different objects may be instantiated from the same class. The number of objects belonging to the same class is counted to obtain the number of objects corresponding to each class.

[0045] S40: Arrange the number of objects corresponding to each class from largest to smallest, perform memory leak detection on a preset number of classes with the largest number of objects, and obtain a memory leak detection result.

[0046] In the embodiment of the present application, considering that memory leaks generally occur in classes that are instantiated more often, the number of objects corresponding to each class is ranked, and memory leak detection is performed on the top-ranked classes to obtain memory leak detection results. For example, class A has 150 objects, class B has 120 objects, and class C has 200 objects. The classes are ranked from high to low based on the number of objects, namely class C, class A, and class B.

[0047] Applying the embodiment of the present application, by sequentially reading the objects in the first memory object linked list loaded in the current frame loop in the current frame loop, if the number of objects read in the current frame loop is greater than or equal to the preset number threshold, obtaining the class information of the read objects, and stopping reading the first memory object linked list in the current frame loop; in the next frame loop of the current frame loop, reading the objects in the second memory object linked list loaded in the next frame loop of the current frame loop, if in the next frame loop of the current frame loop, the number of objects read is greater than or equal to the preset number threshold, but reading the second memory object linked list is not completed. All objects are read, and in the subsequent frame loop of the next frame loop of the current frame loop, the object reading of the memory object list of the corresponding frame loop continues until all objects in the corresponding memory object list are read; wherein, the second memory object list is determined based on the first memory object list and the object change data of the next frame loop of the current frame loop compared with the current frame loop; according to the class information of the read objects, the number of objects corresponding to each class is determined; the number of objects corresponding to each class is arranged from large to small, and a preset number of classes with the highest number of objects are detected for memory leaks to obtain memory leak detection results. The present application reads objects through multiple frame loops. Since each frame loop only reads a certain number of objects, rather than reading all objects in one frame loop, it only takes up a small part of the CPU resources, thus avoiding affecting the normal operation of the server and improving the stability of the server. At the same time, there is no need to interrupt the program, and memory leak detection can be completed during the frame loop, realizing real-time detection of memory leaks.

[0048] In an optional embodiment, step S10 includes steps S11 to S13, which are specifically as follows:

[0049] S11: In the current frame loop, each object node in the first memory object linked list is read one by one to obtain object information stored in the object node.

[0050] In an embodiment of the present application, starting from the first object node in the first memory object linked list, the first object node in the first memory object linked list is read to obtain the object information stored in the first object node. Then, the second object node in the first memory object linked list is read to obtain the object information stored in the second object node. ..., each object node in the first memory object linked list is read one by one to obtain the object information stored in the object node.

[0051] S12: Determine the class information of the object according to the object information.

[0052] The object information includes but is not limited to the object's properties, methods, and class information.

[0053] In the embodiment of the present application, a built-in function can be used to view object information and obtain object class information. Specifically, the built-in function can be a help() function.

[0054] S13: If the number of objects read is greater than or equal to a preset number threshold, stop reading the first memory object linked list in the current frame loop.

[0055] In the embodiment of the present application, a count is performed during the process of reading object nodes, and each time an object node is read, the count value is increased by 1. When the count value exceeds a preset number threshold, reading of the object nodes in the first memory object list in the current frame loop is stopped.

[0056] By reading each object node in the first memory object linked list one by one, the class information of each object that has been read can be automatically and quickly obtained.

[0057] In an optional embodiment, the object information includes attribute information of the object. Step S12 includes step S121, which is as follows:

[0058] S121: Extracting the class information of the object from the attribute information of the object.

[0059] In the embodiment of the present application, the object information stored in the object node includes the object's attribute information. In Python, the class information of each object is stored in a special attribute called __class__, which is a built-in attribute of Python objects and is used to store the class to which the object belongs.

[0060] By getting the __class__ attribute, you can quickly and automatically determine the class of an object.

[0061] In an optional embodiment, the step of determining the second memory object linked list in step S20 based on the first memory object linked list and object change data of the next frame cycle of the current frame cycle compared to the current frame cycle includes steps S21 to S22, which are specifically as follows:

[0062] S21: Obtain object change data of the next frame cycle of the current frame cycle compared with the current frame cycle.

[0063] The object change data includes but is not limited to newly added object information and removed object information.

[0064] In an embodiment of the present application, by obtaining and comparing the object information requesting to occupy memory in the next frame cycle of the current frame cycle and the object information requesting to occupy memory in the previous frame cycle, the object change data of the next frame cycle of the current frame cycle compared with the current frame cycle can be determined.

[0065] S22: updating the object nodes in the first memory object linked list according to the object change data to obtain a second memory object linked list.

[0066] In an embodiment of the present application, when the object change data indicates that an object has been added, a new object node is added after the last object node in the first memory object linked list to generate a second memory object linked list. When the object change data indicates that an object has been removed, the object node corresponding to the object is deleted from the first memory object linked list to generate a second memory object linked list.

[0067] By adding an object node to or reducing an object node in the first memory object linked list, the second memory object linked list can be automatically and quickly obtained.

[0068] In an optional embodiment, in step S20, in the frame cycle next to the current frame cycle, the step of reading the object in the second memory object linked list loaded in the frame cycle next to the current frame cycle includes steps S201 to S203, which are specifically as follows:

[0069] S201: In a frame loop next to the current frame loop, obtain the first position of the last object among the objects read in the current frame loop in the first memory object linked list.

[0070] The first position may be the number of the object node corresponding to the last object among the objects read in the current frame loop in the first memory object linked list.

[0071] In an embodiment of the present application, only some objects in the first memory object linked list are read in the current frame loop, and in the next frame loop of the current frame loop, it is necessary to continue reading the unread objects in the first memory object linked list. To this end, the first position of the last object in the objects read in the current frame loop is obtained in the first memory object linked list.

[0072] S202: Determine the second position of the last object in the second memory object linked list according to the first position of the last object in the first memory object linked list.

[0073] The second position may be the number of the object node corresponding to the last object among the objects read in the current frame loop in the second memory object linked list.

[0074] In an embodiment of the present application, since the second memory object linked list is obtained by updating the first memory object linked list based on object change data, the first memory object linked list includes a plurality of object nodes, each of which has a corresponding number. The second memory object linked list includes all object nodes of the first memory object linked list and newly added object nodes, or the second memory object linked list includes the remaining object nodes in the first memory object linked list except for the reduced object nodes. Therefore, each object node also has a corresponding number, so that the second position of the last object in the second memory object linked list can be determined based on the first position of the last object in the first memory object linked list.

[0075] S203: Read the objects in the second memory object linked list starting from the second position.

[0076] In an embodiment of the present application, reading is started from the object node corresponding to the second position in the second memory object linked list to obtain the object information stored in the object node.

[0077] The second position is determined by the first position, and the object is read from the second position, thereby realizing multiple frame cycle reading of the object, avoiding affecting the normal operation of the server and improving the stability of the server.

[0078] In an optional embodiment, step S40 includes steps S41 to S44, which are specifically as follows:

[0079] S41: Obtain the current version information of the server and the previous version information of the current version.

[0080] In an embodiment of the present application, the current version information and the previous version information of the current version can be found in a configuration file, or in a command line parameter at startup.

[0081] S42: Compare the current version information with the previous version information to determine the modified class.

[0082] In an embodiment of the present application, by comparing the code corresponding to the current version information and the code corresponding to the previous version information, it is determined which classes are modified.

[0083] S43: Match the modified class with a preset number of classes with the largest number of objects to determine a target class; the target class is a class with the same name as the modified class among the preset number of classes with the largest number of objects.

[0084] In an embodiment of the present application, the modified class name is matched one-to-one with a preset number of class names that rank high in terms of the number of objects, and the class with the same matching is determined as the target class.

[0085] S44: Perform memory release detection on each object corresponding to the target class, and determine the object for which memory release is not performed as a memory leak location of the current version of the application.

[0086] In an embodiment of the present application, each object corresponding to the target class is checked to determine whether memory is released for each object, and objects that have not had their memory released are determined as memory leak locations in the current version of the application.

[0087] By matching the modified class and a preset number of classes with the highest number of objects, you can automatically and quickly locate the location of the memory leak.

[0088] In an optional embodiment, the step of performing memory release detection on each object corresponding to the target class in step S44 includes steps S441 to S443, which are specifically as follows:

[0089] S441: Obtain relevant codes of each object corresponding to the target class;

[0090] S442: When the relevant code includes a code for a memory release operation, determining that the object has released the memory;

[0091] S443: When the relevant code does not include a code for a memory release operation, it is determined that the object has not released the memory.

[0092] In the embodiment of the present application, a memory object has specific codes when applying for memory occupation and releasing memory. The relevant codes of each object corresponding to the target class are obtained, and the relevant codes are detected to see whether they contain the code for the memory release operation, so as to determine whether the object releases the memory.

[0093] By detecting whether the relevant code contains the code for memory release operation, you can automatically and quickly determine whether the object has memory released.

[0094] The following are embodiments of the apparatus of the present application, which can be used to perform the content of the method of the present application. For details not disclosed in the embodiments of the apparatus of the present application, please refer to the content of the method in the embodiments of the present application.

[0095] See Figure 2 , which shows a schematic diagram of the structure of the memory leak detection device provided in an embodiment of the present application. The memory leak detection device 5 provided in an embodiment of the present application includes:

[0096] The class information acquisition module 51 is configured to sequentially read objects in the first memory object linked list loaded in the current frame loop within the current frame loop. If the number of objects read in the current frame loop is greater than or equal to a preset number threshold, the class information of the read objects is acquired, and the reading of the first memory object linked list within the current frame loop is stopped.

[0097] The object reading module 52 is configured to read, in a frame cycle next to the current frame cycle, objects in a second memory object linked list loaded in a frame cycle next to the current frame cycle; if, in a frame cycle next to the current frame cycle, the number of objects read is greater than or equal to a preset number threshold, but reading of all objects in the second memory object linked list has not been completed, continue reading objects in the memory object linked list of the corresponding frame cycle in a subsequent frame cycle next to the current frame cycle until all objects in the corresponding memory object linked list are read; wherein the second memory object linked list is determined based on the first memory object linked list and object change data in a frame cycle next to the current frame cycle compared to the current frame cycle;

[0098] An object quantity determination module 53 is configured to determine the number of objects corresponding to each class based on the class information of the read objects;

[0099] The memory leak detection result obtaining module 54 is used to arrange the number of objects corresponding to each class from largest to smallest, perform memory leak detection on a preset number of classes with the highest number of objects, and obtain memory leak detection results.

[0100] Applying the embodiment of the present application, by sequentially reading the objects in the first memory object linked list loaded in the current frame loop in the current frame loop, if the number of objects read in the current frame loop is greater than or equal to the preset number threshold, obtaining the class information of the read objects, and stopping reading the first memory object linked list in the current frame loop; in the next frame loop of the current frame loop, reading the objects in the second memory object linked list loaded in the next frame loop of the current frame loop, if in the next frame loop of the current frame loop, the number of objects read is greater than or equal to the preset number threshold, but the reading of the second memory object linked list is not completed. All objects in the memory object list of the corresponding frame loop are read, and in the subsequent frame loop of the next frame loop of the current frame loop, the object reading of the memory object list of the corresponding frame loop is continued until all objects in the corresponding memory object list are read; wherein, the second memory object list is determined according to the first memory object list and the object change data of the next frame loop of the current frame loop compared with the current frame loop; according to the class information of the read objects, the number of objects corresponding to each class is determined; the number of objects corresponding to each class is arranged from large to small, and a preset number of classes with a high ranking of object numbers are detected for memory leaks to obtain memory leak detection results. The present application reads objects through multiple frame loops. Since each frame loop only reads a certain number of objects instead of reading all objects in one frame loop, it only takes up a very small part of the CPU resources, thus avoiding affecting the normal operation of the server and improving the stability of the server. At the same time, there is no need to interrupt the program, and memory leak detection can be completed during the frame loop, thereby realizing real-time detection of memory leaks.

[0101] The following are device embodiments of the present application, which can be used to perform the content of the method in the embodiment of the present application. For details not disclosed in the device embodiments of the present application, please refer to the content of the method in the embodiment of the present application.

[0102] See also Figure 3 The present application also provides an electronic device 300, which can be specifically a computer, a mobile phone, a tablet computer, a memory leak detection device, etc. In an exemplary embodiment of the present application, the electronic device 300 is a memory leak detection device, which can include: at least one processor 301, at least one memory 302, at least one display, at least one network interface 303, a user interface 304 and at least one communication bus 305.

[0103] The user interface 304 is mainly used to provide an input interface for the user and obtain data input by the user. Optionally, the user interface can also include a standard wired interface or a wireless interface.

[0104] The network interface 303 may optionally include a standard wired interface or a wireless interface (such as a WI-FI interface).

[0105] The communication bus 305 is used to realize the connection and communication between these components.

[0106] The processor 301 may include one or more processing cores. The processor utilizes various interfaces and circuits to connect various components within the electronic device. It executes instructions, programs, code sets, or instruction sets stored in memory, and accesses data stored in memory to perform various functions and process data. Optionally, the processor may be implemented using at least one of the following hardware forms: a digital signal processing (DSP), a field-programmable gate array (FPGA), or a programmable logic array (PLA). The processor may integrate one or a combination of a central processing unit (CPU), a graphics processing unit (GPU), and a modem. The CPU primarily processes the operating system, user interface, and application programs; the GPU is responsible for rendering and drawing content displayed on the display layer; and the modem handles wireless communications. It is understood that the modem may also be implemented as a separate chip, rather than integrated into the processor.

[0107] Among them, the memory 302 may include a random access memory (RAM) or a read-only memory (Read-Only Memory). Optionally, the memory includes a non-transitory computer-readable storage medium. The memory can be used to store instructions, programs, codes, code sets or instruction sets. The memory may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area may store data involved in the above-mentioned various method embodiments, etc. The memory may also be optionally at least one storage device located away from the aforementioned processor. As Figure 3 As shown, the memory as a computer storage medium may include an operating system, a network communication module, a user interface module, and an operating application program.

[0108] The processor can be used to call the application of the memory leak detection method stored in the memory and specifically execute the method steps of the above-mentioned embodiment. The specific execution process can be found in the specific description shown in the embodiment, which will not be repeated here.

[0109] This application also provides a computer-readable storage medium having a computer program stored thereon, with instructions suitable for being loaded by a processor and executing the method steps of the above-described embodiments. The specific execution process can be referred to the specific description of the embodiments and is not described in detail here. The device where the storage medium is located can be a personal computer, laptop computer, smartphone, tablet computer, or other electronic device.

[0110] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to the partial description of the method embodiments. The device embodiments described above are merely illustrative, wherein the components described as separate parts may or may not be physically separated, and the parts shown as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the present application scheme. A person of ordinary skill in the art can understand and implement it without paying any creative work.

[0111] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, the present application may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0112] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 a process or multiple processes and / or boxes Figure 1These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing device to work in a specific way, so that the instructions stored in the computer-readable memory produce a product including an instruction device, which implements the function selected in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 function selected in a box or multiple boxes.

[0113] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 steps for the function selected in a box or multiple boxes.

[0114] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.

[0115] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.

[0116] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can be implemented using any method or technology to store information. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change RAM (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic tape, disk or other magnetic storage devices, or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory media such as modulated data signals and carrier waves.

[0117] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.

[0118] The above are merely embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application should all be included within the scope of the claims of the present application.

Claims

1. A memory leak detection method, characterized in that: The method comprises the following steps: Reading objects in a first memory object linked list loaded in the current frame loop in sequence within the current frame loop, and if the number of objects read in the current frame loop is greater than or equal to a preset number threshold, obtaining class information of the read objects and stopping reading the first memory object linked list within the current frame loop; wherein the frame loop is a complete game logic run by the game program on the main thread; In a frame cycle next to the current frame cycle, objects in a second memory object linked list loaded in a frame cycle next to the current frame cycle are read; if, in a frame cycle next to the current frame cycle, the number of objects read is greater than or equal to a preset number threshold, but reading of all objects in the second memory object linked list is not completed, in a subsequent frame cycle next to the current frame cycle, objects in the memory object linked list of the corresponding frame cycle are continued to be read until all objects in the corresponding memory object linked list are read; wherein, the second memory object linked list is determined based on the first memory object linked list and object change data of the frame cycle next to the current frame cycle compared to the current frame cycle; Determining the number of objects corresponding to each class based on the read class information of the object; The number of objects corresponding to each class is arranged from largest to smallest, and a preset number of classes with the largest number of objects are tested for memory leaks to obtain memory leak detection results.

2. The memory leak detection method according to claim 1, wherein: The step of reading, in a frame cycle next to the current frame cycle, the objects in the second memory object linked list loaded in the frame cycle next to the current frame cycle comprises: In a frame cycle next to the current frame cycle, obtaining a first position in the first memory object linked list of a last object among the objects read in the current frame cycle; Determine, according to a first position of the last object in the first memory object linked list, a second position of the last object in the second memory object linked list; The objects in the second memory object linked list are read starting from the second position.

3. The memory leak detection method according to claim 1, wherein: The step of sequentially reading objects in the first memory object linked list loaded in the current frame loop within the current frame loop, and if the number of objects read in the current frame loop is greater than or equal to a preset number threshold, obtaining class information of the read objects and stopping reading the first memory object linked list in the current frame loop includes: In the current frame loop, each object node in the first memory object linked list is read one by one to obtain object information stored in the object node; Determining class information of the object based on the object information; If the number of objects read is greater than or equal to a preset number threshold, stop reading the first memory object linked list in the current frame cycle.

4. The memory leak detection method according to claim 3, wherein: The object information includes attribute information of the object; The step of determining the class information of the object based on the object information includes: The class information of the object is extracted from the attribute information of the object.

5. The memory leak detection method according to claim 1, wherein: The step of performing memory leak detection on a preset number of classes with the highest number of objects and obtaining memory leak detection results comprises: Get the current version information of the server and the previous version information of the current version; Compare the current version information with the previous version information to determine the modified class; Matching the modified class with a preset number of classes ranked at the top in terms of the number of objects to determine a target class; the target class is a class with the same name as the modified class among the preset number of classes ranked at the top in terms of the number of objects; Memory release detection is performed on each object corresponding to the target class, and objects for which memory release is not performed are determined as memory leak locations of the current version of the application.

6. The memory leak detection method according to claim 5, wherein: The step of performing memory release detection on each object corresponding to the target class includes: Obtain relevant codes of each object corresponding to the target class; When the relevant code includes a code for a memory release operation, determining that the object has released memory; When the relevant code does not include a code for a memory release operation, it is determined that the object has not released memory.

7. The memory leak detection method according to any one of claims 1 to 6, characterized in that: The step of determining the second memory object linked list according to the first memory object linked list and object change data of a next frame cycle of the current frame cycle compared with the current frame cycle includes: Obtain object change data for a next frame cycle of the current frame cycle compared to the current frame cycle; According to the object change data, the object nodes in the first memory object linked list are updated to obtain the second memory object linked list.

8. A memory leak detection device, characterized in that: include: A class information acquisition module is configured to sequentially read objects in a first memory object linked list loaded in the current frame loop within a current frame loop, and if the number of objects read in the current frame loop is greater than or equal to a preset number threshold, obtain class information of the read objects and stop reading the first memory object linked list within the current frame loop; wherein the frame loop is a complete game logic run by the game program on the main thread; An object reading module is configured to read, in a frame cycle next to the current frame cycle, objects in a second memory object linked list loaded in a frame cycle next to the current frame cycle; if, in a frame cycle next to the current frame cycle, the number of objects read is greater than or equal to a preset number threshold, but reading of all objects in the second memory object linked list is not completed, continue to read objects in the memory object linked list of the corresponding frame cycle in a subsequent frame cycle next to the current frame cycle until all objects in the corresponding memory object linked list are read; wherein, the second memory object linked list is determined based on the first memory object linked list and object change data of the frame cycle next to the current frame cycle compared with the current frame cycle; An object quantity determination module, configured to determine the number of objects corresponding to each class based on the class information of the objects that have been read; The memory leak detection result obtaining module is used to arrange the number of objects corresponding to each class from large to small, perform memory leak detection on a preset number of classes with the highest number of objects, and obtain memory leak detection results.

9. An electronic device, characterized in that: include: A processor and a memory; wherein the memory stores a computer program, and the computer program is suitable for being loaded by the processor and executing the memory leak detection method according to any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the memory leak detection method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Information processing method and information processing device

    CN104778087A

  • Memory leak determination method and device, storage medium and electronic equipment

    CN117743151A