Abnormal positioning method and device, electronic equipment and computer readable storage medium

By detecting memory allocation thresholds and total amounts when the application starts, and recording detailed information and extracting features only when conditions are met, the problem of difficult memory leak location in mobile applications is solved, improving the effectiveness of memory management and application performance.

CN120950241APending Publication Date: 2025-11-14SHENZHEN TCL DIGITAL TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511048109.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-29
Publication Date
2025-11-14

AI Technical Summary

Technical Problem

In mobile application development, existing technologies make it difficult to effectively locate memory leaks, leading to decreased application performance and system instability. Furthermore, existing methods for obtaining memory allocation data have low validity, impacting performance.

Method used

When the target application starts, obtain the memory allocation threshold and total amount, record memory allocation details only when preset conditions are met, and identify objects with abnormal memory allocation through feature extraction, including configuring custom allocation functions and cache management.

Benefits of technology

It improves the effectiveness of memory allocation information, reduces resource consumption, and enhances application performance and the accuracy of memory leak location.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120950241A_ABST
    Figure CN120950241A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses an anomaly positioning method and device, electronic equipment and a computer readable storage medium, and the method comprises the steps: obtaining a memory allocation threshold value and a total memory allocation amount when a target application is detected to be started, the total memory allocation amount being the sum of the memory allocation capacities of at least one memory allocation object, if the total memory allocation amount and the memory allocation threshold value meet preset conditions, memory allocation detail information of the target application is recorded, the memory allocation detail information comprises memory allocation records for all memory allocation objects, feature extraction is carried out on the memory allocation detail information to obtain allocation feature information, and the allocation feature information is sent to the target application; and determining a target memory allocation object with abnormal memory allocation from at least one memory allocation object according to the allocation feature information. According to the embodiment of the invention, the memory allocation detail information is prevented from being directly recorded when the application is started, the effectiveness of the recorded memory allocation detail information is improved, the occupation of recording related resources is reduced, and the performance of the target application is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of memory management, specifically to an anomaly location method, apparatus, electronic device, and computer-readable storage medium. Background Technology

[0002] With the rapid development of the mobile internet, the number and complexity of mobile applications are constantly increasing, and memory management issues are becoming increasingly prominent. In mobile application development, memory leaks are a common and serious problem, especially native memory leaks. Due to their hidden nature and difficulty in locating them, they often lead to application performance degradation, crashes, or even system instability.

[0003] During application startup, memory allocation is performed. If the application fails to release the allocated memory correctly during runtime, memory usage will continue to increase, leading to memory leaks.

[0004] Currently, there are schemes designed to obtain memory allocation information when an application starts, with the aim of analyzing this information to determine if memory leaks have occurred. However, current methods for obtaining memory allocation information suffer from low data validity and performance issues. Summary of the Invention

[0005] This application provides an anomaly location method, apparatus, electronic device, and computer-readable storage medium, which can improve the effectiveness of acquired memory allocation information and enhance performance.

[0006] This application provides an anomaly localization method, the method comprising:

[0007] Upon detecting the startup of the target application, obtain the memory allocation threshold and the total memory allocation amount, wherein the total memory allocation amount is the sum of the memory allocation capacity of at least one memory allocation object;

[0008] If the total memory allocation and the memory allocation threshold meet the preset conditions, then the memory allocation details of the target application are recorded, including the memory allocation records for each memory allocation object;

[0009] Feature extraction is performed on the memory allocation details to obtain allocation feature information;

[0010] The target memory allocation object with memory allocation anomaly is determined from the at least one memory allocation object based on the allocation feature information.

[0011] Accordingly, this application also provides an anomaly location device, which includes:

[0012] The detection module is used to detect the startup of the target application, obtain the memory allocation threshold and the total memory allocation, wherein the total memory allocation is the sum of the memory allocation capacity of at least one memory allocation object;

[0013] The recording module is used to record memory allocation details of the target application if the total memory allocation amount and the memory allocation threshold meet preset conditions. The memory allocation details include memory allocation records for each memory allocation object.

[0014] The extraction module is used to extract features from the memory allocation details to obtain allocation feature information;

[0015] The determination module is used to determine the target memory allocation object with memory allocation abnormality from the at least one memory allocation object based on the allocation feature information.

[0016] Optionally, in some embodiments of this application, the preset condition includes the total memory allocation exceeding the memory allocation threshold, or the difference between the total memory allocation and the memory allocation threshold exceeding a set threshold;

[0017] If the total memory allocation and the memory allocation threshold meet preset conditions, then the memory allocation details of the target application are recorded, including:

[0018] If the total memory allocation amount and the memory allocation threshold meet the preset conditions, then the allocation record threshold is obtained;

[0019] Obtain the memory allocation capacity of the memory allocation object in a single memory allocation;

[0020] If the memory allocation capacity is greater than or equal to the allocation record threshold, then the memory allocation record for the memory allocation object is recorded;

