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

By gradually reading objects in the memory object linked list in multiple frame loops, the problem of memory leak detection in the prior art consumes a large amount of CPU resources, real-time detection of memory leaks and improving server stability is achieved.

CN119537167AActive Publication Date: 2025-02-28DUOYI NETWORK CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

When performing memory leak detection, the existing technology consumes a large amount of CPU resources and affects the operation of the server.

Method used

By reading the objects in the memory object linked list in multiple frame loops, obtaining the object's class information, and continuing to read the unfinished objects in subsequent frame loops until the complete objects are read, determining the number of objects in each class, and performing memory leak detection.

Benefits of technology

This method only occupies a small part of the CPU resources, avoids affecting the normal operation of the server, improves the stability of the server, and realizes real-time detection of memory leaks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 00000000_0000_ABST
    Figure 00000000_0000_ABST
Patent Text Reader

Abstract

The invention relates to a memory leak detection method and device, electronic equipment and a storage medium, and the method completes the reading of an object through multiple frame cycles, only a certain number of objects are read in each frame cycle instead of reading all objects in one frame cycle, and only a small part of CPU resources are occupied, thereby avoiding the influence on the normal operation of a server, and improving the reliability of the memory leak detection. And the stability of the server is improved. Meanwhile, the program does not need to be interrupted, memory leak detection can be completed in the frame cycle period, and real-time detection of memory leak is achieved.
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 equipment and storage medium. Background Art

[0002] Memory leak refers to a situation where a program does not release memory correctly after applying for it, causing the system to be unable to use the memory again. This situation may cause the program to run slowly or even crash. Therefore, you should pay attention to avoid memory leaks to ensure the normal operation of the program.

[0003] In the process of implementing the present invention, the inventor discovered 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] Read the objects in the first memory object linked list loaded in the current frame loop in sequence in 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, obtain class information of the read objects, and stop reading the first memory object linked list in 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 continue 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 next frame loop of 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 is used to sequentially read objects in a first memory object linked list loaded in a current frame loop in 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 in the current frame loop;

[0012] An object reading module is used to read objects in a second memory object linked list loaded in a frame cycle next to the current frame cycle in a frame cycle next to the current frame cycle; if the number of objects read in the frame cycle next to the current frame cycle is greater than or equal to a preset number threshold, but the reading of all objects in the second memory object linked list has not been completed, in a subsequent frame cycle of the frame cycle next to the current frame cycle, continue to read objects in the memory object linked list of the corresponding 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;

[0013] An object quantity determination module, used to determine the number of objects corresponding to each class according to 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, there is provided an electronic device, 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 a memory leak detection method such as any one of the 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 objects in a 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 a preset number threshold, class information of the read objects is obtained, and reading of the first memory object linked list in the current frame loop is stopped. In the next frame loop of the current frame loop, objects in a second memory object linked 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 reading of all objects in the second memory object linked list is not completed, The object is read, and in the subsequent frame cycle of the next frame cycle of the current frame cycle, the memory object linked list of the corresponding frame cycle continues to read the object until all the objects in the corresponding memory object linked list are read; wherein, the second memory object linked list is determined according to the first memory object linked list and the object change data of the next frame cycle of the current frame cycle compared with the current frame cycle; 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 the memory leak detection result. The present application reads the objects through multiple frame cycles. Since each frame cycle only reads a certain number of objects instead of reading all the objects in one frame cycle, only a small part of the CPU resources is occupied, which avoids affecting the normal operation of the server and improves 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 cycle, 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 by an embodiment of the present application;

[0021] Figure 2 A structural block diagram of a memory leak detection device provided by an 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 more clear, the embodiments of the present application will be further described in detail below with reference to the accompanying drawings.

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

[0025] The terms used in the embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to limit the embodiments of the present application. The singular forms of "a", "said" 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 other meanings. 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 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 attached 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 do not have to be 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 addition, in the description of this application, unless otherwise specified, "plurality" means two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and 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 executed by a memory leak detection device, which can be implemented by software and / or hardware, and can be composed of two or more physical entities or one physical entity. The memory leak detection device can be any electronic device installed with data processing software, and the electronic device can be a computer, a mobile phone, a tablet or other smart device.

[0029] In the process of implementing the present invention, the inventor discovered that in the related art, the objgraph module is used to view the reference relationship between all objects in the program. Due to the large number of objects in the program, viewing the reference relationship between all objects in the program will consume a large amount of CPU resources and cause performance problems, thereby affecting the normal operation of the server.

[0030] To this end, the present application reads all objects through multiple frame cycles. Since each frame cycle only reads a certain number of objects, rather than reading all objects in one frame cycle, only a small portion of CPU resources is occupied, thus avoiding affecting the normal operation of the server and improving the stability of the server. At the same time, memory leak detection can be completed during the frame cycle without interrupting the program, thus 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 comprises the following steps:

