Memory leak detection and analysis method, system, equipment and medium
The memory leak detection and analysis method of memory usage and leakage mode is displayed through a graphical interface, which solves the problem of inability to customize detection and detection efficiency in the existing technology, and realizes efficient and accurate memory leak detection and analysis.
Patent Information
- Application Number
- CN202510359165.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-25
- Publication Date
- 2025-06-13
AI Technical Summary
Existing memory detection tools cannot be customized according to the characteristics and needs of different applications, resulting in the inability to accurately detect memory leakage in applications in specific fields. The decentralized detection method increases system overhead and reduces detection efficiency.
It provides a memory leak detection and analysis method, displaying memory usage and leakage mode through a graphical interface, allowing users to customize the selection of memory analysis modules, configure the execution order, and integrate multiple analysis subprocesses to generate the analysis process to be executed, and perform memory detection and analysis.
It realizes customization of memory detection according to different application characteristics, improves the pertinence and accuracy of detection, reduces system overhead, improves detection efficiency, and intuitively displays memory leakage through a graphical interface.
Smart Images

Figure CN120145370A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of memory detection, and particularly relates to a method, system, device and medium for memory leak detection and analysis. Background Art
[0002] With the development of information technology, the popularity of computer systems and software applications has been continuously increasing, and the requirements for system performance, stability and security have also become higher and higher. The memory leak problem is a technical challenge that cannot be ignored, especially more prominent in domestic computer systems.
[0003] Memory detection tools in related technologies usually adopt fixed detection processes and rules, and cannot be customized according to the characteristics and requirements of different application programs. For example, for some application programs in specific fields, such as game development, financial trading systems, etc., the memory usage patterns and potential memory leak risks may be very different from those of ordinary application programs. Using general detection tools may not accurately detect memory leak problems in these application programs. Moreover, some memory detection tools will start multiple independent detection processes during the detection process, and each process is responsible for different detection tasks. This decentralized detection method will increase system overhead and reduce detection efficiency.
[0004] The detection results of related memory detection tools are usually presented in the form of text or tables. For complex memory usage situations and leak patterns, it is difficult for developers and operation and maintenance personnel to intuitively understand and analyze. This may lead to misjudgment or missed judgment of memory leak problems, affecting the problem-solving efficiency. Summary of the Invention
[0005] The present invention provides a method for memory leak detection and analysis, which displays the memory usage amount and leak pattern through a graphical interface to help users intuitively understand the distribution of memory leaks and potential risk points.
[0006] The method includes: acquiring and saving memory usage data based on an application program; defining a set containing multiple memory analysis modules; loading the memory analysis modules and displaying them on a first graphical interface; making a custom selection based on the attribute information of the memory to be detected, and selecting multiple target memory leak execution modules; triggering a selected memory detection process based on the target memory leak execution modules, obtaining corresponding target memory leak analysis subprocesses, and determining the execution order among the target memory leak execution modules through an execution order configuration operation; Fuse multiple target memory leak analysis subprocesses in this order to generate a target memory leak analysis process to be executed, so as to detect the memory according to the memory leak analysis instruction and identify the memory leak location and memory leak data; Extract the leakage frequency, total leakage amount, and leakage location in the memory leak data as key information to generate a memory leak data report; Display the memory usage and leakage pattern through a graphical interface.
[0007] Furthermore, it should be noted that based on the selected memory detection process triggered by multiple target memory leak execution modules, obtain the target memory leak analysis subprocesses corresponding to the target memory leak analysis tasks represented by each of the multiple target memory leak execution modules, and determine the execution order between the multiple target memory leak execution modules based on the execution order configuration operation triggered by the multiple target memory leak execution modules; Fuse multiple target memory leak analysis subprocesses in the execution order to generate a target memory leak analysis process to be executed and detect the memory.
[0008] Furthermore, it should be noted that according to the correspondence between the preset memory leak analysis task and the memory detection template file, determine the target memory detection template file corresponding to the target memory leak analysis task represented by the target memory leak execution module; Based on the editing operation of the target memory detection template file, use the generated memory leak analysis subprocess as the memory leak analysis subprocess associated with the target memory leak analysis task.
[0009] Furthermore, it should be noted that based on the editing operation of the analyzed memory leak analysis subprocess, determine the edited memory leak analysis subprocess; Use the edited memory leak analysis subprocess as an analyzed memory leak analysis subprocess associated with the target memory leak analysis task.
[0010] Furthermore, it should be noted that according to the correspondence between the preset memory detection template file and the memory leak analysis test process template, determine the target memory leak analysis test process template corresponding to the target memory detection template file corresponding to the target memory leak analysis task represented by a target memory leak execution module; Based on the editing operation on the target memory leak analysis test process template, use the generated memory leak analysis test process as the memory leak analysis test process corresponding to the memory leak analysis subprocess associated with the target memory leak analysis task; Determine the edited memory leak analysis test process; Use the edited memory leak analysis test process as the memory leak analysis test process corresponding to the memory leak analysis subprocess associated with the target memory leak analysis task.
[0011] Furthermore, it should be noted that a memory leak analysis instruction is received; According to the pre-saved correspondence between each object attribute information and the memory leak analysis process, determine the target memory leak analysis process corresponding to the attribute information of the memory to be processed; Run the target memory leak analysis process to detect the memory.
[0012] This application also provides a memory leak detection and analysis system, which includes: A data acquisition module for acquiring and saving memory usage data based on an application program; An analysis and display module for defining a set containing multiple memory analysis modules, loading the memory analysis modules and displaying them on a first graphical interface; An information selection module for making a custom selection based on the attribute information of the memory to be detected and selecting multiple target memory leak execution modules; An execution order configuration module for obtaining the corresponding target memory leak analysis subprocess based on the selected memory detection process triggered by the target memory leak execution module, and determining the execution order between the target memory leak execution modules through an execution order configuration operation; A memory detection module for fusing multiple target memory leak analysis subprocesses in this order to generate a target memory leak analysis process to be executed, so as to detect the memory according to the memory leak analysis instruction and identify the memory leak location and memory leak data; An information extraction module for extracting the leak frequency, total leak amount, and leak location in the memory leak data as key information to generate a memory leak data report; A memory display module for displaying the memory usage amount and leak mode through a graphical interface.
[0013] According to another embodiment of the present application, an electronic device is provided, which includes a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, the steps of the memory leak detection and analysis method are implemented.
[0014] According to still another embodiment of the present application, a storage medium is further provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the memory leak detection and analysis method are implemented.
[0015] From the above technical solutions, it can be seen that the present invention has the following advantages: The memory leak detection and analysis method provided by this application allows users to make custom selections based on a set of memory analysis modules, select multiple target memory leak execution modules, and configure their execution order. This enables memory detection to be customized according to the characteristics and requirements of different applications, improving the pertinence and accuracy of detection.
[0016] By presetting the correspondence between memory leak analysis tasks and memory detection template files, this application provides editable templates for each target memory leak analysis task. Users can edit the template files to generate memory leak analysis subprocesses suitable for specific scenarios, and can also perform secondary editing on the generated subprocesses. This enhances the flexibility of detection and can quickly respond to changes in applications and newly emerging memory leak patterns. According to the configured execution order, multiple target memory leak analysis subprocesses are integrated into a target memory leak analysis process to be executed. This can avoid starting different detection processes multiple times, reduce system overhead, and improve detection efficiency. At the same time, unified process execution also facilitates the summarization and analysis of detection results.
[0017] This application integrates multiple target memory leak analysis subprocesses into a target memory leak analysis process to be executed, avoiding starting different detection processes multiple times and reducing system overhead. At the same time, unified process execution also facilitates the summarization and analysis of detection results, improving the coherence and efficiency of detection. Brief Description of the Drawings
[0018] To more clearly illustrate the technical solutions of the present invention, the drawings required for description will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0019] Figure 1 It is a flowchart of the memory leak detection and analysis method; Figure 2 It is a flowchart of an embodiment of the memory leak detection and analysis method; Figure 3 It is a flowchart of another embodiment of the memory leak detection and analysis method Figure 4 It is a schematic diagram of an electronic device. Detailed Embodiments
[0020] In the memory leak detection and analysis method provided by this application, based on the data acquisition module, the memory allocation and release operations of the application program are monitored in real time through the API hook or system call interception method, and the specific information of each operation, such as timestamp, memory address, size, etc., is recorded. This information is stored in the database for subsequent analysis.
[0021] The memory analysis module conducts comprehensive analysis using multiple detection techniques, including but not limited to Valgrind, VisualLeak Detector, Bounds Checker, etc. By adopting a complementary fusion strategy through integrating multiple techniques, the memory analysis module can more accurately locate the position and nature of memory leaks. For example, Valgrind can provide detailed memory access paths, while mtrace can quickly scan the memory usage of the entire program.
[0022] The data extraction module further processes the detected memory leak data and extracts key information such as leak frequency, total leak volume, leak location, etc. After statistical analysis and summarization, these information are used to generate easy-to-understand data reports to support visual display.
[0023] The data display module can display the memory usage and leak patterns in the form of line charts, bar charts, scatter plots, etc. through a graphical interface. Users can customize and analyze the charts and graphs through operations such as clicking, dragging, and zooming.
[0024] The following will describe in detail the specific implementation steps of the memory leak detection and analysis method. For the purpose of illustration rather than limitation, specific details such as specific system structures and technologies are proposed to facilitate a thorough understanding of the embodiments of the present application. However, those skilled in the art should clearly understand that the present application can also be implemented in other embodiments without these specific details.
[0025] It should be understood that when used in the specification of the present application, the term "including" indicates the presence of the described features, wholes, steps, operations, elements, and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components, and / or their combinations. The terms "including", "comprising", "having" and their variants all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0026] Statements such as "in one embodiment" or "in some embodiments" described in the present application mean that specific features, structures, or characteristics described in that embodiment are included in one or more embodiments of the present application. Thus, statements such as "in one embodiment", "in some embodiments", "in other some embodiments", "in still other embodiments" and the like that appear in different parts of the present application do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways.
[0027] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0028] Please refer to Figure 1 The figure shows a flowchart of a memory leak detection and analysis method in a specific embodiment. The method includes: S101: Obtain and save memory usage data based on the application.
[0029] S102: Based on the memory analysis module, analyze the memory usage data and identify the memory leak location and memory leak data.
[0030] S103: Extract the key information of the memory leak data and generate a memory leak data report.
[0031] S104: Display the memory usage amount and the leak mode through a graphical interface.
[0032] In some specific embodiments, the memory usage amount data can be collected in real time, and detailed memory usage information can be obtained by monitoring the memory allocation and release operations of the system.
[0033] The memory analysis module integrates, such as Valgrind, mtrace, etc., analyzes the collected memory usage data, and identifies the location and nature of the memory leak. Then, the detected memory leak data is further analyzed and processed to extract key information, providing data support for visual display. The memory usage amount and the leak mode are displayed through a graphical interface to help users intuitively understand the distribution of memory leaks and potential risk points.
[0034] In this embodiment, suitable detection methods and technologies are selected and combined according to the characteristics and advantages of various technologies. For example, the precise positioning ability of Valgrind and the fast positioning function of mtrace are combined. Various technologies are integrated at different levels to form a hierarchical detection system. For example, Bounds Checker can be used for preliminary memory debugging first, and then Valgrind can be used for in-depth memory leak detection. Through automated scripts and toolchains, the automated integration and collaborative work of various technologies are realized. Users only need to input relevant configuration parameters, and the platform can automatically complete the memory leak detection task.
[0035] Based on the graphical interface, users can intuitively view the memory usage and leakage patterns. The platform provides a series of charts and graphs, such as line charts, bar charts, scatter plots, etc., to help users understand the distribution of memory leaks and potential risk points. These visualized data not only help users quickly identify problems but also guide further troubleshooting work.
[0036] Based on the above embodiments, in order to further improve the reliability of the memory leak detection and analysis method provided in the above embodiments, the following provides a more specific and implementable manner in combination with the above method. In one embodiment, as Figure 2 shown, the specific implementation process of the memory leak detection and analysis method is as follows: S201: Define a set of memory analysis modules. The set of memory analysis modules includes multiple memory analysis modules, and each memory analysis module is used to implement a memory leak analysis task.
[0037] In some embodiments of the present application, memory detection personnel can pre-configure multiple memory analysis modules, where each memory analysis module can be used to implement a memory leak analysis task.
[0038] When the system starts the memory detection related functions, it loads the pre-configured multiple memory analysis modules and displays the information of the memory analysis modules on the first graphical interface. This interface can be in the form of a list, and each list item represents a memory analysis module.
[0039] It should be noted that different types of memory leak analysis tasks can be encapsulated into independent memory analysis modules. Memory leaks are detected based on different algorithms and rules, such as detecting whether memory allocation and release match, and detecting whether memory is still not released after a long time of inactivity. When the system needs to display these modules, it reads the information from the database or configuration file storing the module information and renders it on the first graphical interface.
[0040] Exemplarily, a set of pre-configured memory analysis modules is displayed through a graphical interface. Each module corresponds to an independent memory leak analysis task, and the tasks can include: periodically capturing the memory usage status, analyzing the reference relationships between objects, identifying objects referenced by garbage collection root nodes, detecting unclosed file handles or database connections, and counting the rate and distribution of memory allocation.
[0041] This embodiment allows complex memory leak detection tasks to be decomposed into sub-tasks with single functions based on modular design, and each module encapsulates specific algorithms or rules.
[0042] S202: Select multiple target memory leak execution modules based on the custom selection triggered by the set of memory analysis modules. The custom selection is triggered based on the attribute information of the to-be-analyzed memory.
[0043] In the embodiment of the present application, the memory detection personnel can select a memory analysis module applicable to the to-be-detected memory from the set of memory analysis modules displayed in the first graphical interface according to the type and attribute information of the to-be-detected memory.
[0044] Optionally, in the first graphical interface, a selection list containing each memory analysis module can be displayed. What can be displayed based on the selection list can be the identification information of each memory analysis module. Specifically, what can be displayed can be the name of each memory analysis module, or the name and icon of each memory analysis module can be displayed simultaneously. Optionally, in order to facilitate the memory detection personnel to select a memory analysis module, a corresponding selection box can be displayed based on each memory analysis module. The memory detection personnel can select the corresponding memory analysis module through a triggering operation on the selection box. In response to the custom selection triggered by the memory detection personnel based on the set of memory analysis modules, a plurality of target memory leak execution modules selected by the memory detection personnel can be displayed in the second graphical interface.
[0045] In this embodiment, the memory detection personnel select a memory analysis module on the first graphical interface according to the attribute information of the to-be-detected memory (such as the program type to which the memory belongs, the running environment, the memory scale, etc.). The system will capture these selection operations and then display the selected module information on the second graphical interface.
[0046] Specifically, the attribute information of the to-be-detected memory can help the memory detection personnel determine which memory analysis modules are more suitable for the current detection task. For example, if the to-be-detected memory is the memory of a high-concurrency server program, then the analysis modules related to multi-thread memory management may be more useful. The system will screen out the corresponding modules from the set of memory analysis modules according to the user's selection and display their information on a new interface for the user to further operate.
[0047] Exemplarily, for the memory detection of a certain server, if the server is a multi-threaded real-time policy server, the memory detection personnel select the dynamic memory release detection module and the multi-thread memory synchronization detection module from the first graphical interface according to this attribute information. The system will display the functions, detection rules, etc. of these two modules on the second graphical interface.
[0048] S203: Trigger a memory detection process based on a plurality of target memory leak execution modules, obtain target memory leak analysis subprocesses corresponding to the target memory leak analysis tasks represented by the plurality of target memory leak execution modules respectively, and determine the execution order among the plurality of target memory leak execution modules based on the execution order configuration operation triggered by the plurality of target memory leak execution modules.
[0049] In the embodiment of the present application, when a memory detection personnel configures a memory leak analysis subprocess corresponding to the memory leak analysis task implemented by each memory analysis module for each memory analysis module in advance, multiple analyzed memory leak analysis subprocesses are generated. Among them, different analyzed memory leak analysis subprocesses may be applicable to different memories to be detected.
[0050] In order to select a memory leak analysis subprocess applicable to the memory to be detected, the memory leak analysis task represented by each memory analysis module can be associated with each analyzed memory leak analysis subprocess. Based on each target memory leak execution module, a memory leak analysis subprocess corresponding to the memory leak analysis task represented by each target memory leak execution module can be selected.
[0051] In the embodiment of the present application, since each target memory leak execution module applicable to the memory can be selected from multiple memory analysis modules based on the attribute information of the memory to be detected, when it is necessary to modify the memory leak analysis subprocess corresponding to the memory leak analysis task represented by a certain memory leak execution module, only the memory leak analysis subprocess corresponding to the memory leak analysis task represented by a certain memory leak execution module needs to be modified, without the memory detection personnel having to rewrite the entire detection code applicable to the memory to be detected from scratch, thereby improving the flexibility of detection.
[0052] In this embodiment, each memory analysis module corresponds to a specific target memory leak analysis subprocess during design, and these subprocesses contain specific detection logics. The system will obtain the corresponding subprocess from the memory or storage device according to the identification information of the module. The configuration of the execution order allows the user to adjust the detection order according to the actual situation. For example, some key memory areas are detected first, and then other areas are detected.
[0053] In the embodiment of the present application, in order to configure the execution order of multiple target memory leak execution modules, the memory detection personnel set an execution order identifier for each target memory leak execution module. Through this configuration operation, the execution sequence among multiple target memory leak execution modules can be clarified based on the execution order identifier.
[0054] When the memory detection personnel adjust the execution order of these modules, only the execution order configuration operation for multiple target memory leak execution modules needs to be triggered again. Then the execution order among each module can be determined again. The memory detection personnel do not need to rewrite the entire detection code for the memory to be detected from scratch for memory leak detection.
[0055] S204: Integrate multiple target memory leak analysis subprocesses according to the execution order to generate a target memory leak analysis process to be executed. Based on the memory leak analysis instructions for the memory to be detected, run the target memory leak analysis process to detect the memory.
[0056] After determining the execution order between the target memory leak analysis subprocesses and multiple target memory leak execution modules, this embodiment can integrate multiple target memory leak analysis subprocesses according to this execution order, thereby generating a target memory leak analysis process to be executed.
[0057] It should be noted that according to the previously determined execution order, multiple target memory leak analysis subprocesses are combined into a complete target memory leak analysis process. When a memory leak analysis instruction for the memory to be detected is received, the system will start this target memory leak analysis process and sequentially execute each subprocess to comprehensively detect the memory to be detected.
[0058] In this embodiment, integrating multiple subprocesses into one process can improve the detection efficiency and coherence. After each subprocess completes its detection task, the result is passed to the next subprocess or aggregated into the final detection result. This can avoid starting different processes multiple times and reduce system overhead.
[0059] This embodiment can integrate the dynamic memory release detection subprocess and the multi-threaded memory synchronization detection subprocess into a target memory leak analysis process according to the previously determined execution order. When a memory leak analysis instruction for the game server memory is received, first run the dynamic memory release detection subprocess to detect the dynamic memory allocation and release situation of the server, and then run the multi-threaded memory synchronization detection subprocess to check the memory synchronization problem in the multi-threaded environment. Finally, aggregate the detection results of the two subprocesses to generate a final memory leak detection report.
[0060] The subprocess integration uses the output of the previous module as the input of the subsequent module, such as passing the snapshot file path. The process that the user can configure is: start memory monitoring, perform stress testing, generate a heap dump file, and analyze suspicious objects in the heap dump. The system automatically executes in sequence and finally outputs the class name and reference chain of the leaked objects.
[0061] Exemplarily, assume there are target memory leak execution modules 1-1, target memory leak execution modules 1-2, target memory leak execution modules 1-3, and target memory leak execution modules 1-4. The target memory leak analysis subprocesses corresponding to the target memory leak analysis tasks represented by each are target memory leak analysis subprocess 1-1-1, target memory leak analysis subprocess 1-2-1, target memory leak analysis subprocess 1-3-1, and target memory leak analysis subprocess 1-4-1.
[0062] If the execution order among multiple target memory leak execution modules is target memory leak execution module 1-2, target memory leak execution module 1-3, target memory leak execution module 1-1, and target memory leak execution module 1-4 respectively. Then after fusing these multiple target memory leak analysis subprocesses, the code order included in the generated target memory leak analysis process to be executed will be target memory leak analysis subprocess 1-2-1, target memory leak analysis subprocess 1-3-1, target memory leak analysis subprocess 1-1-1, and target memory leak analysis subprocess 1-4-1.
[0063] Another exemplary case is that if you want to change the execution order so that the execution order of the target memory leak execution modules is target memory leak execution module 1-4, target memory leak execution module 1-3, target memory leak execution module 1-2, and target memory leak execution module 1-1. Then the code order included in the fused target memory leak analysis process to be executed is target memory leak analysis subprocess 1-4-1, target memory leak analysis subprocess 1-3-1, target memory leak analysis subprocess 1-2-1, and target memory leak analysis subprocess 1-1-1.
[0064] In this embodiment, by adjusting the execution order of the target memory leak execution modules, the code order in the finally generated target memory leak analysis process to be executed can be controlled. In this way, when receiving a memory leak analysis instruction based on the target memory, the system can run these codes in a predetermined order, so as to comprehensively detect the target memory.
[0065] This embodiment also relates to a new target memory leak analysis module X. The module name can be defined as memory leak analysis module X. The target memory leak analysis module X is specifically designed to detect and analyze memory leak problems in specific types or specific scenarios. It can track memory allocation and release in real time and identify potential memory leak points.
[0066] Corresponding to subprocess x, assuming that x is the target memory leak analysis subprocess corresponding to the execution of the X memory leak analysis module, which contains all the analysis logics and algorithms required by the target memory leak analysis module X. Among the execution orders of multiple target memory leak execution modules, the target memory leak analysis module X can be arranged at any position according to needs. Its execution order will affect the code order in the finally generated target memory leak analysis process to be executed, thus determining the process and focus of memory leak analysis. In this way, the target memory leak analysis module X adopts optimized algorithms and data structures to ensure high efficiency even when analyzing large-scale memory usage. Through accurate tracking of memory allocation and release, the target memory leak analysis module X can accurately identify memory leak problems and reduce false alarms and missed reports.
[0067] In this embodiment, by selecting appropriate analysis modules and execution orders according to the attribute information of the memory to be detected, memory leak detection can be carried out more pertinently, improving the accuracy of detection. For example, for different types of programs, using different detection modules can more accurately discover potential memory leak problems. Users can adjust the detection modules and execution orders according to actual needs to adapt to different detection scenarios. For example, in an emergency, only key detection modules can be selected for rapid detection; when comprehensive detection is required, more modules can be selected for detailed detection.
[0068] In this embodiment, multiple child processes are fused into one process for detection, which can reduce system overhead and improve detection efficiency. At the same time, executing child processes in a reasonable order can avoid repeated detection and unnecessary operations, further improving detection efficiency.
[0069] In some embodiments of the present application, in order to reduce the workload of memory detection personnel and improve object detection efficiency, each memory leak analysis subprocess associated with the target memory leak analysis task represented by a target memory leak execution module can be configured in the following manner: S301: Determine the target memory detection template file corresponding to the target memory leak analysis task represented by a target memory leak execution module according to the preset correspondence between the memory leak analysis task and the memory detection template file.
[0070] In some embodiments of the present application, a correspondence between the memory leak analysis task and the memory detection template file is established in advance in the system, and this correspondence can be stored in a database or a configuration file. When specifying the target memory leak analysis task represented by a target memory leak execution module, the system will, according to this preset correspondence, search and determine the corresponding target memory detection template file from the stored information.
[0071] Exemplarily, this correspondence can be regarded as a mapping function f. Let T be the set of memory leak analysis tasks and M be the set of memory detection template files, then f: T → M. For the target memory leak analysis task t ∈ T, the corresponding target memory detection template file m = f(t) ∈ M can be found through the function f.
[0072] Exemplarily, assume that in the memory detection system of a software development project, the following correspondence is preset: the global variable memory leak detection task corresponds to the global variable detection template file, and the dynamic memory allocation leak detection task corresponds to the dynamic allocation detection template file. If the target memory leak execution module represents the global variable memory leak detection task, then the system will, according to this preset relationship, determine the global variable detection template file as the target memory detection template file.
[0073] S302; Based on the editing operation of the target memory detection template file, the memory leak analysis subprocess generated by the editing is used as the analyzed memory leak analysis subprocess associated with the target memory leak analysis task.
[0074] After this embodiment determines the target memory detection template file corresponding to the target memory leak analysis task represented by a target memory leak execution module, the memory detection personnel can edit the target memory detection template file based on this target memory detection template file. In response to the editing operation of the memory detection personnel based on the target memory detection template file, this embodiment can use the memory leak analysis subprocess generated by the memory detection personnel based on the target memory detection template file as an analyzed memory leak analysis subprocess associated with the target memory leak analysis task.
[0075] It should be noted that the user or system administrator can perform an editing operation on the target memory detection template file, such as modifying the detection rules, parameter settings, etc. in the template. After the editing is completed, the system will generate a memory leak analysis subprocess according to the edited template file, and this subprocess will be specifically used to execute the target memory leak analysis task.
[0076] In this embodiment, the target memory detection template file can be regarded as a template of an algorithm, and the editing operation is to adjust the parameters and rules of this algorithm. Let the template file be m, and the editing operation can be represented as a transformation function g. After editing, the new template m' = g(m) is obtained. Then, according to the new template m', a memory leak analysis subprocess p is generated, which can be represented by a generation function h, that is, p = h(m').
[0077] S303: Based on the editing operation of the analyzed memory leak analysis subprocess, determine the edited memory leak analysis subprocess.
[0078] In this embodiment, after generating the memory leak analysis subprocess, further editing operations can also be performed on this subprocess. These operations may include adjusting the execution logic of the subprocess, optimizing the detection algorithm, etc. The system will modify the original subprocess according to these editing operations to obtain the edited memory leak analysis subprocess.
[0079] Specifically, let the original memory leak analysis subprocess be p, and the editing operation can be represented as a transformation function k. Then the edited memory leak analysis subprocess p' = k(p). This transformation function k can modify the code logic, parameters, etc. in p.
[0080] For the global variable memory leak analysis subprocess generated previously, the user found that the subprocess would generate some unnecessary calculations during the detection process, resulting in low detection efficiency. So the user edited the subprocess, optimized the detection algorithm, and reduced unnecessary calculation steps. After editing, a new and more efficient memory leak analysis subprocess was obtained.
[0081] S304: Use the edited memory leak analysis subprocess as an analysis memory leak analysis subprocess associated with the target memory leak analysis task.
[0082] In this embodiment, the edited memory leak analysis subprocess is associated with the target memory leak analysis task to update the analysis subprocess information corresponding to the task in the system. In this way, when the target memory leak analysis task is subsequently executed, this edited subprocess will be used for detection.
[0083] In this embodiment, the target memory leak analysis task can be set as t, the originally associated analysis subprocess as p, and the edited subprocess as p'. The system will update the association relationship between task t and the subprocess, changing the original t→p to t→p'.
[0084] In some embodiments of this application, considering that if the target memory leak analysis subprocess corresponding to the target memory leak analysis task represented by the target memory leak execution module runs unstably, it may affect the accuracy of the detection results for the memory to be detected. To perform object detection stably and accurately, based on each analysis memory leak analysis subprocess associated with the target memory leak analysis task represented by each target memory leak execution module, a corresponding memory leak analysis test process can be pre-configured for each analysis memory leak analysis subprocess, and then based on the corresponding memory leak analysis test process, the corresponding analysis memory leak analysis subprocess is tested. If the test result of the unit test meets the requirements, the corresponding analysis memory leak analysis subprocess can be saved.
[0085] If the test result of the unit test does not meet the requirements, the memory leak analysis subprocess needs to be modified. When the test result of the modified memory leak analysis subprocess during unit testing is appropriate, the corresponding analysis memory leak analysis subprocess is saved.
[0086] In the above manner of this embodiment, a preset memory detection template file is associated with the memory leak analysis task, and editing of the template file and the generated analysis subprocess is allowed. This manner is different from the traditional fixed detection process. The traditional method may use a hard-coded detection algorithm, which is difficult to flexibly adjust according to different scenarios and requirements. Through the template and editing operations, users can customize the rules and logic of memory leak detection according to the specific application program characteristics and detection requirements. This embodiment can not only edit the template file, but also perform secondary editing on the generated analysis subprocess. This multi-stage editing method makes the adjustment of memory leak detection more refined and flexible, and can optimize the detection algorithm at different levels to improve the detection accuracy.
[0087] In this embodiment, the target memory leak execution module represents the memory leak analysis test process corresponding to the analysis memory leak analysis subprocess associated with the target memory leak analysis task, and can be configured in the following manner: S401: According to the corresponding relationship between the preset memory detection template file and the memory leak analysis test process template, determine the target memory detection template file corresponding to the target memory leak analysis task represented by a target memory leak execution module to match the target memory leak analysis test process template.
[0088] In some embodiments of the present application, memory detection personnel can preset the corresponding relationship between the memory detection template file and the memory leak analysis test process template, and save the preset corresponding relationship between the memory detection template file and the memory leak analysis test process template in this embodiment. The memory detection template file and the corresponding memory leak analysis test process template can be set according to requirements.
[0089] In this embodiment, the corresponding relationship between the memory detection template file and the memory leak analysis test process template is preset in advance, and these corresponding relationships are stored in a database or a configuration file. After determining the target memory detection template file corresponding to the target memory leak analysis task represented by the target memory leak execution module, the system will search and determine the target memory leak analysis test process template corresponding to the target memory detection template file according to the preset corresponding relationship.
[0090] In this embodiment, a set of memory detection template files can be set as A, and a set of memory leak analysis test process templates can be set as B. The preset corresponding relationship can be regarded as a mapping function f: A → B. For a target memory detection template file a ∈ A, the corresponding target memory leak analysis test process template b = f(a) ∈ B can be obtained through the function f. In a memory detection system for mobile application development, a correspondence between an object creation and destruction detection template file and an object lifecycle test process template is preset. If the target memory leak execution module represents an object creation and destruction memory leak analysis task, after determining that the corresponding target memory detection template file is the object creation and destruction detection template file, the system can determine, according to the corresponding relationship, that the target memory leak analysis test process template is the object lifecycle test process template.
[0091] S402: Based on the editing operation of the target memory leak analysis test process template, the memory leak analysis test process generated by the editing is used as the memory leak analysis test process corresponding to the memory leak analysis subprocess associated with the target memory leak analysis task.
[0092] In some embodiments of the present application, the user can perform an editing operation on the target memory leak analysis test process template, such as modifying test parameters, adjusting the test process, etc. After the editing is completed, the system generates a memory leak analysis test process according to the edited template and binds it to an analysis memory leak analysis subprocess associated with the target memory leak analysis task.
[0093] In this embodiment, the target memory leak analysis test process template is set as b, and the editing operation can be represented as a transformation function g. After editing, a new template b' = g(b) is obtained. Then, through a generation function h, a memory leak analysis test process p = h(b') is generated according to the new template b'. Finally, the process p is associated with the analysis memory leak analysis subprocess associated with the target memory leak analysis task. S403: Based on the editing operation of other analysis memory leak analysis test processes, determine the edited memory leak analysis test process.
[0094] In this embodiment, after there is already an analysis memory leak analysis test process, further editing operations can be performed on it. These operations may include optimizing the test algorithm, adding new test conditions, etc. The system modifies the original test process according to these editing operations to obtain the edited memory leak analysis test process.
[0095] Exemplarily, for the object lifecycle memory leak analysis test process generated previously, the user found that the test effect of this process was not good in a multi-threaded environment. So the user edited it and added test logic for multi-threading. After editing, a new memory leak analysis test process that is more suitable for the multi-threaded environment was obtained.
[0096] S404: Use the edited memory leak analysis test process as the memory leak analysis test process corresponding to an analysis memory leak analysis subprocess associated with the target memory leak analysis task.
[0097] In this embodiment, the edited memory leak analysis test process is re-associated with an analysis memory leak analysis subprocess associated with the target memory leak analysis task, and the test process information corresponding to this subprocess in the system is updated. In this way, when the target memory leak analysis task is executed subsequently, this edited test process will be used for detection.
[0098] It should be noted that assume the analysis memory leak analysis subprocess associated with the target memory leak analysis task is s, the originally associated memory leak analysis test process is p, and the edited test process is p'. The system will update the association relationship between subprocess s and the test process, changing the original s→p to s→p'.
[0099] This embodiment introduces the corresponding relationship between the memory detection template file and the memory leak analysis test process template, and allows editing of the test process template and the generated test process. This design of multi-level templates and flexible editing method is different from the traditional single detection process. It can customize the test process according to different memory leak analysis tasks and application scenarios, improving the pertinence of detection. It can not only perform initial editing on the template, but also perform secondary editing on the generated test process. This enables the test logic of memory leak detection to be continuously optimized as the application program changes and new memory leak patterns are discovered, maintaining the effectiveness of detection.
[0100] As Figure 3 shown, the method of this embodiment also involves the following specific methods: S501: Receive a memory leak analysis instruction, where the memory leak analysis instruction carries the memory to be detected and the attribute information of the memory to be detected.
[0101] The memory detection system is in a state of waiting for instructions. When the user or other system components initiate a memory leak analysis requirement, a memory leak analysis instruction will be generated. This instruction contains the target memory (i.e., the memory to be detected) that needs to be detected and the relevant attribute information of this memory, such as the application program type to which the memory belongs, the running environment, the memory scale, etc. After the system receives this instruction, it will parse it to extract the memory to be detected and the attribute information, preparing for subsequent analysis.
[0102] In some embodiments of the present application, the memory detection personnel can also configure a timing detection instruction for when to detect the memory to be detected according to the attribute information of the memory to be detected, etc. In this embodiment, when the current time reaches the detection time specified in the timing detection instruction, it can be considered that a memory leak analysis instruction for detecting the memory is received. For example, the memory detection personnel can first save all the memories to be detected received within the current detection cycle at a set position, and configure a timing detection instruction for the memories to be detected at the set position to be detected at 10:00 every morning. In this embodiment, at 10:00 every morning, it can be considered that memory leak analysis instructions for detecting each memory to be detected at the set position are received. Among them, each memory leak analysis instruction can carry a memory to be detected and the attribute information of the memory to be detected.
[0103] S502: Determine the target memory leak analysis process corresponding to the attribute information of the memory to be detected according to the corresponding relationship between each object attribute information and the memory leak analysis process pre - saved.
[0104] In the previous configuration or learning process, the corresponding relationship between the object attribute information and the memory leak analysis process has been established and saved. This corresponding relationship can be stored in a database or a configuration file. When the attribute information of the memory to be detected in step S501 is received, the system will search and match in this corresponding relationship to find the memory leak analysis process that most conforms to the attribute information of the memory to be detected, and determine it as the target memory leak analysis process.
[0105] Suppose the pre - saved corresponding relationship of the system is as follows: For a Java - based Web application running on a Tomcat server with a memory scale of 1 - 3GB, the corresponding memory leak analysis process is the Java - Tomcat - 1 - 3GB memory detection process. When the system receives the attribute information of the above - mentioned service module, by searching the corresponding relationship, the target memory leak analysis process can be determined as the Java - Tomcat - 1 - 3GB memory detection process.
[0106] In some embodiments of the present application, in order to quickly determine the memory leak analysis process suitable for the memory to be detected, the corresponding relationship between each object attribute information and the memory leak analysis process can be pre - saved, where each object attribute information and the corresponding memory leak analysis process can be flexibly configured according to requirements, and the present application does not make specific limitations on this. When a memory leak analysis instruction is received, this embodiment can determine the memory leak analysis process corresponding to the attribute information of the memory to be detected (referred to as the target memory leak analysis process for convenience of description) according to the corresponding relationship between each object attribute information and the memory leak analysis process pre - saved.
[0107] S503: Run the target memory leak analysis process to detect the memory.
[0108] After determining the target memory leak analysis process in this embodiment, the process will be started. The target memory leak analysis process will comprehensively scan and analyze the memory to be detected according to the preset logic and algorithm. During the detection process, various data on memory usage will be collected, such as the time of memory allocation and release, the change in memory occupancy, etc., and based on these data, it will be determined whether there is a memory leak, as well as the location of the memory leak and the amount of leaked data.
[0109] Exemplarily speaking, for the determined Java - Tomcat - 1 - 3GB memory detection process, this process will first connect to the Tomcat server running the business module to obtain the memory usage data of the business module. Then, it will analyze the creation and destruction of Java objects to check whether there is a situation where an object still occupies memory after it is no longer used. For example, check whether cached objects are not properly cleared after expiration, or whether there are memory leaks in the threads in the thread pool. During the analysis process, if it is found that the memory occupancy of a certain object continuously increases and there is no corresponding release operation, it will be marked as a possible memory leak point and the relevant data will be recorded.
[0110] The method of this embodiment realizes customized detection based on attributes by using the attribute information of the memory to be detected. Different from the traditional general memory detection method, it can select the most appropriate detection strategy according to the characteristics and usage scenarios of different memories, improving the pertinence and accuracy of detection. By pre - saving the corresponding relationship between object attribute information and the memory leak analysis process, the system can quickly and accurately find the appropriate analysis process after receiving the analysis instruction, avoiding the cumbersome process of re - configuring the detection process each time and improving the detection efficiency.
[0111] It should be understood that the magnitudes of the sequence numbers of the steps in the above embodiments do not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation to the implementation process of the embodiments of the present invention.
[0112] The following are embodiments of the memory leak detection and analysis system provided by the embodiments of the present disclosure. This system and the memory leak detection and analysis methods of the above - mentioned embodiments belong to the same inventive concept. For the details not described in detail in the embodiments of the memory leak detection and analysis system, reference can be made to the embodiments of the above - mentioned memory leak detection and analysis methods.
[0113] The system includes: a data acquisition module for acquiring and saving the memory usage data based on the application program; An analysis and display module, which is used to define a set containing multiple memory analysis modules, load the memory analysis modules and display them on a first graphical interface; An information selection module, which makes a custom selection based on the attribute information of the memory to be detected and selects multiple target memory leak execution modules; An execution order configuration module, which, based on the selected memory detection process triggered by the target memory leak execution module, obtains the corresponding target memory leak analysis subprocess, and determines the execution order among the target memory leak execution modules through execution order configuration operations; A memory detection module, which is used to fuse multiple target memory leak analysis subprocesses in this order to generate a target memory leak analysis process to be executed, so as to detect the memory according to the memory leak analysis instruction and identify the memory leak location and memory leak data; An information extraction module, which is used to extract the leakage frequency, total leakage amount, and leakage location in the memory leak data as key information and generate a memory leak data report; A memory display module, which is used to display the memory usage amount and leakage mode through a graphical interface.
[0114] As Figure 4 shown, the present application also provides an electronic device, including a display module 103, a memory 102, a processor 101, and a computer program stored on the memory and executable on the processor 101. When the processor 101 executes the program, the steps of the memory leak detection and analysis method are implemented.
[0115] In the embodiments of the present invention, the electronic device includes, but is not limited to, a laptop computer, a desktop computer, a workbench, a personal digital assistant, a server, a blade server, a mainframe computer, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as, a personal digital processor, a cellular phone, a smart phone, a wearable device, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the embodiments of the present application described herein and / or claimed.
[0116] In the embodiments of the present application, the processor 101 can be implemented by using at least one of an application specific integrated circuit (ASIC), a programmable logic device (PLD), a field programmable gate array (FPGA), a processor, a controller, a microcontroller, a microprocessor, and an electronic unit designed to execute the functions described herein. In some cases, such an implementation can be implemented in a controller. For a software implementation, an implementation of a process or function can be implemented with a separate software module that allows execution of at least one function or operation. The software code can be implemented by a software application (or program) written in any suitable programming language. The software code can be stored in a memory and executed by a controller.
[0117] The display module 103 is used to display information input by the user or information provided to the user. The display module 103 may include a display panel, and the display panel may be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), or the like.
[0118] The memory 102 can be used to store software programs and various data. The memory 102 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0119] The present application also provides a storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the memory leak detection and analysis method are implemented.
[0120] The storage medium can be any combination of one or more readable media. The readable media can be a readable signal medium or a readable storage medium. The readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples (a non-exhaustive list) of the readable storage medium include: an electrical connection having one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0121] The foregoing description of the disclosed embodiments enables those skilled in the art to practice or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A memory leak detection and analysis method, characterized in that: Methods include: Get and save application-based memory usage data; Defining a set including a plurality of memory analysis modules, loading the memory analysis modules and displaying them on a first graphical interface; Customize the selection based on the attribute information of the memory to be detected and select multiple target memory leak execution modules; Based on the selected memory detection process triggered by the target memory leak execution module, the corresponding target memory leak analysis subprocess is obtained, and the execution order between the target memory leak execution modules is determined through the execution order configuration operation; Merge multiple target memory leak analysis sub-processes in this order to generate a target memory leak analysis process to be executed, so as to detect the memory according to the memory leak analysis instruction and identify the memory leak location and memory leak data; Extract the leakage frequency, total leakage amount, and leakage location from the memory leakage data as key information and generate a memory leakage data report; Graphical display of memory usage and leak patterns.
2. The memory leak detection and analysis method according to claim 1, characterized in that: Define a memory analysis module set, where the memory analysis module set includes multiple memory analysis modules; Based on the custom selection triggered by the memory analysis module set, multiple target memory leak execution modules are selected.
3. The memory leak detection and analysis method according to claim 2, characterized in that: Based on the selected memory detection process triggered by multiple target memory leak execution modules, the target memory leak analysis sub-process corresponding to the target memory leak analysis task represented by each of the multiple target memory leak execution modules is obtained, and based on the execution order configuration operation triggered by the multiple target memory leak execution modules, the execution order between the multiple target memory leak execution modules is determined; According to the execution order, multiple target memory leak analysis sub-processes are merged to generate a target memory leak analysis process to be executed, and the memory is detected.
4. The memory leak detection and analysis method according to claim 1, characterized in that: Determine the target memory leak analysis task represented by the target memory leak execution module and the target memory leak analysis task corresponding to the target memory leak detection template file according to the correspondence between the preset memory leak analysis task and the memory detection template file; Based on the editing operation of the target memory detection template file, the memory leak analysis subprocess generated by the editing is used as the memory leak analysis subprocess associated with the target memory leak analysis task.
5. The memory leak detection and analysis method according to claim 4, characterized in that: Based on the edit operation of the analyzed memory leak analysis sub-process, determine the edited memory leak analysis sub-process; The edited memory leak analysis subprocess is used as the memory leak analysis subprocess associated with the target memory leak analysis task.
6. The memory leak detection and analysis method according to claim 1, characterized in that: According to the correspondence between the preset memory detection template file and the memory leak analysis test process template, determine the target memory leak analysis test process template corresponding to the target memory detection template file represented by the target memory leak execution module; A memory leak analysis test process generated based on the editing operation of the target memory leak analysis test process template is used as the memory leak analysis test process corresponding to the memory leak analysis subprocess associated with the target memory leak analysis task; Based on the editing operation of the memory leak analysis test process analyzed by other methods, determine the edited memory leak analysis test process; The edited memory leak analysis test process is used as the memory leak analysis test process corresponding to a memory leak analysis sub-process associated with the target memory leak analysis task.
7. The memory leak detection and analysis method according to claim 1, characterized in that: Receive memory leak analysis instructions; Determine the target memory leak analysis process corresponding to the attribute information of the memory to be analyzed according to the correspondence between the attribute information of each object and the memory leak analysis process saved in advance; Run the target memory leak analysis process to detect the memory.
8. A memory leak detection and analysis system, characterized in that: The system is used to implement the memory leak detection and analysis method as described in any one of claims 1 to 7; The system includes: A data acquisition module, used to acquire and save application-based memory usage data; An analysis and display module, used to define a set including multiple memory analysis modules, load the memory analysis modules and display them on a first graphical interface; The information selection module performs customized selection based on the attribute information of the memory to be detected and selects multiple target memory leak execution modules; An execution order configuration module, based on the selected memory detection process triggered by the target memory leak execution module, obtains the corresponding target memory leak analysis subprocess, and determines the execution order between the target memory leak execution modules through the execution order configuration operation; A memory detection module is used to merge multiple target memory leak analysis sub-processes in this order to generate a target memory leak analysis process to be executed, so as to detect the memory according to the memory leak analysis instruction and identify the memory leak location and memory leak data; The information extraction module is used to extract the leakage frequency, total leakage amount, and leakage location from the memory leakage data as key information and generate a memory leakage data report; The memory display module is used to display memory usage and leakage patterns through a graphical interface.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the steps of the memory leak detection and analysis method as described in any one of claims 1 to 7 are implemented.
10. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the memory leak detection and analysis method according to any one of claims 1 to 7 are implemented.