[0021] The memory allocation details are obtained from the memory allocation records of each memory allocation object.

[0022] Optionally, in some embodiments of this application, the device further includes:

[0023] The allocation quantity is extracted from the memory allocation details information, and the allocation quantity includes the number of memory allocations with the same capacity.

[0024] If the number of allocations is less than the number threshold, the memory allocation threshold is increased by a preset amount to obtain the target allocation threshold.

[0025] Record the new memory allocation details of the target application according to the target allocation threshold;

[0026] Determine new allocation characteristics based on the new memory allocation details;

[0027] The target memory allocation object for the memory allocation anomaly is determined from at least one of the memory allocation objects based on the new allocation characteristic information.

[0028] Optionally, in some embodiments of this application, the step of extracting allocation feature information from the memory allocation details includes:

[0029] The number of times each memory allocation object allocates memory for the same memory allocation capacity is counted, and the number of memory allocations is used as the allocation feature information;

[0030] or,

[0031] The memory allocation capacity of each memory allocation object in a single allocation is calculated, and the memory allocation capacity is used as the allocation feature information.

[0032] Optionally, in some embodiments of this application, determining the target memory allocation object with memory allocation anomalies from the at least one memory allocation object based on the allocation feature information includes:

[0033] The memory allocation object whose memory allocation count exceeds the threshold is selected as the target memory allocation object;

[0034] or,

[0035] The memory allocation object whose memory allocation capacity exceeds the capacity threshold is taken as the target memory allocation object.

[0036] Optionally, in some embodiments of this application, the device further includes:

[0037] Configure a first number of caches, the caches including a target capacity determined based on at least one memory allocation capacity;

[0038] The memory allocation record is recorded through the cache.

[0039] If the first number of caches is full, then a second number of caches is configured, wherein the second number is greater than the first number.

[0040] Optionally, in some embodiments of this application, the device further includes:

[0041] Upon detecting the startup of the target application, a custom allocation function is invoked, and memory allocation is performed on each memory allocation object according to the custom allocation function to obtain the memory allocation capacity corresponding to each memory allocation object;

[0042] Register a first signal function and a second signal function through the custom allocation function; wherein, the first signal function is used to issue a first target signal when the total memory allocation amount and the memory allocation threshold meet preset conditions, wherein, the first target signal is used to indicate the triggering of recording of the memory allocation details;

[0043] The second signal function is used to issue a second target signal when the cache storing the memory allocation details meets the recording conditions, wherein the second target signal is used to instruct the memory allocation details to be saved as a target file and the cache to be cleared;

[0044] The memory allocation record includes at least one of memory address, memory size, or stack information;

[0045] The memory allocation object includes the process of the target application.

[0046] Thirdly, embodiments of this application also provide an electronic device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, it implements the steps in the above-described anomaly location method.

[0047] Fourthly, embodiments of this application also provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps in the above-described anomaly location method.

[0048] Fifthly, embodiments of this application also provide a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the methods provided in the various optional implementations described in embodiments of this application.

[0049] In summary, when the target application is detected to be launched, the embodiments of this application obtain the memory allocation threshold and the total memory allocation. The total memory allocation is the sum of the memory allocation capacity of at least one memory allocation object. If the total memory allocation and the memory allocation threshold meet the preset conditions, the memory allocation details of the target application are recorded. The memory allocation details include memory allocation records for each memory allocation object. The memory allocation details are used to extract features to obtain allocation feature information. Based on the allocation feature information, the target memory allocation object with abnormal memory allocation is determined from at least one memory allocation object.

[0050] Specifically, after the target application starts, memory allocation details are only recorded when the total memory allocation and memory allocation threshold meet preset conditions. This avoids recording memory allocation details directly when the application starts, which helps improve the effectiveness of the recorded memory allocation details, reduces the resource consumption related to recording, and improves the performance of the target application. Attached Figure Description

[0051] To more clearly illustrate the technical solutions in this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0052] Figure 1 This is a schematic diagram of a scenario in which a terminal device, according to an embodiment of this application, executes the anomaly location method;

[0053] Figure 2 This is a flowchart illustrating the anomaly localization method provided in an embodiment of this application;

[0054] Figure 3 This is a schematic diagram of the anomaly location device provided in the embodiments of this application;

[0055] Figure 4 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation

[0056] The technical solutions of this application will now be clearly and completely described with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0057] This application provides an anomaly location method, apparatus, electronic device, and computer-readable storage medium. Specifically, this application provides an anomaly location apparatus suitable for electronic devices, which include terminal devices or servers. The terminal devices include, but are not limited to, mobile phones, tablets, and other devices. The server can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms. The server can be directly or indirectly connected via wired or wireless communication.