[0032] S10: Read the objects in the first memory object linked list loaded in the current frame loop in sequence 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, obtain the class information of the read objects and stop reading the first memory object linked list in the current frame loop.

[0033] Among them, during the game running process, the game program runs a complete game logic on the main thread, which is called completing a frame cycle. In each frame cycle, the game engine can process a series of operations such as user input, timed events, and drawing according to the game logic rules. A frame cycle can be regarded as the process of rendering a frame of game screen (drawing). Multiple frame cycles can perform multiple drawing operations to keep 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 quantity threshold can be manually set according to actual needs. Generally, the preset quantity threshold is less than the total number of objects in the memory object list. For example, the preset quantity 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 loop continuously after startup, and 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 linked list is changing.

[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 number 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 a 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 cycle of the current frame cycle. Since the network requests, timers, game battles and other events that the game server needs to process may be different in each frame cycle, 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 linked list are read in the current frame loop, and the objects that have not been read in the first memory object linked list need to continue to be read 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 linked list to the second memory object linked list. The second memory object linked list is loaded, and the objects in the second memory object linked list are read. When the number of objects read exceeds a preset number threshold, the reading of objects in the second memory object linked 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 linked 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 large to small, perform memory leak detection on a preset number of classes with the highest number of objects, and obtain a memory leak detection result.

[0046] In the embodiment of the present application, considering that the location of the memory leak generally appears on the class with a large number of instantiations, the number of objects corresponding to each class is ranked, and the memory leak detection is performed on the top-ranked classes to obtain the 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 according to the number of objects, namely class C, class A, and class B.

[0047] In the embodiment of the present application, objects in the first memory object linked list loaded in the current frame loop are read sequentially 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, class information of the read objects is obtained, and reading of the first memory object linked list in the current frame loop is stopped. In the next frame loop of the current frame loop, objects in the second memory object linked 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 reading of 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 memory object linked list of the corresponding frame loop continues to read objects until all objects in the corresponding memory object linked list are read; wherein, the second memory object linked list is determined according to the first memory object linked list and the object change data of the next frame loop of the current frame loop compared to 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 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, only a small part of the CPU resources is occupied, which avoids affecting the normal operation of the server and improves 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 the 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 class information of the object according to the object information.

[0052] The object information includes but is not limited to the object's attributes, 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 class information of the object. Specifically, the built-in function can be a help() function.

[0054] S13: If the number of objects that have been 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, counting 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, the reading of object nodes in the first memory object linked list is stopped in the current frame loop.

[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 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 attribute information of the object. In Python, the class information of each object is stored in a special attribute named __class__, which is a built-in attribute of Python objects and is used to store the class to which the object belongs.

[0060] By obtaining the class attribute, you can automatically and quickly determine the class to which the object belongs.

[0061] In an optional embodiment, the step of determining the second memory object linked list in step S20 according to the first memory object linked list and the object change data of the next frame cycle of the current frame cycle compared with 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 reduced object information.

[0064] In an embodiment of the present application, by acquiring 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: According to the object change data, the object nodes in the first memory object linked list are updated 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 reduced, the object node corresponding to the object is deleted in the first memory object linked list to generate a second memory object linked list.

[0067] By adding an object node 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 next frame cycle of the current frame cycle, the step of reading the object in the second memory object linked list loaded in the next frame cycle of the current frame cycle includes steps S201 to S203, which are specifically as follows:

[0069] S201: In a next frame loop of 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 the unread objects in the first memory object linked list need to be read in the next frame loop of the current frame loop. To this end, the first position of the last object in the objects read in the current frame loop in the first memory object linked list is obtained.

[0072] S202: Determine a 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 the embodiment of the present application, since the second memory object linked list is obtained by updating the first memory object linked list based on the object change data, the first memory object linked list includes a plurality of object nodes, and each object node corresponds to a 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 corresponds to a number, so that the second position of the last object in the second memory object linked list can be determined according to 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, so that the object is read in multiple frame cycles, thereby 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 may be searched 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 the 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 the embodiment of the present application, the modified class name is matched one by one with a preset number of class names with the highest 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 has not been 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 released memory 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 the code for the memory release operation, it is determined that the object has not released the memory.

[0092] In the embodiment of the present application, when a memory object applies for occupying memory and releasing memory, it corresponds to a specific code. The relevant code of each object corresponding to the target class is obtained, and it is detected whether the relevant code contains the code of 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, it is possible to automatically and quickly determine whether the object has memory released.

[0094] The following is an embodiment of the device of the present application, which can be used to execute the content of the method of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the content of the method in the embodiment of the present application.

[0095] See also Figure 2 , which shows a schematic diagram of the structure of a 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 comprises:

[0096] The class information acquisition module 51 is used to sequentially read objects in the first memory object linked list loaded in the current frame loop in 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, obtain the class information of the read objects and stop reading the first memory object linked list in the current frame loop;

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

[0098] An object quantity determination module 53, used to determine the number of objects corresponding to each class according to 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 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.

[0100] In the embodiment of the present application, objects in the first memory object linked list loaded in the current frame loop are read in sequence 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, class information of the read objects is obtained, and reading of the first memory object linked list in the current frame loop is stopped; in the next frame loop of the current frame loop, objects in the second memory object linked 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 reading of 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 memory object linked list of the corresponding frame loop continues to read objects until all objects in the corresponding memory object linked list are read; wherein, the second memory object linked list is determined according to 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; 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 the 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 instead of reading all objects in one frame loop, only a small part of the CPU resources is occupied, which avoids affecting the normal operation of the server and improves 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.

[0101] The following is an embodiment of the device of the present application, which can be used to execute the content of the method in the embodiment of the present application. For details not disclosed in the embodiment of the device 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 may be 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 may 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 may 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] Among them, the processor 301 may include one or more processing cores. The processor uses various interfaces and lines to connect various parts of the entire electronic device, and executes various functions of the electronic device and processes data by running or executing instructions, programs, code sets or instruction sets stored in the memory, and calling data stored in the memory. Optionally, the processor can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The processor can integrate one or more combinations of central processing unit (Central Processing Unit, CPU), image processor (Graphics Processing Unit, GPU) and modem. Among them, the CPU mainly processes the operating system, user interface and application program, etc.; the GPU is responsible for rendering and drawing the content to be displayed by the display layer; the modem is used to process wireless communication. It can be understood that the above-mentioned modem may not be integrated into the processor, but implemented by a single chip.

[0107] Among them, the memory 302 may include a random access memory (Random Access Memory, RAM) and may also include 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 method embodiments, etc.; the data storage area may store data involved in the above-mentioned 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 refer to the specific description shown in the embodiment, which will not be repeated here.

[0109] The present application also provides a computer-readable storage medium on which a computer program is stored, and the instructions are suitable for being loaded by a processor and executing the method steps of the above-mentioned embodiment. The specific execution process can refer to the specific description shown in the embodiment, and will not be repeated here. The device where the storage medium is located can be a personal computer, a laptop computer, a smart phone, a tablet computer and other electronic devices.

[0110] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can refer to the partial description of the method embodiments. The device embodiments described above are merely schematic, wherein the components described as separate parts may or may not be physically separated, and the parts displayed 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 may 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 adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include 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 box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes 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 generate 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 operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions 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 (CPU), 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 include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. 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 memory (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 technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, tape, disk or other magnetic storage device or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.

[0117] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0118] The above are only 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 modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should 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 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, obtaining class information of the read objects, and stopping reading the first memory object linked list in the current frame loop; 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 continue 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 next frame cycle of the current frame cycle compared to the current frame cycle; Determine the number of objects corresponding to each class according to the class information of the object that has been read; 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 subjected to memory leak detection to obtain a memory leak detection result.

2. The memory leak detection method according to claim 1, characterized in that: The step of reading, in the next frame cycle of the current frame cycle, the objects in the second memory object linked list loaded in the next frame cycle of the current frame cycle comprises: In a next frame cycle of 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, characterized in that: The step of sequentially reading objects in the first memory object linked list loaded in the current frame loop in 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; Determine class information of the object according to the object information; If the number of objects that have been 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, characterized in that: The object information includes attribute information of the object; The step of determining the class information of the object according to the object information comprises: 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, characterized in that: The step of performing memory leak detection on a preset number of classes with the highest number of objects to obtain 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 with the highest 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 highest number of objects; Memory release detection is performed on each object corresponding to the target class, and objects for which memory release has not been performed are determined as memory leak locations of the current version of the application.

6. The memory leak detection method according to claim 5, characterized in that: 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 does not release 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 the next frame cycle of the current frame cycle compared with the current frame cycle includes: Obtain object change data for the 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 used to sequentially read objects in a first memory object linked list loaded in the current frame loop in 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, obtain class information of the read objects and stop reading the first memory object linked list in the current frame loop; An object reading module is used to read objects in a second memory object linked list loaded in a frame cycle next to the current frame cycle in a frame cycle next to the current frame cycle; if the number of objects read in a frame cycle next to the current frame cycle is greater than or equal to a preset number threshold, but the reading of all objects in the second memory object linked list has not been completed, in a subsequent frame cycle of the frame cycle next to the current frame cycle, continue to read objects in the memory object linked list of the corresponding 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; An object quantity determination module, used to determine the number of objects corresponding to each class according to 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 as described in 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

  • Memory refresh parameter determination method and apparatus, memory refresh method and apparatus, and medium and device

    WO2024082343A1