Memory leak detection method, device, computer equipment and storage medium
By receiving memory processing instructions input by users and obtaining memory block processing times, identifying memory attribute information, calculating the total memory amount, and detecting memory leaks, the memory leak problem is solved, and the memory leak detection problem is achieved in embedded operating systems, and fast and accurate memory leak detection and Positioning improves system stability and debugging efficiency.
Patent Information
- Application Number
- CN202410986777.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-23
- Publication Date
- 2024-11-22
- Estimated Expiration
- 2044-07-23
AI Technical Summary
In embedded operating systems, existing memory leak detection tools lack support for RTOS, making it difficult to detect and accurately locate memory leaks in advance, affecting debugging efficiency and system stability, and the existing methods have high complexity and poor applicability.
Provide a memory leak detection method, by receiving memory processing instructions input by the user, obtaining the number of target memory block processing times in the preset historical time, identifying memory attribute information, determining the target memory to be processed, calculating the total memory amount, and tracing the information. Update memory processing data tables, detect memory leaks, and quickly and accurately determine the location of memory leaks.
It improves the efficiency and accuracy of memory leak detection, is highly applicable, simplifies the memory leak detection process, and avoids the problems of memory waste and improper resource utilization.
Smart Images

Figure CN118519917B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of memory leak detection, and in particular to a memory leak detection method, device, computer equipment and storage medium. Background Art
[0002] In embedded operating systems, resources are very limited, and memory leaks may cause problems such as system stability, memory resource waste, and security. Most of the current memory leak detection tools lack support for RTOS. If there is a memory leak, it is often difficult to detect it in advance and it is difficult to accurately locate the location of the memory leak. This will seriously affect the debugging efficiency and system stability of embedded projects based on RTOS.
[0003] Most of the memory leak detection methods in the prior art are complex to implement and have poor applicability. Therefore, how to quickly and accurately detect memory leaks has become an urgent problem to be solved. Summary of the invention
[0004] In view of this, the present invention provides a memory leak detection method, apparatus, computer equipment and storage medium to solve the problem of how to quickly and accurately implement memory leak detection.
[0005] In a first aspect, the present invention provides a memory leak detection method, the method comprising:
[0006] Receive memory processing instructions input by the user;
[0007] According to the memory processing instruction, the target memory to be processed is processed;
[0008] Obtain the number of times a target memory block corresponding to the target memory to be processed is processed within a preset historical time;
[0009] According to the processing times of the target memory block corresponding to the target memory to be processed, it is detected whether a memory leak occurs in the target memory block.
[0010] The memory leak detection method provided in the embodiment of the present application receives a memory processing instruction input by a user;
[0011] According to the memory processing instruction, the target memory to be processed is processed, ensuring the accuracy of the processing of the target memory to be processed. The number of processing times of the target memory block corresponding to the target memory to be processed within the preset historical time is obtained, and according to the number of processing times of the target memory block corresponding to the target memory to be processed, whether the target memory block has a memory leak is detected, so that it can be simply and quickly determined whether the target memory to be processed has a memory leak, and the accuracy of the determined result is guaranteed. The efficiency of confirming whether the target memory has a leak is improved, and the applicability is strong.
[0012] In an optional implementation, processing the target memory to be processed according to the memory processing instruction includes:
[0013] Identify the memory processing instruction and determine the memory attribute information included in the memory processing instruction;
[0014] Determine the target memory to be processed according to the memory attribute information;
[0015] According to the memory processing instruction, the target memory to be processed is processed.
[0016] The memory leak detection method provided in the embodiment of the present application identifies the memory processing instruction, determines the memory attribute information included in the memory processing instruction, and ensures the accuracy of the memory attribute information included in the determined memory processing instruction. According to the memory attribute information, the target memory to be processed is determined, the accuracy of the determined target memory to be processed is ensured, and the target memory to be processed is processed according to the memory processing instruction. It avoids the inaccuracy of the determined target memory to be processed, resulting in errors in the processing of the target memory to be processed.
[0017] In an optional implementation, the memory processing instruction includes a memory application instruction, and the memory attribute information includes an amount of memory applied for the memory and first identification information of a first target functional module to which the memory application is applied; and determining the target memory to be processed according to the memory attribute information includes:
[0018] Acquire and store the first identification information and the first occupied memory amount occupied by the applied memory amount;
[0019] The total memory amount corresponding to the target memory to be processed is calculated by adding the applied memory amount to the first occupied memory amount;
[0020] The target memory to be processed is determined based on the total memory amount.
[0021] The memory leak detection method provided in the embodiment of the present application obtains the first occupied memory amount occupied by the first identification information and the applied memory amount, ensuring that the first occupied memory amount obtained is not too large to cause memory waste, nor too small to cause the two values of the first identification information and the applied memory amount to be unable to be stored, thereby ensuring the accuracy of the first occupied memory amount obtained. The total memory amount corresponding to the target memory to be processed is calculated by adding the applied memory amount to the first occupied memory amount, ensuring the accuracy of the calculated total memory amount corresponding to the target memory to be processed, ensuring that the memory space is not wasted, and ensuring that the memory space is sufficient. The target memory to be processed is determined based on the total memory amount, ensuring the accuracy of the determined target memory to be processed.
[0022] In an optional implementation, processing the target memory to be processed according to the memory processing instruction includes:
[0023] Obtaining a first storage start address corresponding to the target memory to be processed;
[0024] According to the first storage start address, storing the first identification information and the requested memory amount;
[0025] Determine the storage end address corresponding to the storage of the first identification information and the memory amount applied;
[0026] Determine the storage end address as the second storage start address;
[0027] The second storage start address is returned to the user to satisfy the memory processing instruction.
[0028] The memory leak detection method provided in the embodiment of the present application obtains the first storage start address corresponding to the target memory to be processed; based on the first storage start address, the first identification information and the requested memory amount are stored, thereby ensuring the accuracy of storing the first identification information and the requested memory amount, so that the memory amount requested by the memory processing instruction input by the user can be traced based on the stored first identification information and the requested memory amount, and then, based on the tracing result, it is possible to detect whether a memory leak occurs in the target memory to be processed. Determine the storage end address corresponding to the storage of the first identification information and the requested memory amount, and determine the storage end address as the second storage start address, thereby ensuring the accuracy of the determined second storage start address. Return the second storage start address to the user, so that the user can start storing data from the second storage start address, thereby satisfying the memory processing instruction.
[0029] In an optional implementation, after returning the second storage start address to the user to satisfy the memory processing instruction, the method further includes:
[0030] Get the memory processing data table;
[0031] Searching the memory processing data table for a first currently occupied memory amount corresponding to the first identification information;
[0032] According to the requested memory amount, update the first currently occupied memory amount;
[0033] The number of applications corresponding to the first identification information is increased by 1.
[0034] The memory leak detection method provided by the embodiment of the present application obtains a memory processing data table; searches for the first currently occupied memory amount corresponding to the first identification information in the memory processing data table; updates the first currently occupied memory amount according to the application memory amount, thereby ensuring the accuracy of the updated first currently occupied memory amount. The number of applications corresponding to the first identification information is increased by 1, thereby ensuring the accuracy of the number of applications corresponding to the first identification information recorded in the memory processing data table.
[0035] In an optional implementation, the memory processing instruction includes a memory release instruction, and the memory attribute information includes a third storage start address corresponding to the memory to be released; and determining the target memory to be processed according to the memory attribute information includes:
[0036] Acquire and store the second identification information and the second occupied memory amount occupied by the released memory amount; the second identification information is the identification information of the second target functional module corresponding to the memory to be released, and the released memory amount is the released memory amount corresponding to the memory to be released;
[0037] The fourth storage start address corresponding to the target memory to be processed is calculated by subtracting the second occupied memory amount from the third storage start address;
[0038] The target memory to be processed is determined according to the fourth storage start address, the second occupied memory amount, and the released memory amount.
[0039] The memory leak detection method provided in the embodiment of the present application obtains the second occupied memory amount occupied by the second storage identification information and the released memory amount, thereby ensuring the accuracy of the determined second occupied memory amount. The fourth storage starting address corresponding to the target memory to be processed is calculated by subtracting the second occupied memory amount from the third storage starting address, thereby ensuring the accuracy of the calculated fourth storage starting address corresponding to the target memory to be processed. The target memory to be processed is determined based on the fourth storage starting address, the second occupied memory amount, and the released memory amount, thereby ensuring the accuracy of the determined target memory to be processed.
[0040] In an optional implementation, processing the target memory to be processed according to the memory processing instruction includes:
[0041] According to the fourth storage start address, searching for the second identification information and releasing the memory amount;
[0042] Cache the second identification information and the amount of released memory into a local variable;
[0043] Releases the memory in the target memory block.
[0044] The memory leak detection method provided in the embodiment of the present application searches for the second identification information and the amount of released memory according to the fourth storage start address, thereby ensuring the accuracy of the second identification information and the amount of released memory found. The second identification information and the amount of released memory are cached in a local variable, thereby avoiding the loss of the second identification information and the amount of released memory, and then the memory in the target memory block is released, thereby completing the memory release instruction.
[0045] In an optional implementation, after releasing the memory in the target memory block, the method further includes:
[0046] Get the memory processing data table;
[0047] Searching the memory processing data table for a second currently occupied memory amount corresponding to the second identification information;
[0048] According to the released memory amount, update the second currently occupied memory amount;
[0049] The number of releases corresponding to the second identification information is increased by 1.
[0050] The memory leak detection method provided in the embodiment of the present application obtains a memory processing data table; searches for the second currently occupied memory amount corresponding to the second identification information in the memory processing data table, thereby ensuring the accuracy of the second currently occupied memory amount corresponding to the found second identification information. The second currently occupied memory amount is updated according to the released memory amount, thereby ensuring the accuracy of the updated second currently occupied memory amount. The number of releases corresponding to the second identification information is increased by 1, thereby ensuring the accuracy of the number of releases corresponding to the second identification information recorded in the memory processing data table.
[0051] In an optional implementation, the number of processing times includes the number of times applied and the number of times released; detecting whether a memory leak occurs in the target memory block according to the number of times the target memory block corresponding to the target memory to be processed includes:
[0052] Get the number of times the target memory block corresponding to the target memory to be processed is applied and released;
[0053] Detect whether a memory leak occurs in the target memory block based on the number of times it is allocated and released.
[0054] The memory leak detection method provided in the embodiment of the present application obtains the number of times a target memory block corresponding to the target memory to be processed is applied and released; based on the number of times an application is made and the number of times an release is made, it detects whether a memory leak occurs in the target memory block, thereby ensuring the accuracy of determining whether a memory leak occurs in the target memory to be processed.
[0055] In an optional implementation, detecting whether a target memory block has a memory leak according to the number of times it is applied and the number of times it is released includes:
[0056] Subtract the number of releases from the number of applications to get the difference.
[0057] If the difference in times is greater than 0, determine whether there is a thread currently occupying the target memory block and running;
[0058] If there is no thread currently occupying the target memory block and running, it is determined that a memory leak occurs in the target memory block.
[0059] The memory leak detection method provided in the embodiment of the present application uses the number of times applied for minus the number of times released to obtain the number difference, thereby ensuring the accuracy of the obtained number difference. If the number difference is greater than 0, it is determined whether there is a thread currently occupying the target memory block and running. If there is no thread currently occupying the target memory block and running, it is determined that a memory leak occurs in the target memory block, thereby ensuring the accuracy of the result of determining that a memory leak occurs in the target memory to be processed.
[0060] In an optional implementation, after determining that a memory leak occurs in the target memory block, the method further includes:
[0061] Get each historical function module that occupies the target memory block within the preset historical time;
[0062] Check whether each historical function module releases the memory in the target memory block after running;
[0063] If there is a historical function module that does not release the memory in the target memory block after running, the historical function module that does not release the memory in the target memory block is determined to be the memory leak location corresponding to the target memory block.
[0064] The memory leak detection method provided in the embodiment of the present application obtains each historical function module that occupies the target memory block within a preset historical time; detects whether each historical function module releases the memory in the target memory block after running; if there is a historical function module that does not release the memory in the target memory block after running, the historical function module that does not release the memory in the target memory block is determined to be the memory leak location corresponding to the target memory block, thereby accurately and quickly determining the memory leak location corresponding to the target memory block.
[0065] In an optional embodiment, the method further includes:
[0066] If the difference in the number of times is equal to 0, it is determined that no memory leak occurs in the target memory block.
[0067] In the memory leak detection method provided in the embodiment of the present application, if the difference in the number of times is equal to 0, it is determined that no memory leak occurs in the target memory block, thereby ensuring the accuracy of the result that no memory leak occurs in the determined target memory block.
[0068] In an optional embodiment, the method further includes:
[0069] If there are currently running threads occupying the target memory to be processed, and the number of threads is consistent with the difference in times, it is determined that no memory leak occurs in the target memory block.
[0070] The memory leak detection method provided in the embodiment of the present application determines that no memory leak occurs in the target memory block if there are currently running threads occupying the target memory to be processed and the number of threads is consistent with the difference in the number of times, thereby ensuring the accuracy of the result that no memory leak occurs in the determined target memory block.
[0071] In a second aspect, the present invention provides a memory leak detection device, the device comprising:
[0072] A receiving module, used for receiving a memory processing instruction input by a user;
[0073] A processing module, used for processing a target memory to be processed according to a memory processing instruction;
[0074] An acquisition module, used to acquire the number of processing times of a target memory block corresponding to the target memory to be processed within a preset historical time;
[0075] The detection module is used to detect whether a memory leak occurs in the target memory block according to the number of processing times of the target memory block corresponding to the target memory to be processed.
[0076] The memory leak detection device provided in the embodiment of the present application receives a memory processing instruction input by a user;
[0077] According to the memory processing instruction, the target memory to be processed is processed, ensuring the accuracy of the processing of the target memory to be processed. The number of processing times of the target memory block corresponding to the target memory to be processed within the preset historical time is obtained, and according to the number of processing times of the target memory block corresponding to the target memory to be processed, whether the target memory block has a memory leak is detected, so that it can be simply and quickly determined whether the target memory to be processed has a memory leak, and the accuracy of the determined result is guaranteed. The efficiency of confirming whether the target memory has a leak is improved, and the applicability is strong.
[0078] In a third aspect, the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the memory leak detection method of the first aspect or any corresponding embodiment thereof by executing the computer instructions.
[0079] In a fourth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the memory leak detection method of the first aspect or any corresponding embodiment thereof.
[0080] In a fifth aspect, the present invention provides a computer program product, comprising computer instructions, wherein the computer instructions are used to enable a computer to execute the memory leak detection method of the first aspect or any corresponding embodiment thereof. BRIEF DESCRIPTION OF THE DRAWINGS
[0081] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0082] Figure 1 is a flowchart of a memory leak detection method according to an embodiment of the present invention;
[0083] Figure 2 is a flow chart of another memory leak detection method according to an embodiment of the present invention;
[0084] Figure 3 is a flowchart of another memory leak detection method according to an embodiment of the present invention;
[0085] Figure 4 is a schematic diagram of a software framework of a memory leak detection method according to an embodiment of the present invention;
[0086] Figure 5 is a schematic diagram of a memory application processing flow according to an embodiment of the present invention;
[0087] Figure 6 is a schematic diagram of a memory release process according to an embodiment of the present invention;
[0088] Figure 7 is a schematic diagram of a process for storing module memory information according to an embodiment of the present invention;
[0089] Figure 8 is a schematic diagram of an application scenario of memory leak detection according to an embodiment of the present invention;
[0090] Fig. 9 is a structural block diagram of a memory leak detection device according to an embodiment of the present invention;
[0091] Fig.10 It is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0092] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0093] In embedded operating systems, resources are very limited, and memory leaks may cause problems such as system stability, memory resource waste, and security. Most of the current memory leak detection tools lack support for RTOS. If there is a memory leak, it is often difficult to detect it in advance and it is difficult to accurately locate the location of the memory leak. This will seriously affect the debugging efficiency and system stability of embedded projects based on RTOS.
[0094] The first similar technology detects memory leaks by managing user memory through circular queues and linked lists and scanning them regularly. Although this method can detect whether the system has sent a memory leak, it takes a lot of time to traverse the linked list when managing memory detection through queues and linked lists, that is, the time complexity is high. And after the memory leak is found, it is impossible to quickly and accurately find the location of the module or code segment of the memory leak. The second related technology tracks the memory usage by recording logs when applying for memory release, and then uses the TCP network protocol to transfer the logs to the host computer, and the host computer parses and compares the logs to determine whether there is a memory leak. Although this method can accurately record each memory application release record, it requires a large amount of memory space to store the logs, and needs to be uploaded to the host computer for analysis via TCP, which is more complex to implement. It is not suitable for projects with limited system resources (memory, CPU, etc.) or that do not support TCP.
[0095] Therefore, most of the memory leak detection methods in the related art have high implementation complexity and poor applicability. Therefore, how to quickly and accurately detect memory leaks has become an urgent problem to be solved.
[0096] It should be noted that the execution subject of the memory leak detection method provided in the embodiment of the present application can be a memory leak detection device, and the memory leak detection device can be implemented as part or all of a computer device through software, hardware, or a combination of software and hardware, wherein the computer device can be a server or a terminal, wherein the server in the embodiment of the present application can be a single server or a server cluster composed of multiple servers, and the terminal in the embodiment of the present application can be a smart phone, a personal computer, a tablet computer, a wearable device, and other smart hardware devices such as an intelligent robot. In the following method embodiments, the execution subject is an electronic device as an example for explanation.
[0097] According to an embodiment of the present invention, a memory leak detection method embodiment is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0098] In this embodiment, a memory leak detection method is provided, which can be used in the above electronic device. Figure 1 is a flowchart of a memory leak detection method according to an embodiment of the present invention. Figure 1 As shown, the process includes the following steps:
[0099] Step S101, receiving a memory processing instruction input by a user.
[0100] Specifically, the electronic device may receive a memory processing instruction input by a user, and the memory processing instruction may be for a functional module to apply for memory or release memory. The embodiment of the present application does not specifically limit the memory processing instruction.
[0101] Step S102: Process the target memory to be processed according to the memory processing instruction.
[0102] Specifically, the electronic device can determine the target memory to be processed according to the memory processing instruction, and then process the target memory to be processed according to the instruction content.
[0103] This step will be described in detail below.
[0104] Step S103, obtaining the number of times the target memory block corresponding to the target memory to be processed is processed within a preset historical time.
[0105] Specifically, the electronic device may record the number of processing times after processing the target memory to be processed each time, thereby obtaining the number of processing times of the target memory block corresponding to the target memory to be processed within a preset historical time according to the recording result of the number of processing times.
[0106] Among them, the preset historical time can be a time within one hour before the current time, a time within two hours before the current time, or other time periods. The embodiment of the present application does not specifically limit the preset historical time.
[0107] Step S104, detecting whether a memory leak occurs in the target memory block according to the number of processing times of the target memory block corresponding to the target memory to be processed.
[0108] Specifically, the electronic device may detect whether a memory leak occurs in the target memory block according to the number of times the target memory block corresponding to the target memory to be processed is processed.
[0109] This step will be described in detail below.
[0110] The memory leak detection method provided in the embodiment of the present application receives a memory processing instruction input by a user;
[0111] According to the memory processing instruction, the target memory to be processed is processed, ensuring the accuracy of the processing of the target memory to be processed. The number of processing times of the target memory block corresponding to the target memory to be processed within the preset historical time is obtained, and according to the number of processing times of the target memory block corresponding to the target memory to be processed, whether the target memory block has a memory leak is detected, so that it can be simply and quickly determined whether the target memory to be processed has a memory leak, and the accuracy of the determined result is guaranteed. The efficiency of confirming whether the target memory has a leak is improved, and the applicability is strong.
[0112] In this embodiment, a memory leak detection method is provided, which can be used in the above electronic device. Figure 2 is a flowchart of a memory leak detection method according to an embodiment of the present invention. Figure 2 As shown, the process includes the following steps:
[0113] Step S201, receiving a memory processing instruction input by a user.
[0114] For details, please see Figure 1 Step S101 of the illustrated embodiment will not be described in detail here.
[0115] Step S202: Process the target memory to be processed according to the memory processing instruction.
[0116] Specifically, the above step S202 includes:
[0117] Step S2021, identifying the memory processing instruction and determining the memory attribute information included in the memory processing instruction.
[0118] Specifically, the electronic device can identify the memory processing instruction and determine the memory attribute information included in the memory processing instruction.
[0119] Step S2022: Determine the target memory to be processed according to the memory attribute information.
[0120] Step S2023, processing the target memory to be processed according to the memory processing instruction.
[0121] In an optional implementation of the present application, the memory processing instruction includes a memory application instruction, and the memory attribute information includes an amount of memory applied for the memory and first identification information of a first target functional module to which the memory application is applied; the above step S2022 "determining the target memory to be processed according to the memory attribute information" includes:
[0122] Step a1, obtaining and storing the first identification information and the first occupied memory amount occupied by the applied memory amount.
[0123] Specifically, the electronic device may calculate the first occupied memory amount occupied by storing the first identification information and the applied memory amount according to the sizes of the two data, the first identification information and the applied memory amount.
[0124] Step a2, using the applied memory amount plus the first occupied memory amount, calculate the total memory amount corresponding to the target memory to be processed.
[0125] Specifically, after calculating the first occupied memory amount, the electronic device can calculate the total memory amount corresponding to the target memory to be processed by adding the applied memory amount to the first occupied memory amount.
[0126] Step a3, determining the target memory to be processed according to the total memory amount.
[0127] Specifically, the electronic device may determine the data offset corresponding to the currently stored data according to the data stored in the current storage device, and then determine the target memory to be processed according to the data offset and the total memory capacity.
[0128] Correspondingly, the above step S2023 "processing the target memory to be processed according to the memory processing instruction" includes:
[0129] Step b1, obtaining the first storage start address corresponding to the target memory to be processed.
[0130] Specifically, the electronic device may determine the first storage start address corresponding to the target memory to be processed according to the data offset corresponding to the currently stored data.
[0131] Step b2: storing the first identification information and the requested memory amount according to the first storage start address.
[0132] Specifically, the electronic device may store the first identification information and the requested memory amount starting from the first storage start address.
[0133] Step b3, determining the storage end address corresponding to storing the first identification information and applying for the memory amount.
[0134] Specifically, the electronic device determines to store the first identification information and applies for a corresponding storage end address after the memory amount is applied.
[0135] Step b4, determining the storage end address as the second storage start address.
[0136] Specifically, the electronic device determines the storage end address as the second storage start address.
[0137] Step b5, returning the second storage start address to the user to satisfy the memory processing instruction.
[0138] Specifically, the electronic device can return the second storage start address to the user, so that the user can store the operating data of the functional module based on the second storage start address, thereby satisfying the memory processing instruction.
[0139] In an optional implementation manner of the present application, the above step b5 may further include the following steps:
[0140] Step b6, obtaining the memory processing data table.
[0141] Specifically, the electronic device can search the memory processing data table from the storage space, wherein the memory processing data table can record the amount of memory currently occupied by each functional module, as well as the number of times each functional module applies for memory and the number of times each functional module releases memory.
[0142] Step b7, searching the memory processing data table for the first currently occupied memory amount corresponding to the first identification information.
[0143] Specifically, the electronic device may search, in the memory processing data table, according to the first identification information, for a first current occupied memory amount occupied by the first target functional module corresponding to the first identification information in the storage device.
[0144] Step b8: updating the first currently occupied memory amount according to the requested memory amount.
[0145] Specifically, the electronic device may add the first currently occupied memory amount to the requested memory amount to calculate an updated first currently occupied memory amount.
[0146] Step b9, adding 1 to the number of applications corresponding to the first identification information.
[0147] Specifically, the electronic device may also search for the number of applications corresponding to the first identification information in the memory processing data table according to the first identification information, and add 1 to the number of applications corresponding to the first identification information.
[0148] In an optional implementation manner of the present application, the memory processing instruction includes a memory release instruction, and the memory attribute information includes a third storage start address corresponding to the memory to be released; the above step S2022 "determining the target memory to be processed according to the memory attribute information" includes:
[0149] Step c1, obtaining a second occupied memory amount that stores the second identification information and the released memory amount.
[0150] The second identification information is identification information of the second target functional module corresponding to the memory to be released, and the amount of released memory is the amount of released memory corresponding to the memory to be released.
[0151] Specifically, the electronic device may calculate the second occupied memory amount occupied by storing the second identification information and the released memory amount according to the sizes of the two data, the second identification information and the released memory amount.
[0152] Step c2, using the third storage start address minus the second occupied memory amount, calculate and obtain the fourth storage start address corresponding to the target memory to be processed.
[0153] Specifically, the electronic device uses the third storage start address to subtract the second occupied memory amount to calculate a fourth storage start address corresponding to the target memory to be processed.
[0154] Among them, the fourth storage starting address is the starting address corresponding to the target memory to be processed.
[0155] Step c3, determining the target memory to be processed according to the fourth storage start address, the second occupied memory amount and the released memory amount.
[0156] Specifically, the electronic device calculates the total memory amount corresponding to the target memory to be processed by adding the second occupied memory amount to the released memory amount.
[0157] The electronic device determines the target memory to be processed according to the fourth storage start address and the total memory capacity.
[0158] Correspondingly, the above step S2023 "processing the target memory to be processed according to the memory processing instruction" includes:
[0159] Step d1, searching for the second identification information and releasing the memory amount according to the fourth storage start address.
[0160] Specifically, the electronic device may use the fourth storage start address to search for the second identification information and release the memory amount starting from the fourth storage start address.
[0161] Step d2: Cache the second identification information and the amount of released memory into a local variable.
[0162] Specifically, the electronic device may cache the second identification information and the amount of released memory into local variables.
[0163] Step d3, release the memory in the target memory block.
[0164] Specifically, the electronic device releases the target memory to be processed.
[0165] In an optional implementation manner of the present application, the above step d3 may further include the following steps:
[0166] Step d4, obtaining the memory processing data table.
[0167] Specifically, the electronic device can search the memory processing data table from the storage space, wherein the memory processing data table can record the amount of memory currently occupied by each functional module, as well as the number of times each functional module applies for memory and the number of times each functional module releases memory.
[0168] Step d5, searching the memory processing data table for the second currently occupied memory amount corresponding to the second identification information.
[0169] Specifically, the electronic device may search, in the memory processing data table, according to the second identification information, for a second currently occupied memory amount currently occupied by the second target functional module corresponding to the second identification information in the storage device.
[0170] Step d6: updating the second currently occupied memory amount according to the released memory amount.
[0171] Specifically, the electronic device may update the second currently occupied memory amount by subtracting the second currently occupied memory amount from the second currently occupied memory amount.
[0172] Step d7, adding 1 to the number of release times corresponding to the second identification information.
[0173] Specifically, the electronic device may search the memory processing data table for the release count of the second target functional module corresponding to the second identification information according to the second identification information, and add 1 to the release count of the second target functional module.
[0174] Step S203, obtaining the number of times the target memory block corresponding to the target memory to be processed within a preset historical time is processed.
[0175] For more information about this step, see Figure 1 The introduction of step S103 is not repeated here.
[0176] Step S204, detecting whether a memory leak occurs in the target memory block according to the number of processing times of the target memory block corresponding to the target memory to be processed.
[0177] For more information about this step, see Figure 1 The introduction of step S104 is not repeated here.
[0178] The memory leak detection method provided in the embodiment of the present application identifies memory processing instructions and determines memory attribute information included in the memory processing instructions.
[0179] In an optional implementation, the memory processing instruction includes a memory application instruction, and the memory attribute information includes the application memory amount corresponding to the application memory and the first identification information of the first target functional module to which the application memory is applied. The first occupied memory amount occupied by the first identification information and the application memory amount is obtained to ensure that the first occupied memory amount obtained will not be too large to cause memory waste, nor too small to store the first identification information and the application memory amount, thereby ensuring the accuracy of the first occupied memory amount obtained. The total memory amount corresponding to the target memory to be processed is calculated by adding the application memory amount to the first occupied memory amount, thereby ensuring the accuracy of the calculated total memory amount corresponding to the target memory to be processed, and both ensuring that the memory space is not wasted and that the memory space is sufficient. The target memory to be processed is determined according to the total memory amount, thereby ensuring the accuracy of the determined target memory to be processed. The first storage start address corresponding to the target memory to be processed is obtained; according to the first storage start address, the first identification information and the application memory amount are stored, thereby ensuring the accuracy of storing the first identification information and the application memory amount, thereby tracing the memory amount requested by the memory processing instruction input by the user according to the stored first identification information and the application memory amount, and then detecting whether a memory leak occurs in the target memory to be processed according to the tracing result. Determine the storage end address corresponding to the storage of the first identification information and the amount of memory applied, and determine the storage end address as the second storage start address, thereby ensuring the accuracy of the determined second storage start address. Return the second storage start address to the user, so that the user can start storing data from the second storage start address, thereby satisfying the memory processing instruction. Then, obtain the memory processing data table; search the memory processing data table for the first current occupied memory amount corresponding to the first identification information; update the first current occupied memory amount according to the amount of memory applied, thereby ensuring the accuracy of the updated first current occupied memory amount. Add 1 to the number of applications corresponding to the first identification information, thereby ensuring the accuracy of the number of applications corresponding to the first identification information recorded in the memory processing data table.
[0180] In another optional implementation, the memory processing instruction includes a memory release instruction, and the memory attribute information includes a third storage start address corresponding to the memory to be released. The second occupied memory amount occupied by the second identification information and the released memory amount is obtained; the accuracy of the determined second occupied memory amount is ensured. The fourth storage start address corresponding to the target memory to be processed is calculated by subtracting the second occupied memory amount from the third storage start address; the accuracy of the calculated fourth storage start address corresponding to the target memory to be processed is ensured. The target memory to be processed is determined according to the fourth storage start address, the second occupied memory amount and the released memory amount, and the accuracy of the determined target memory to be processed is ensured. Then, according to the fourth storage start address, the second identification information and the released memory amount are searched, and the accuracy of the found second identification information and the released memory amount is ensured. The second identification information and the released memory amount are cached to a local variable, so as to avoid the loss of the second identification information and the released memory amount, and then, the memory in the target memory block is released, thereby completing the memory release instruction. Then, a memory processing data table is obtained; the second current occupied memory amount corresponding to the second identification information is searched in the memory processing data table, and the accuracy of the second current occupied memory amount corresponding to the found second identification information is ensured. According to the released memory amount, the second currently occupied memory amount is updated to ensure the accuracy of the updated second currently occupied memory amount. The release times corresponding to the second identification information are increased by 1 to ensure the accuracy of the release times corresponding to the second identification information recorded in the memory processing data table.
[0181] According to an embodiment of the present invention, a memory leak detection method embodiment is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0182] In this embodiment, a memory leak detection method is provided, which can be used in the above electronic device. Figure 3 is a flowchart of a memory leak detection method according to an embodiment of the present invention. Figure 3 As shown, the process includes the following steps:
[0183] Step S301, receiving a memory processing instruction input by a user.
[0184] For details, please see Figure 2 Step S201 of the illustrated embodiment will not be described in detail here.
[0185] Step S302: Process the target memory to be processed according to the memory processing instruction.
[0186] For details, please see Figure 2Step S202 of the illustrated embodiment will not be described in detail here.
[0187] Step S303, obtaining the number of times the target memory block corresponding to the target memory to be processed within a preset historical time is processed.
[0188] For details, please see Figure 2 Step S203 of the illustrated embodiment will not be described in detail here.
[0189] Step S304: Detect whether a memory leak occurs in the target memory block according to the number of processing times of the target memory block corresponding to the target memory to be processed.
[0190] Specifically, the number of processing times includes the number of applications and the number of releases; the above step S304 may include the following steps:
[0191] Step S3041, obtaining the number of times the target memory block corresponding to the target memory to be processed is applied and released.
[0192] Specifically, the electronic device can search the memory processing data table from the storage space, wherein the memory processing data table can record the application times and release times corresponding to each memory.
[0193] The electronic device searches the memory processing data table for the number of applications and the number of releases corresponding to the target memory block according to the identification information corresponding to the target memory block.
[0194] Step S3042: Detect whether a memory leak occurs in the target memory block according to the number of times it is applied and the number of times it is released.
[0195] Specifically, the above step S3042 may include the following steps:
[0196] Step e1, subtract the number of times released from the number of times applied for to obtain the difference in times.
[0197] Specifically, the electronic device subtracts the number of released times from the number of applied times to obtain the difference in times.
[0198] Step e2: If the number difference is equal to 0, it is determined that no memory leak occurs in the target memory block.
[0199] Specifically, if the number difference is equal to 0, the electronic device determines that no memory leak occurs in the target memory block.
[0200] Step e3: If the number difference is greater than 0, determine whether there is a thread that currently occupies the target memory block and is running.
[0201] Specifically, if the number difference is greater than 0, the electronic device determines whether there is a thread that currently occupies the target memory block and is running.
[0202] Step e4: If there is no thread currently occupying the target memory block and running, it is determined that a memory leak occurs in the target memory block.
[0203] Specifically, if there is no thread currently occupying the target memory block and running, it is determined that a memory leak occurs in the target memory block.
[0204] Step e5, obtaining each historical function module occupying the target memory block within a preset historical time.
[0205] Specifically, the electronic device may search the memory processing data table for each historical function module that occupies the target memory block within a preset historical time.
[0206] Step e6, detecting whether each historical function module releases the memory in the target memory block after the execution is completed.
[0207] Specifically, the electronic device detects whether each historical function module releases the memory in the target memory block after the operation is completed, according to the situations in which each historical function module requests the memory during the operation and releases the memory after the operation is completed.
[0208] Step e7: if there is a historical function module that does not release the memory in the target memory block after running, then determine the historical function module that does not release the memory in the target memory block as the memory leak location corresponding to the target memory block.
[0209] Specifically, if there is a historical function module that does not release the memory in the target memory block after running, the historical function module that does not release the memory in the target memory block is determined as the memory leak location corresponding to the target memory block.
[0210] Step e8: If there are currently running threads occupying the target memory to be processed, and the number of threads is consistent with the difference in times, it is determined that no memory leak occurs in the target memory block.
[0211] Specifically, if there are currently running threads occupying the target memory to be processed, and the number of threads is consistent with the difference in times, it is determined that no memory leak occurs in the target memory block.
[0212] The memory leak detection method provided in this embodiment obtains the number of times the target memory block corresponding to the target memory to be processed is applied and released; based on the number of times applied and released, detects whether a memory leak occurs in the target memory block, thereby ensuring the accuracy of determining whether a memory leak occurs in the target memory to be processed. The number of times is subtracted from the number of times released to obtain the number difference, thereby ensuring the accuracy of the obtained number difference. If the number difference is greater than 0, it is determined whether there is a thread currently occupying the target memory block and running. If there is no thread currently occupying the target memory block and running, it is determined that a memory leak occurs in the target memory block, thereby ensuring the accuracy of the result of determining that a memory leak occurs in the target memory to be processed. Obtain each historical function module that occupies the target memory block within a preset historical time; detect whether each historical function module releases the memory in the target memory block after running; if there is a historical function module that does not release the memory in the target memory block after running, it is determined that the historical function module that does not release the memory in the target memory block is the memory leak location corresponding to the target memory block, thereby accurately and quickly determining the memory leak location corresponding to the target memory block.
[0213] If the number difference is equal to 0, it is determined that no memory leak occurs in the target memory block, thereby ensuring the accuracy of the result that no memory leak occurs in the determined target memory block.
[0214] If there are currently running threads occupying the target memory to be processed, and the number of threads is consistent with the difference in times, it is determined that no memory leak occurs in the target memory block, thereby ensuring the accuracy of the result that no memory leak occurs in the determined target memory block.
[0215] In an optional embodiment of the present application, Figure 4 A software framework diagram of a memory leak detection method is provided. Figure 4As shown in the figure, when the user applies for memory, the RTOS memory application interface (malloc) is called to apply for a piece of memory including the information segment and the data segment, data characteristics, and the user's memory application record. Among them, the information segment contains the module index and the size of the data segment, and the data segment is the memory actually applied by the user. After the application is successful, the module memory information of the global data area is updated through the module index, and then the first address of the data segment is returned to the user. When the user releases the memory, the address of the information segment is calculated through the address of the data segment, the data in the information segment is read, and the memory information of the module in the module memory information table is updated through the module index. Then the RTOS memory release interface (free) is called to release the information segment and the data segment. Through the above application and release operations, real-time statistics of the memory information of each module are realized. With the memory application / release information of each module, it is possible to determine whether there is a memory leak by comparing the difference between the application and release before and after the program is executed (or within a period of time). The implementation method is to call the module memory information setting interface at the starting position of the memory leak statistics to record the current memory application and release times of each module. At the end of the statistics, the memory information of all modules is obtained and compared with the memory information saved at the beginning, so that the number of memory applications and releases during this period can be counted. The entire implementation scheme mainly consists of four parts: memory application interface, memory release interface, module memory information storage interface and memory leak judgment interface.
[0216] 1) Application process for memory interface implementation
[0217] like Figure 5 The user application memory interface implementation process shown in the figure has the following steps:
[0218] ① When the user calls the memory application interface, two parameters (information segments) are passed in: the module index and the memory size that the user wants to apply for. The sum of the size of these two parameters and the size of the memory applied for by the user is calculated as the total memory size applied for.
[0219] ② Then call the RTOS memory application interface, and the application size includes two parameters and a total memory block applied by the user. After the application is successful, the operating system memory application interface returns the first address of the data segment of this total memory. By adding the first address of the data segment to the size of the two parameters, the first address of the memory segment applied by the user can be obtained.
[0220] ③ At the same time, copy the two parameters of the module index and memory application size to the information segment of the total memory applied for. Then use the module index to obtain the memory information (number of applications and releases) corresponding to the module in the module information table.
[0221] ④ Add 1 to the number of requests in the memory information, and add the memory occupied by the module to the memory size requested by the user this time.
[0222] ⑤ The above operations complete the memory application and module memory information statistics, and finally return to the first address of the user's requested memory obtained in step ②.
[0223] This memory application interface implementation counts and saves the memory information when the user applies for memory. The information segment is invisible to the user, and the user does not need to pay attention to the memory information statistics process. In addition, the return value of the memory application interface and the operating system memory application is consistent, which will not change the original user's usage habits.
[0224] 2) Release memory interface implementation process
[0225] like Figure 6 The implementation process of the user releasing the memory interface shown in the figure has the following steps:
[0226] ① The user calls the memory release interface and passes in the first address of the memory segment requested by the user.
[0227] ② Obtain the first address of the total memory application by subtracting the size of the information segment from the first address of the memory segment applied by the user, and cache the module index and the size of the memory application in the information segment into local variables.
[0228] ③ Call the RTOS memory release interface to release the total memory including the information segment and data segment.
[0229] ④ Use the module index cached by the local variable to find the memory information of the module in the module memory information table.
[0230] ⑤ Increase the number of releases in the module's memory information by 1, and subtract the user-applied memory size for this release from the memory size currently occupied by the module.
[0231] In this way, each time the user releases memory, the module index and size of the memory requested can be directly obtained without traversing all the requested memory blocks, which greatly reduces the time complexity of table lookup when releasing memory. And when releasing, the user only needs to pass in the parameter of the requested memory address, which is consistent with the commonly used memory release interface parameters.
[0232] 3)Module memory information storage interface
[0233] The memory application and release interface realizes the dynamic statistics of each module information. The current memory usage of each module can be obtained by directly reading the memory information of these modules. However, in actual application, some modules apply for memory during initialization, and they will occupy a piece of applied memory throughout the life cycle of the system. Because there is memory that does not need to be released, the memory usage of these modules cannot only look at the current application / release times. Therefore, it is necessary to save an initial value of the memory usage during initialization after each module is initialized, obtain the current memory usage after running for a period of time, and then compare it with the initial value to check whether there is a memory leak. The present invention realizes a module memory information saving interface. Calling this interface will save the memory application / release times of all modules at that moment into the application / release times record. Figure 7 As shown, it is used as a calculation parameter for memory leak detection.
[0234] 4) Memory leak judgment criteria
[0235] First, calculate the increment of the number of requests / releases for each module:
[0236] Application times increment = current application times – application times record
[0237] Release count increment = current release count – release count record
[0238] Then determine whether there is a memory leak in each module, based on:
[0239] The number of application increments > the number of release increments, indicating a memory leak
[0240] The increment of application times = the increment of release times, there is no memory leak
[0241] If the increment of application times is less than the increment of release times, this phenomenon will not occur.
[0242] 5) Application scenarios of memory leak detection
[0243] Figure 8 The present invention shows a process of checking whether there is a memory leak during the execution of a business program. First, the memory application and release times of all current modules are recorded in the initialization stage, and then the business program is executed. After the execution is completed, the memory application and release times at the end of the execution are obtained, and then the difference between the memory application and release is calculated. By comparing the size of the application and release differences of each module, it is determined whether the module has a memory leak.
[0244] In this embodiment, a memory leak detection device is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0245] This embodiment provides a memory leak detection device, such as Fig. 9 As shown, including:
[0246] The receiving module 401 is used to receive a memory processing instruction input by a user;
[0247] A processing module 402 is used to process the target memory to be processed according to the memory processing instruction;
[0248] The acquisition module 403 is used to acquire the number of times the target memory block corresponding to the target memory to be processed is processed within a preset historical time;
[0249] The detection module 404 is used to detect whether a memory leak occurs in the target memory block according to the number of processing times of the target memory block corresponding to the target memory to be processed.
[0250] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.
[0251] The memory leak detection device in this embodiment is presented in the form of a functional unit, where the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.
[0252] The embodiment of the present invention also provides a computer device having the above Fig.10 The memory leak detection device is shown.
[0253] See also Fig.10 , Fig.10 is a schematic diagram of the structure of a computer device provided by an optional embodiment of the present invention, such as Fig.10As shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process the instructions executed in the computer device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Fig.10 A processor 10 is taken as an example.
[0254] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.
[0255] The memory 20 stores instructions executable by at least one processor 10, so that at least one processor 10 executes the method shown in the above embodiment.
[0256] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0257] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.
[0258] The computer device also includes an input device 30 and an output device 40. The processor 10, the memory 20, the input device 30 and the output device 40 may be connected via a bus or other means. Fig.10 The example of connecting through bus is taken in the following.
[0259] The input device 30 can receive input digital or character information, and generate key signal input related to the user settings and function control of the computer device, such as a touch screen, a keypad, a mouse, a track pad, a touch pad, an indicator bar, one or more mouse buttons, a trackball, a joystick, etc. The output device 40 may include a display device, an auxiliary lighting device (e.g., an LED) and a tactile feedback device (e.g., a vibration motor), etc. The above-mentioned display device includes but is not limited to a liquid crystal display, a light emitting diode, a display and a plasma display. In some optional embodiments, the display device can be a touch screen.
[0260] The embodiment of the present invention also provides a computer-readable storage medium. The method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium through a network download, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.
[0261] A part of the present invention may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present invention through the operation of the computer. Those skilled in the art should understand that the existence of the computer program instruction in a computer-readable medium includes, but is not limited to, a source file, an executable file, an installation package file, etc., and accordingly, the way in which the computer program instruction is executed by the computer includes, but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer-readable medium may be any available computer-readable storage medium or communication medium accessible to the computer.
[0262] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.
Claims
1. A memory leak detection method, characterized in that: The method comprises: Receive memory processing instructions input by the user; According to the memory processing instruction, processing the target memory to be processed; Obtaining the number of times a target memory block corresponding to the target memory to be processed is processed within a preset historical time; Detecting whether a memory leak occurs in the target memory block according to the number of times the target memory block corresponding to the target memory to be processed is processed; The processing times include the application times and the release times; and detecting whether a memory leak occurs in the target memory block according to the processing times of the target memory block corresponding to the target memory to be processed, comprises: Obtaining the number of times the target memory block corresponding to the target memory to be processed is applied and the number of times it is released; Detecting whether a memory leak occurs in the target memory block according to the number of times the target memory block is applied and the number of times the target memory block is released; The detecting whether a memory leak occurs in the target memory block according to the number of times the target memory block is applied and the number of times the target memory block is released comprises: Subtract the number of releases from the number of applications to obtain a difference in number of times; If the number difference is greater than 0, determine whether there is a thread currently occupying the target memory block and running; If there is currently no thread occupying the target memory block and running, it is determined that a memory leak occurs in the target memory block.
2. The method according to claim 1, characterized in that: The processing of the target memory to be processed according to the memory processing instruction includes: Identifying the memory processing instruction and determining memory attribute information included in the memory processing instruction; Determining the target memory to be processed according to the memory attribute information; According to the memory processing instruction, the target memory to be processed is processed.
3. The method according to claim 2, characterized in that The memory processing instruction includes a memory application instruction, the memory attribute information includes an amount of memory applied for the applied memory and first identification information of a first target functional module applying the applied memory; and determining the target memory to be processed according to the memory attribute information includes: Acquire a first occupied memory amount for storing the first identification information and the applied memory amount; The total memory amount corresponding to the target memory to be processed is calculated by adding the applied memory amount to the first occupied memory amount; The target memory to be processed is determined according to the total memory amount.
4. The method according to claim 3, characterized in that The processing of the target memory to be processed according to the memory processing instruction includes: Obtaining a first storage start address corresponding to the target memory to be processed; storing the first identification information and the requested memory amount according to the first storage start address; Determine a storage end address corresponding to storing the first identification information and the requested memory amount; Determining the storage end address as the second storage start address; The second storage start address is returned to the user to satisfy the memory processing instruction.
5. The method according to claim 4, characterized in that After returning the second storage start address to the user to satisfy the memory processing instruction, the method further includes: Get the memory processing data table; Searching the memory processing data table for a first currently occupied memory amount corresponding to the first identification information; According to the applied memory amount, updating the first currently occupied memory amount; The number of applications corresponding to the first identification information is increased by 1.
6. The method according to claim 2, characterized in that The memory processing instruction includes a memory release instruction, and the memory attribute information includes a third storage start address corresponding to the memory to be released; The step of determining the target memory to be processed according to the memory attribute information includes: Acquire and store the second identification information and the second occupied memory amount occupied by the released memory amount; the second identification information is the identification information of the second target functional module corresponding to the memory to be released, and the released memory amount is the released memory amount corresponding to the memory to be released; The fourth storage start address corresponding to the target memory to be processed is calculated by subtracting the second occupied memory amount from the third storage start address; The target memory to be processed is determined according to the fourth storage start address, the second occupied memory amount, and the released memory amount.
7. The method according to claim 6, characterized in that The processing of the target memory to be processed according to the memory processing instruction includes: According to the fourth storage start address, searching for the second identification information and the released memory amount; Cache the second identification information and the released memory amount into a local variable; Releases the memory in the target memory block.
8. The method according to claim 7, characterized in that After releasing the memory in the target memory block, the method further includes: Get the memory processing data table; Searching the memory processing data table for a second currently occupied memory amount corresponding to the second identification information; According to the released memory amount, updating the second currently occupied memory amount; The number of release times corresponding to the second identification information is increased by 1.
9. The method according to claim 1, characterized in that: After determining that a memory leak occurs in the target memory block, the method further includes: Acquire each historical function module occupying the target memory block within the preset historical time; Detecting whether each of the historical function modules releases the memory in the target memory block after running; If there is a historical function module that does not release the memory in the target memory block after running, the historical function module that does not release the memory in the target memory block is determined as the memory leak location corresponding to the target memory block.
10. The method according to claim 1, characterized in that The method further comprises: If the number difference is equal to 0, it is determined that no memory leak occurs in the target memory block.
11. The method according to claim 1, characterized in that: The method further comprises: If there are currently running threads occupying the target memory to be processed, and the number of threads is consistent with the number difference, it is determined that no memory leak occurs in the target memory block.
12. A memory leak detection device, characterized in that: The device comprises: A receiving module, used for receiving a memory processing instruction input by a user; A processing module, used for processing the target memory to be processed according to the memory processing instruction; An acquisition module, used for acquiring the number of times a target memory block corresponding to the target memory to be processed is processed within a preset historical time; A detection module, used for detecting whether a memory leak occurs in the target memory block according to the number of times the target memory block corresponding to the target memory to be processed is processed; wherein the number of times the processing includes the number of times the memory block is applied and the number of times the memory block is released; detecting whether a memory leak occurs in the target memory block according to the number of times the target memory block corresponding to the target memory to be processed is comprised of: obtaining the number of times the memory block is applied and the number of times the memory block is released corresponding to the target memory to be processed; detecting whether a memory leak occurs in the target memory block according to the number of times the memory block is applied and the number of times the memory block is released; detecting whether a memory leak occurs in the target memory block according to the number of times the memory block is applied and the number of times the memory block is released comprises: obtaining a number difference by subtracting the number of times the memory block is released from the number of times the memory block is applied; if the number difference is greater than 0, determining whether there is a thread currently occupying the target memory block and running; if there is no thread currently occupying the target memory block and running, determining that a memory leak occurs in the target memory block.
13. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the memory leak detection method according to any one of claims 1 to 11 by executing the computer instructions.
14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the memory leak detection method according to any one of claims 1 to 11.
15. A computer program product, characterized in that The method comprises computer instructions, wherein the computer instructions are used to cause a computer to execute the memory leak detection method according to any one of claims 1 to 11.