[0058] For example, please see Figure 1 , Figure 1 This is a schematic diagram illustrating a scenario in which a terminal device, according to an embodiment of this application, executes the anomaly location method. The process of the server executing the anomaly location method can be understood by referring to the execution process of the terminal device. Specifically, the specific execution process of the terminal device executing the anomaly location method is as follows:

[0059] When the terminal device 10 detects that the target application has started, it obtains the memory allocation threshold and the total memory allocation. The total memory allocation is the sum of the memory allocation capacity of at least one memory allocation object. If the total memory allocation and the memory allocation threshold meet the preset conditions, it records the memory allocation details of the target application. The memory allocation details include the memory allocation records for each memory allocation object. The memory allocation details are used to extract the allocation feature information to obtain allocation feature information. Based on the allocation feature information, the target memory allocation object with abnormal memory allocation is determined from at least one memory allocation object.

[0060] For example, when the target application starts, it allocates memory to memory allocation objects and records the total amount of memory allocated. When the total amount of memory allocated meets the preset conditions of the memory allocation threshold, it records the memory allocation details and extracts the allocation feature information from the memory allocation details to obtain the allocation feature information. Based on the allocation feature information, it identifies the target memory allocation object with abnormal memory allocation from the memory allocation objects.

[0061] In summary, this application embodiment records memory allocation details only after the target application starts, when the total memory allocation amount and memory allocation threshold meet preset conditions. This avoids recording memory allocation details directly when the application starts, which helps improve the effectiveness of the recorded memory allocation details, reduces the resource consumption related to recording, and improves the performance of the target application.

[0062] The following sections provide detailed descriptions of each example. It should be noted that the order in which the embodiments are described is not intended to limit the priority of the embodiments.

[0063] Please see Figure 2 , Figure 2 This is a flowchart illustrating the anomaly localization method provided in this application. Although the flowchart shows a logical order, in some cases, the steps shown or described can be performed in a different order than that shown in the flowchart. Specifically, the specific flow of the anomaly localization method is as follows:

[0064] 101. Upon detecting the startup of the target application, obtain the memory allocation threshold and the total memory allocation amount, wherein the total memory allocation amount is the sum of the memory allocation capacity of at least one memory allocation object.

[0065] The target application is an application on a terminal device, including mobile applications or desktop applications, which are the applications for memory leak analysis required in this application embodiment.

[0066] The memory allocation threshold is a pre-set threshold, such as 60MB or 100MB. This threshold can be set based on factors such as the device's memory capacity and the type of application. For example, different types of applications may have different memory allocation thresholds. For instance, the threshold can be set according to the application's memory allocation requirements; for example, a mobile application might have a memory allocation threshold of 100MB, while a desktop application might have a threshold of 500MB.

[0067] This memory allocation threshold can be set locally as a default value, or it can be configured on the server and obtained in real time from the server. In some cases, the memory allocation threshold can also be obtained by the user locally via command line input or through relevant configuration files; the specific method of obtaining the memory allocation threshold is not limited here.

[0068] The total memory allocation refers to the sum of the memory allocation capacity occupied by all memory allocation objects in the application. The memory allocation capacity is the amount of memory allocated, for example, allocating 1MB of memory. Memory allocation objects are various data structures, caches, image resources, and other objects in the application that require memory allocation. For example, these memory allocation objects include processes or threads. This application embodiment takes processes as an example to obtain the memory allocation status of each process in order to determine which process has a memory allocation leak problem.

[0069] 102. If the total memory allocation and the memory allocation threshold meet the preset conditions, then record the memory allocation details of the target application, including memory allocation records for each memory allocation object.

[0070] For example, the total amount of memory allocated can be compared with the memory allocation threshold to determine whether the preset conditions are met.

[0071] The preset condition is a pre-defined condition that triggers the recording of memory allocation details. That is, when the preset condition is met, the recording of memory allocation details is triggered. For example, the preset condition may include the total memory allocation exceeding a memory allocation threshold, or the difference between the total memory allocation and the memory allocation threshold exceeding a set threshold. For instance, when the total memory allocation reaches or exceeds 80% of the memory allocation threshold, the preset condition can be considered met.

[0072] The memory allocation details include memory allocation records for each memory allocation object. These records include the object's identifier, the size of the allocated memory, the allocation time, and the memory allocation stack information.

[0073] Understandably, by only recording memory allocation details when the memory allocation capacity and threshold meet preset conditions, the recording burden is reduced, and more effective memory allocation data can be filtered out for memory allocation analysis. For example, after the target application triggers memory allocation upon startup, memory allocation details are not recorded immediately. Instead, they are only recorded when the total memory allocation exceeds the memory allocation threshold. This reduces the amount of memory allocation details recorded below the threshold, thus reducing the amount of data that needs to be recorded.

[0074] The memory allocation details record memory allocations that occur even after exceeding the memory allocation threshold. Therefore, analyzing this data is more helpful in identifying memory allocation objects with persistent memory leaks. For example, if memory allocation object A has a persistent memory leak, its corresponding memory allocation record will appear in the memory allocation details exceeding the threshold, indicating it is a memory leak point. If memory allocation object B does not have a persistent memory leak, its corresponding memory leak usually occurs within the memory allocation capacity, meaning it will not remain in the memory allocation details exceeding the threshold (i.e., it will not appear in the memory allocation details due to persistence), or even if it appears, it will not exhibit persistent memory allocation. Therefore, analyzing the memory allocation details will not incorrectly identify memory allocation object B as a memory leak point. Thus, designing a memory allocation threshold is more helpful in obtaining effective memory allocation details and more accurately locating abnormal memory allocation objects (i.e., memory leak points).

[0075] 103. Extract features from the memory allocation details to obtain allocation feature information.

[0076] The allocation characteristic information is the allocation feature contained in the memory allocation details information, reflecting the memory allocation characteristics of each memory allocation object. For example, this allocation characteristic information includes the number of times each memory allocation object allocates memory for the same memory allocation capacity, or the memory allocation capacity of each memory allocation object in a single allocation.

[0077] 104. Determine the target memory allocation object with memory allocation anomaly from the at least one memory allocation object based on the allocation feature information.

[0078] For example, based on allocation characteristic information, target memory allocation objects with memory allocation anomalies can be selected from various memory allocation objects.

[0079] In summary, this application embodiment records memory allocation details only after the target application starts, when the total memory allocation amount and memory allocation threshold meet preset conditions. This avoids recording memory allocation details directly when the application starts, which helps improve the effectiveness of the recorded memory allocation details, reduces the resource consumption related to recording, and improves the performance of the target application.

[0080] It is understandable that small-capacity content leakage is within an acceptable range. Therefore, embodiments of this application include recording memory allocation objects exceeding the memory allocation capacity to further reduce the recording burden of memory allocation records. Specifically, in some embodiments of this application, the step "if the total memory allocation amount and the memory allocation threshold meet preset conditions, then record the memory allocation details of the target application" includes:

[0081] If the total memory allocation amount and the memory allocation threshold meet the preset conditions, then the allocation record threshold is obtained;

[0082] Obtain the memory allocation capacity of the memory allocation object in a single memory allocation;

[0083] If the memory allocation capacity is greater than or equal to the allocation record threshold, then the memory allocation record for the memory allocation object is recorded;

[0084] The memory allocation details are obtained from the memory allocation records of each memory allocation object.

[0085] For example, the allocation recording threshold can be set to 1MB, so that only memory allocation objects with a single allocation size exceeding 1MB will be recorded, while memory allocation objects with a single allocation size less than 1MB will not be recorded.

[0086] Understandably, by obtaining the memory allocation capacity of each memory allocation object in a single transaction, and if the allocation capacity is greater than or equal to the allocation record threshold, a memory allocation record is recorded for that memory allocation object. This method helps to filter out large memory allocation objects that may cause memory anomalies, reducing the amount of data recorded. Furthermore, identifying large memory allocation objects also helps to pinpoint leaks and resolve application stuttering and other performance issues more quickly and efficiently.

[0087] After obtaining the memory allocation records of each memory allocation object, the memory allocation details can be obtained by summarizing the records. This detailed information provides the basic data for locating abnormal memory allocation objects in the future.

[0088] It is understandable that memory leaks primarily occur when a target application fails to properly release allocated memory during runtime, and then continuously allocates memory again during runtime, typically by repeatedly allocating memory of the same size. Therefore, the number of times memory is allocated with the same size is crucial for analyzing memory leaks. However, when the memory allocation threshold is low, even if memory allocation details reveal instances of memory allocations with the same size, a memory leak cannot be accurately determined; more such allocations are needed to confirm the leak. Optionally, in some embodiments of this application, the method further includes:

[0089] The allocation quantity is extracted from the memory allocation details information, and the allocation quantity includes the number of memory allocations with the same capacity.

[0090] If the number of allocations is less than the number threshold, the memory allocation threshold is increased by a preset amount to obtain the target allocation threshold.

[0091] Record the new memory allocation details of the target application according to the target allocation threshold;

[0092] Determine new allocation characteristics based on the new memory allocation details;

[0093] The target memory allocation object for the memory allocation anomaly is determined from at least one of the memory allocation objects based on the new allocation characteristic information.

[0094] The allocation quantity refers to the number of times the same memory allocation capacity is allocated, while the quantity threshold is a reference standard for the allocation quantity. When the allocation quantity is less than the quantity threshold, the memory allocation threshold is increased to determine whether the allocation quantity has increased or is too large, thereby more accurately determining whether the corresponding memory allocation object belongs to the target memory allocation object of the memory allocation anomaly.

[0095] For example, if the memory allocation threshold is set to 60MB, the relatively small threshold (e.g., small difference from the normal capacity range of 50MB) results in a relatively small number of recorded allocations, making it impossible to accurately determine whether the allocation is continuous. However, if the memory allocation threshold is set larger (e.g., to 80MB), and memory allocation details still record allocations of the same memory capacity, it is more certain that this allocation occurs frequently. In other words, the actual number of allocations is considered to be large (e.g., there may be many memory allocations of the same capacity within 80MB).

[0096] A higher memory allocation threshold allows for more accurate identification of abnormal memory allocation objects. However, an excessively large threshold hinders the timely acquisition of detailed memory allocation information, thus reducing the efficiency of locating the target memory allocation object. This threshold can be dynamically adjusted based on experience or the quantity of allocations. In other words, the preset range can be customized to account for the impact of being too large or too small, for example, 10MB or 20MB.

[0097] In this embodiment, the allocation feature information can be obtained through data statistics, such as counting the number of times each memory allocation object allocates the same memory allocation capacity or the memory capacity during a single allocation. That is, optionally, in some embodiments of this application, the step "extracting features from the memory allocation details to obtain allocation feature information" includes:

[0098] The number of times each memory allocation object allocates memory for the same memory allocation capacity is counted, and the number of memory allocations is used as the allocation feature information;

[0099] or,

[0100] The memory allocation capacity of each memory allocation object in a single allocation is calculated, and the memory allocation capacity is used as the allocation feature information.

[0101] For example, it can be calculated that memory allocation object C allocated 10MB of memory 20 times, and memory allocation object D allocated 5MB of memory 50 times. Or, it can be calculated that memory allocation object E allocated a maximum of 15MB of memory in a single allocation, and memory allocation object F allocated a maximum of 8MB of memory in a single allocation.

[0102] Correspondingly, the target memory allocation object with memory allocation anomalies can be selected from multiple memory allocation objects based on the allocation feature information. That is, optionally, in some embodiments of this application, the step "determining the target memory allocation object with memory allocation anomalies from the at least one memory allocation object based on the allocation feature information" includes:

[0103] The memory allocation object whose memory allocation count exceeds the threshold is selected as the target memory allocation object;

[0104] or,

[0105] The memory allocation object whose memory allocation capacity exceeds the capacity threshold is taken as the target memory allocation object.

[0106] For example, if the number of allocations threshold is set to 100, then any memory allocation object that has been allocated more than 100 times will be marked as an abnormal object, i.e., the target memory allocation object. Or, if the capacity threshold is set to 50MB, then any memory allocation object that has been allocated more than 50MB in a single allocation will be marked as an abnormal object, i.e., the target memory allocation object.

[0107] In summary, the above statistical methods can more effectively identify target memory allocation objects in the target application that may have abnormal memory allocation, which can help developers optimize these target memory allocation objects and improve the performance and stability of the target application.

[0108] In practical applications, to improve the efficiency and accuracy of memory allocation records, a certain number of caches can be configured to record memory allocation records. That is, optionally, in some embodiments of this application, the method further includes:

[0109] Configure a first number of caches, the caches including a target capacity determined based on at least one memory allocation capacity;

[0110] The memory allocation record is recorded through the cache.

[0111] If the first number of caches is full, then a second number of caches is configured, wherein the second number is greater than the first number.

[0112] For example, based on historical records or development, there is a greater demand for small memory allocations, such as for caching variables (e.g., defining an int type variable). The memory allocation records corresponding to these variables are also relatively small. If the stack is small, then more caches of this size can be configured to store the memory allocation records for each small amount of memory.

[0113] Correspondingly, when the demand for such small memory allocation capacity increases, for example, when the initial cache is full, the number of such caches can be dynamically increased to store more memory allocation records. Understandably, dynamically increasing the number of caches to enable timely and continuous recording of memory allocation records helps in locating the target memory allocation object in case of memory allocation anomalies.

[0114] In some embodiments of this application, a custom allocation function can be used to perform memory allocation processing and record memory allocation details. Optionally, in some embodiments of this application, the method further includes:

[0115] Upon detecting the startup of the target application, a custom allocation function is invoked, and memory allocation is performed on each memory allocation object according to the custom allocation function to obtain the memory allocation capacity corresponding to each memory allocation object;

[0116] Register a first signal function and a second signal function through the custom allocation function; wherein, the first signal function is used to issue a first target signal when the total memory allocation amount and the memory allocation threshold meet preset conditions, wherein, the first target signal is used to indicate the triggering of recording of the memory allocation details;

[0117] The second signal function is used to issue a second target signal when the cache storing the memory allocation details meets the recording conditions, wherein the second target signal is used to instruct the memory allocation details to be saved as a target file and the cache to be cleared;

[0118] The memory allocation record includes at least one of memory address, memory size, or stack information;

[0119] The memory allocation object includes the process of the target application.

[0120] For example, when the target application starts, a custom allocation function is loaded to replace the native memory allocation function. When initializing the custom allocation function, a certain amount of cache is allocated to store memory allocation records for later use. Two signal functions are registered, namely the first signal function and the second signal function, which are used to control the timing of recording memory allocation details and the timing of converting the memory allocation records in the cache into the target file, respectively.

[0121] For example, after the application starts, it launches a processing thread. This thread obtains information such as the memory allocation threshold, allocation record threshold, and the initial quantity of buffers from the server, local machine, or user command line. Furthermore, when it detects that the total memory allocation exceeds the memory allocation threshold, it sends a first target signal (e.g., signal 47) via a first signal function to indicate that it should begin recording the memory allocation details for each allocated object. For instance, it might start recording the stack information for each memory allocation at this point.

[0122] Furthermore, after a period of time (such as after the first number of caches are full), a second target signal is sent through a second signal function to instruct the data in the cache to be saved to the target file, and to clear the cache and configure a larger number of caches, etc.

[0123] In practical applications, the target file can be sent to a server or backed up locally so that the current terminal device or other analysis device can obtain the memory allocation details from the server to analyze memory leaks.

[0124] To facilitate better implementation of the anomaly localization method of this application, this application also provides an anomaly localization device based on the above-described anomaly localization method. The meanings of the terms used are the same as in the anomaly localization method described above, and specific implementation details can be found in the descriptions of the method embodiments.

[0125] Please see Figure 3 , Figure 3 This is a schematic diagram of the anomaly location device provided in an embodiment of this application, wherein the anomaly location device may specifically be as follows:

[0126] The detection module 301 is used to detect the startup of the target application, obtain the memory allocation threshold and the total memory allocation, wherein the total memory allocation is the sum of the memory allocation capacity of at least one memory allocation object;

[0127] The recording module 302 is used to record the memory allocation details of the target application if the total memory allocation amount and the memory allocation threshold meet the preset conditions. The memory allocation details include memory allocation records for each memory allocation object.

[0128] Extraction module 303 is used to extract features from the memory allocation details to obtain allocation feature information;

[0129] The determination module 304 is used to determine the target memory allocation object with memory allocation abnormality from the at least one memory allocation object based on the allocation feature information.

[0130] Optionally, in some embodiments of this application, the preset condition includes the total memory allocation exceeding the memory allocation threshold, or the difference between the total memory allocation and the memory allocation threshold exceeding a set threshold;

[0131] If the total memory allocation and the memory allocation threshold meet preset conditions, then the memory allocation details of the target application are recorded, including:

[0132] If the total memory allocation amount and the memory allocation threshold meet the preset conditions, then the allocation record threshold is obtained;

[0133] Obtain the memory allocation capacity of the memory allocation object in a single memory allocation;

[0134] If the memory allocation capacity is greater than or equal to the allocation record threshold, then the memory allocation record for the memory allocation object is recorded;

[0135] The memory allocation details are obtained from the memory allocation records of each memory allocation object.

[0136] Optionally, in some embodiments of this application, the device further includes:

[0137] The allocation quantity is extracted from the memory allocation details information, and the allocation quantity includes the number of memory allocations with the same capacity.

[0138] If the number of allocations is less than the number threshold, the memory allocation threshold is increased by a preset amount to obtain the target allocation threshold.

[0139] Record the new memory allocation details of the target application according to the target allocation threshold;

[0140] Determine new allocation characteristics based on the new memory allocation details;

[0141] The target memory allocation object for the memory allocation anomaly is determined from at least one of the memory allocation objects based on the new allocation characteristic information.

[0142] Optionally, in some embodiments of this application, the step of extracting allocation feature information from the memory allocation details includes:

[0143] The number of times each memory allocation object allocates memory for the same memory allocation capacity is counted, and the number of memory allocations is used as the allocation feature information;

[0144] or,

[0145] The memory allocation capacity of each memory allocation object in a single allocation is calculated, and the memory allocation capacity is used as the allocation feature information.

[0146] Optionally, in some embodiments of this application, determining the target memory allocation object with memory allocation anomalies from the at least one memory allocation object based on the allocation feature information includes:

[0147] The memory allocation object whose memory allocation count exceeds the threshold is selected as the target memory allocation object;

[0148] or,

[0149] The memory allocation object whose memory allocation capacity exceeds the capacity threshold is taken as the target memory allocation object.

[0150] Optionally, in some embodiments of this application, the device further includes:

[0151] Configure a first number of caches, the caches including a target capacity determined based on at least one memory allocation capacity;

[0152] The memory allocation record is recorded through the cache.

[0153] If the first number of caches is full, then a second number of caches is configured, wherein the second number is greater than the first number.

[0154] Optionally, in some embodiments of this application, the device further includes:

[0155] Upon detecting the startup of the target application, a custom allocation function is invoked, and memory allocation is performed on each memory allocation object according to the custom allocation function to obtain the memory allocation capacity corresponding to each memory allocation object;

[0156] Register a first signal function and a second signal function through the custom allocation function; wherein, the first signal function is used to issue a first target signal when the total memory allocation amount and the memory allocation threshold meet preset conditions, wherein, the first target signal is used to indicate the triggering of recording of the memory allocation details;

[0157] The second signal function is used to issue a second target signal when the cache storing the memory allocation details meets the recording conditions, wherein the second target signal is used to instruct the memory allocation details to be saved as a target file and the cache to be cleared;

[0158] The memory allocation record includes at least one of memory address, memory size, or stack information;

[0159] The memory allocation object includes the process of the target application.

[0160] In this embodiment, the detection module 301 first detects the startup of the target application, obtains the memory allocation threshold and the total memory allocation, wherein the total memory allocation is the sum of the memory allocation capacity of at least one memory allocation object. If the total memory allocation and the memory allocation threshold meet preset conditions, the recording module 302 records the memory allocation details of the target application. The memory allocation details include memory allocation records for each memory allocation object. The extraction module 303 performs feature extraction on the memory allocation details to obtain allocation feature information. The determination module 304 determines the target memory allocation object with abnormal memory allocation from the at least one memory allocation object based on the allocation feature information.

[0161] In this embodiment, memory allocation details are recorded only when the total memory allocation and memory allocation threshold meet preset conditions after the target application starts. This avoids recording memory allocation details directly when the application starts, which helps improve the effectiveness of the recorded memory allocation details, reduces the resource consumption related to recording, and improves the performance of the target application.

[0162] In addition, this application also provides an electronic device, such as Figure 4 As shown, it illustrates the structural diagram of the electronic device involved in this application, specifically:

[0163] The electronic device may include components such as a processor 401 with one or more processing cores, a memory 402 with one or more computer-readable storage media, a power supply 403, and an input unit 404. Those skilled in the art will understand that... Figure 4 The electronic device structure shown does not constitute a limitation on the electronic device and may include more or fewer components than shown, or combine certain components, or have different component arrangements. Wherein:

[0164] The processor 401 is the control center of the electronic device. It connects various parts of the electronic device via various interfaces and lines. By running or executing software programs and / or modules stored in the memory 402, and by calling data stored in the memory 402, it performs various functions and processes data, thereby providing overall monitoring of the electronic device. Optionally, the processor 401 may include one or more processing cores; preferably, the processor 401 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and applications, and the modem processor mainly handles wireless communication. It is understood that the modem processor may not be integrated into the processor 401.

[0165] The memory 402 can be used to store software programs and modules. The processor 401 executes various functional applications and data processing by running the software programs and modules stored in the memory 402. The memory 402 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, application programs required for at least one function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the electronic device, etc. In addition, the memory 402 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, the memory 402 may also include a memory controller to provide the processor 401 with access to the memory 402.

[0166] The electronic device also includes a power supply 403 that supplies power to the various components. Preferably, the power supply 403 can be logically connected to the processor 401 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. The power supply 403 may also include one or more DC or AC power supplies, recharging systems, power equipment debugging circuits, power converters or inverters, power status indicators, and other arbitrary components.

[0167] The electronic device may also include an input unit 404, which can be used to receive input digital or character information, and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control.

[0168] Although not shown, the electronic device may also include a display unit, etc., which will not be described in detail here. Specifically, in this embodiment, the processor 401 in the electronic device loads the executable files corresponding to the processes of one or more applications into the memory 402 according to the following instructions, and the processor 401 runs the applications stored in the memory 402, thereby implementing the steps in any of the anomaly location methods provided in the embodiments of this application.

[0169] In response to the startup operation of the target application, this embodiment loads the target library file corresponding to the target application. The target library file contains a target configuration function that replaces the original configuration function. The target configuration function is executed to configure and obtain an array of memory allocation objects. In response to the memory allocation operation for the target application, the memory allocation information of the allocated target memory is obtained, and the memory allocation exception is located in the array of memory allocation objects.

[0170] In this embodiment, by directly replacing the original configuration function in the library file with the target configuration function, the application can directly use the target configuration function configured in the library file to record memory allocation information when performing memory allocation. Compared with the method of memory allocation anomaly location based on application hook functions in related technologies, this embodiment reduces the complexity of memory allocation anomaly location.

[0171] The library file and its target configuration function are applicable to multiple applications. Therefore, there is no need to configure hook functions separately for multiple applications, which reduces the complexity of memory allocation exception location.

[0172] By pre-establishing the array of memory allocation objects before the memory allocation operation, the stuttering, performance and efficiency problems caused by temporarily creating the array of memory allocation objects during the memory allocation process are avoided.

[0173] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.

[0174] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.

[0175] Therefore, this application provides a computer-readable storage medium storing a computer program that can be loaded by a processor to execute the steps in any of the anomaly location methods provided in this application.

[0176] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.

[0177] The computer-readable storage medium may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.

[0178] Since the instructions stored in the computer-readable storage medium can execute the steps in any of the anomaly location methods provided in this application, the beneficial effects that any of the anomaly location methods provided in this application can achieve can be realized, as detailed in the preceding embodiments, and will not be repeated here.

[0179] The above provides a detailed description of an anomaly location method, apparatus, electronic device, and computer-readable storage medium provided in this application. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, those skilled in the art will recognize that there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.

Claims

1. An anomaly localization method, characterized in that, The method includes: Upon detecting the startup of the target application, obtain the memory allocation threshold and the total memory allocation amount, wherein the total memory allocation amount is the sum of the memory allocation capacity of at least one memory allocation object; If the total memory allocation and the memory allocation threshold meet the preset conditions, then the memory allocation details of the target application are recorded, including the memory allocation records for each memory allocation object; Feature extraction is performed on the memory allocation details to obtain allocation feature information; The target memory allocation object with memory allocation anomaly is determined from the at least one memory allocation object based on the allocation feature information.

2. The anomaly localization method according to claim 1, characterized in that, The preset conditions include the total memory allocation exceeding the memory allocation threshold, or the difference between the total memory allocation and the memory allocation threshold exceeding a set threshold; If the total memory allocation and the memory allocation threshold meet preset conditions, then the memory allocation details of the target application are recorded, including: If the total memory allocation amount and the memory allocation threshold meet the preset conditions, then the allocation record threshold is obtained; Obtain the memory allocation capacity of the memory allocation object in a single memory allocation; If the memory allocation capacity is greater than or equal to the allocation record threshold, then the memory allocation record for the memory allocation object is recorded; The memory allocation details are obtained from the memory allocation records of each memory allocation object.

3. The anomaly localization method according to claim 1, characterized in that, The method further includes: The allocation quantity is extracted from the memory allocation details information, and the allocation quantity includes the number of memory allocations with the same capacity. If the number of allocations is less than the number threshold, the memory allocation threshold is increased by a preset amount to obtain the target allocation threshold. Record the new memory allocation details of the target application according to the target allocation threshold; Determine new allocation characteristics based on the new memory allocation details; The target memory allocation object for the memory allocation anomaly is determined from at least one of the memory allocation objects based on the new allocation characteristic information.

4. The anomaly localization method according to claim 1, characterized in that, The step of extracting allocation feature information from the memory allocation details includes: The number of times each memory allocation object allocates memory for the same memory allocation capacity is counted, and the number of memory allocations is used as the allocation feature information; or, The memory allocation capacity of each memory allocation object in a single allocation is calculated, and the memory allocation capacity is used as the allocation feature information.

5. The anomaly localization method according to claim 4, characterized in that, The step of determining the target memory allocation object with memory allocation anomalies from the at least one memory allocation object based on the allocation feature information includes: The memory allocation object whose memory allocation count exceeds the threshold is selected as the target memory allocation object; or, The memory allocation object whose memory allocation capacity exceeds the capacity threshold is taken as the target memory allocation object.

6. The anomaly localization method according to claim 1, characterized in that, The method further includes: Configure a first number of caches, the caches including a target capacity determined based on at least one memory allocation capacity; The memory allocation record is recorded through the cache. If the first number of caches is full, then a second number of caches is configured, wherein the second number is greater than the first number.

7. The anomaly localization method according to claim 1, characterized in that, The method further includes: Upon detecting the startup of the target application, a custom allocation function is invoked, and memory allocation is performed on each memory allocation object according to the custom allocation function to obtain the memory allocation capacity corresponding to each memory allocation object; Register a first signal function and a second signal function through the custom allocation function; wherein, the first signal function is used to issue a first target signal when the total memory allocation amount and the memory allocation threshold meet preset conditions, wherein, the first target signal is used to indicate the triggering of recording of the memory allocation details; The second signal function is used to issue a second target signal when the cache storing the memory allocation details meets the recording conditions, wherein the second target signal is used to instruct the memory allocation details to be saved as a target file and the cache to be cleared; The memory allocation record includes at least one of memory address, memory size, or stack information; The memory allocation object includes the process of the target application.

8. An anomaly location device, characterized in that, The device includes: The detection module is used to detect the startup of the target application, obtain the memory allocation threshold and the total memory allocation, wherein the total memory allocation is the sum of the memory allocation capacity of at least one memory allocation object; The recording module is used to record memory allocation details of the target application if the total memory allocation amount and the memory allocation threshold meet preset conditions. The memory allocation details include memory allocation records for each memory allocation object. The extraction module is used to extract features from the memory allocation details to obtain allocation feature information; The determination module is used to determine the target memory allocation object with memory allocation abnormality from the at least one memory allocation object based on the allocation feature information.

9. An electronic device, characterized in that, It includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the anomaly localization method as described in any one of claims 1-7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the anomaly localization method as described in any one of claims 1-7.