A memory leakage detection method, related device and equipment
By comparing the actual number of operable objects with the preset number of operable objects in the object mapping list of the target business module, the problem of low accuracy in memory leak detection in the prior art is solved, and memory leak detection with higher precision and finer detail is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- TENCENT TECHNOLOGY (SHENZHEN) CO LTD
- Filing Date
- 2021-08-19
- Publication Date
- 2026-04-28
AI Technical Summary
Existing memory leak detection methods struggle to accurately determine whether a memory leak has occurred when the counter variable is greater than 0 after the application has finished running, leading to reduced accuracy of the detection results.
By pre-setting the mapping relationship between interface identifiers and the number of operable objects in the object mapping list of the target business module, the actual number of operable objects is compared with the preset number to determine whether there is a memory leak, and the detection is carried out at the business module level.
It improves the accuracy and precision of memory leak detection, enabling accurate identification of the types of business processes experiencing memory leaks.
Smart Images

Figure CN115934493B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a method, related apparatus and equipment for detecting memory leaks. Background Technology
[0002] A memory leak refers to the phenomenon where dynamically allocated heap memory in a program fails to be released or is not released for some reason. Memory leaks waste memory, slow down program execution, and can even lead to serious consequences such as system crashes. Therefore, effectively detecting memory leaks has become an urgent problem to solve.
[0003] In one memory leak detection method, during application runtime, when the detection class detects a call to the updated creation or release method by a class under test, it changes the value of a counter variable corresponding to that class. After the application terminates, the class names of all classes under test whose counter variables were not zero are written to a detection result file, allowing relevant personnel to identify the class experiencing the memory leak by reviewing the file.
[0004] In this detection method, the default is that when memory is normal, the counter variable corresponding to the class to be detected is 0. However, in practical applications, there are situations where a counter variable greater than 0 is also considered to indicate normal memory. In such cases, this detection method needs to filter the memory leak detection result files to determine whether a memory leak has occurred, reducing the accuracy of the detection results. Summary of the Invention
[0005] In view of this, this application provides a method, related apparatus, and device for detecting memory leaks. The method uses a target business module to indicate the target business type in the application to be detected. A mapping relationship between interface identifiers and the number of operable objects is preset in the object mapping list of the target business module. The interface identifier uniquely identifies the interface of the target business module. When detecting whether a memory leak has occurred, the method compares the actual number of operable objects corresponding to each interface with the preset number of operable objects corresponding to each interface, making the comparison more targeted and improving the accuracy of memory leak detection. Furthermore, comparing at the business module level allows for pinpointing the type of business where the memory leak has occurred, improving the granularity of the detection.
[0006] This application provides a method for detecting memory leaks, including:
[0007] Obtain an object mapping list for the target business module in the application to be tested. The target business module indicates the target business type of the application to be tested. The object mapping list includes the mapping relationship between the interface identifier and the number of operable objects. The interface identifier is used to uniquely identify the interface of the target business module.
[0008] In response to the exit operation of the application to be tested, the first operable object data is obtained, wherein the first operable object data is the sum of the number of operable objects included in M interfaces, and the M interfaces include the interfaces in the target business module that are in the running state before the application to be tested exits, where M is a positive integer;
[0009] The second operable object data is obtained from the object mapping list. The second operable object data is the sum of the number of operable objects corresponding to M interface identifiers, and the M interface identifiers correspond one-to-one with the M interfaces.
[0010] If the data of the first operable object is greater than the data of the second operable object, then it is determined that there is a memory leak in the target business module.
[0011] This application also provides a memory leak detection device, comprising:
[0012] Acquisition unit, used for:
[0013] Obtain an object mapping list for the target business module in the application to be tested. The target business module indicates the target business type of the application to be tested. The object mapping list includes the mapping relationship between the interface identifier and the number of operable objects. The interface identifier is used to uniquely identify the interface of the target business module.
[0014] In response to the exit operation of the application to be tested, the first operable object data is obtained, wherein the first operable object data is the sum of the number of operable objects included in M interfaces, and M interfaces include the interfaces in which the target business module was running before the application to be tested exits, and M is a positive integer;
[0015] The second operable object data is obtained from the object mapping list. The second operable object data is the sum of the number of operable objects corresponding to M interface identifiers, and the M interface identifiers correspond one-to-one with the M interfaces.
[0016] The processing unit is used to determine that there is a memory leak in the target business module if the data of the first operable object is greater than the data of the second operable object.
[0017] In one possible design, in another implementation of the embodiments of this application, the memory leak detection device further includes a display unit, used for:
[0018] Display the first interface, which is the first interface of the target application module and includes the target control;
[0019] In response to a touch command for a target control, a second interface is displayed, wherein the second interface corresponds to the target business module;
[0020] The acquisition unit is specifically used to respond to the exit operation for the second interface and acquire the data of the first operable object.
[0021] In one possible design, in another implementation of the embodiments of this application, the memory leak detection device further includes a display unit, used for:
[0022] Display the first interface, which is the first interface of the target application module and includes the target control;
[0023] In response to a touch command for a target control, a second interface is displayed, wherein the second interface corresponds to the target business module;
[0024] In response to an exit action from the second screen, the first screen is displayed.
[0025] The acquisition unit is specifically used to respond to the exit operation for the first interface and acquire the data of the first operable object.
[0026] In one possible design, in another implementation of the embodiments of this application, the memory leak detection device further includes a sending unit;
[0027] The processing unit is also used to create a target application, which is used to detect the application to be detected;
[0028] The sending unit is also used to send the application identifier of the application to be detected to the server through the data transmission interface of the target application, so that the server can create a detection file for the application to be detected, which includes an object mapping list.
[0029] In one possible design, in another implementation of the embodiments of this application, the memory leak detection device further includes a sending unit;
[0030] The processing unit is also used to call the target application to divide the business type of the application to be detected, and obtain the target business module, wherein the target application is used to detect the application to be detected;
[0031] The acquisition unit is also used to acquire the mapping relationship between the interface identifier corresponding to the target business module and the number of operable objects;
[0032] The sending unit is also used to send the mapping relationship between the interface identifier of the target business module and the number of operable objects to the server through the data transmission interface of the target application.
[0033] In one possible design, in another implementation of the embodiments of this application, the memory leak detection device further includes a sending unit;
[0034] The sending unit is also used to send a list retrieval request to the server, wherein the list retrieval request carries the application identifier of the application to be detected, and the M interface identifiers corresponding to the M interfaces.
[0035] The acquisition unit is also used to receive an object mapping list from the server through the data transmission interface of the target application, based on the application identifier and M interface identifiers, wherein the target application is used to detect the application to be detected.
[0036] In one possible design, in another implementation of the embodiments of this application, the memory leak detection device, including a processing unit, is further configured to:
[0037] The first creation method of the application to be tested is replaced with the second creation method, and the first release method of the application to be tested is replaced with the second release method. The first creation method is used to create an operable object, the first release method is used to destroy the operable object, the second creation method includes the function of creating an operable object and a first counting function, and the second release method includes the function of destroying an operable object and a second counting function.
[0038] Based on the number of calls to the second creation method, the first counting function, the number of calls to the second release method, and the second counting function, the number of operable objects in the target business module is recorded, wherein the number of operable objects is used to determine the first operable object data.
[0039] This application also provides a computer device, including: a memory, a processor, and a bus system; the memory is used to store program code; the processor is used to execute the memory leak detection method described in any of the preceding aspects according to instructions in the program code.
[0040] In another aspect, this application provides a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform the memory leak detection method described in any of the preceding aspects.
[0041] According to another aspect of this application, a computer program product or computer program is provided, comprising 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 memory leak detection method described in any of the preceding aspects.
[0042] As can be seen from the above technical solutions, the embodiments of this application have the following advantages:
[0043] When an exit operation is detected for the application under test, the first operable object data corresponding to M interfaces is obtained. The M interfaces include those that were running in the target business module before the application exited, and M is a positive integer. The target business module indicates the target business type in the application under test. Based on the object mapping list, the second operable object data corresponding to these M interfaces is obtained. Then, the first operable object data and the second operable object data are compared. If the first operable object data is greater than the second operable object data, it is determined that a memory leak has occurred in the target business module. In this embodiment, the target business module indicates the target business type in the application under test. A mapping relationship between interface identifiers and the number of operable objects is preset in the object mapping list of the target business module. The interface identifier is used to uniquely identify the interface of the target business module. When detecting whether a memory leak has occurred, the comparison is made between the actual number of operable objects corresponding to each interface and the preset number of operable objects corresponding to each interface, making the comparison more targeted and improving the accuracy of memory leak detection. Simultaneously, comparing at the business module level allows for the location of the business type experiencing a memory leak, improving the granularity of the detection. Attached Figure Description
[0044] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0045] Figure 1 A schematic diagram of the architecture of the memory leak detection method provided in the embodiments of this application;
[0046] Figure 2 A flowchart illustrating a memory leak detection method provided in an embodiment of this application;
[0047] Figure 3a A schematic diagram illustrating an application scenario of the memory leak detection method provided in this application embodiment;
[0048] Figure 3b A schematic diagram illustrating the mapping relationship between business modules and object mapping lists provided in embodiments of this application;
[0049] Figure 4 Another flowchart illustrating the memory leak detection method provided in this application embodiment;
[0050] Figure 5 A schematic diagram of the structure of a memory leak detection device provided in an embodiment of this application;
[0051] Figure 6 A schematic diagram of the structure of a computer device provided in an embodiment of this application. Detailed Implementation
[0052] This application provides a method, related apparatus, and device for detecting memory leaks. In this embodiment, the object mapping list of the application to be detected includes a mapping relationship between interface identifiers and the number of operable objects. The interface identifier uniquely identifies the interface of the application to be detected. Therefore, the relationship between the interfaces and the number of operable objects in the application to be detected can be preset through the object mapping list. When detecting whether a memory leak has occurred, the actual number of operable objects corresponding to each interface is compared with the preset number of operable objects corresponding to each interface, making the comparison more targeted and improving the accuracy of memory leak detection.
[0053] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a particular order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented, for example, in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “corresponding to,” and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0054] First, some terms that may appear in the embodiments of this application will be explained.
[0055] 1. Memory leak.
[0056] Memory leaks, also known as memory leaks, refer to the phenomenon where dynamically allocated heap memory in a program cannot be released or is not released for some reason. Simply put, a memory leak means that some objects in the heap memory are no longer used, but the garbage collector cannot remove them from memory. Memory leaks waste memory, slow down program execution, and can even lead to serious consequences such as system crashes. For example, suppose the application being tested is a media player. When a download is triggered in the media player, a corresponding download task is created. After the download is complete, theoretically, this task should be destroyed to release the memory resources. If these memory resources are not released when the media player is exited, then the media player application has a memory leak.
[0057] 2. Database.
[0058] In short, a database can be viewed as an electronic filing cabinet—a place to store electronic files, where users can perform operations such as adding, querying, updating, and deleting data. A "database" is a collection of data stored together in a certain way, capable of being shared by multiple users, with minimal redundancy, and independent of application programs.
[0059] A database management system (DBMS) is a computer software system designed to manage databases, generally possessing basic functions such as storage, retrieval, security, and backup. DBMSs can be classified according to the database model they support, such as relational or Extensible Markup Language (XML); or according to the type of computer they support, such as server clusters or mobile phones; or according to the query language used, such as Structured Query Language (SQL) or XQuery; or according to performance priorities, such as maximum scale or maximum operating speed; or other classification methods. Regardless of the classification method used, some DBMSs can cross categories, for example, simultaneously supporting multiple query languages. In the memory leak detection method provided in this application embodiment, the object mapping list of the application to be detected can be stored in a cloud database.
[0060] 3. Code instrumentation.
[0061] Code instrumentation is one of the key techniques for implementing coverage testing. Coverage testing refers to the degree to which the test system covers the system under test, and it can be used to evaluate the completion level and quality of a working application. During coverage testing, the computer can automatically record data during the execution of the program under test. At this point, code that performs the corresponding task can be inserted into the program under test, which is known as code instrumentation.
[0062] The architecture of the memory leak detection method provided in this application embodiment is described below. Please refer to [link / reference]. Figure 1 , Figure 1 This is a schematic diagram of the architecture of a memory leak detection method provided in an embodiment of this application.
[0063] It should be understood that the memory leak detection method provided in this application can be applied to systems or programs in terminal devices that include memory leak detection functionality. Specifically, the memory leak detection system can run on, for example,... Figure 1 In the network architecture shown.
[0064] like Figure 1As shown, the terminal device establishes a communication connection with the server. An application to be tested is installed on the terminal device. During operation, the application displays different interfaces, each containing a different type and number of operable objects. The terminal device can obtain an object mapping list for the target business module within the application under test. The target business module indicates the target business type of the application. This object mapping list includes a mapping relationship between interface identifiers and the number of operable objects, and each interface identifier uniquely identifies the interface of the target business module. In other words, each interface identifier corresponds to a unique and definite interface. Before the application exits, the terminal device obtains the memory usage of the application before exiting to detect memory leaks. Specifically, the client responds to the exit operation of the application under test and obtains the first operable object data. This first operable object data is the sum of the number of operable objects included in the M interfaces of the target business module in the running state before the application exits. Here, M is a positive integer. The terminal device also obtains the second operable object data included in these M interfaces based on the object mapping list. Understandably, the first set of operable object data reflects the sum of the actual number of operable objects corresponding to the M interfaces of the target business module; the second set of operable object data reflects the sum of the preset number of operable objects corresponding to these M interfaces of the target business module. Therefore, the terminal device can compare the first set of operable object data and the second set of operable object data. If the first set of operable object data is greater than the second set of operable object data, it indicates that some memory has not been released, and the target business module in the application under test has experienced a memory leak.
[0065] In this embodiment, when detecting whether a memory leak has occurred, the comparison is made between the actual number of operable objects corresponding to each interface and the preset number of operable objects corresponding to each interface. This makes the comparison more targeted and improves the accuracy of memory leak detection. Furthermore, comparing at the business module level allows for pinpointing the type of business where the memory leak occurred, improving the granularity of the detection.
[0066] Understandable, Figure 1 The diagram illustrates a terminal device and a server. In real-world scenarios, many more types of terminal devices or servers can participate in the memory leak detection process. The specific number and types depend on the actual scenario and are not limited here. If multiple terminal devices participate in the memory leak detection process, these multiple terminal devices can constitute a memory leak detection system. For example, in the following description, the memory leak detection method is described using a terminal device as the execution subject, which has the application to be detected and the target application to be detected installed on it.
[0067] Optionally, the terminal device can be a device running Apple's mobile operating system (iOS), which includes the operating systems used by devices such as iPhone, iPad, iWatch, and macOS. For example, the following description will use a device running the iOS system as an example.
[0068] Servers can transfer their stored data to the cloud, where it forms a database. The cloud can include a database management system for managing different types of databases.
[0069] In this embodiment, the server can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing 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 terminal device can be a smartphone, tablet, laptop, desktop computer, smart speaker, smartwatch, in-vehicle terminal, smart TV, etc., but is not limited to these. The terminal device and the server can be directly or indirectly connected via wired or wireless communication, and the terminal device and the server can be connected to form a blockchain network; this application does not impose any restrictions.
[0070] The memory leak detection method proposed in this application is described below. Please refer to [link / reference]. Figure 2 , Figure 2 A flowchart for memory leak detection provided in this application embodiment, which includes at least the following steps:
[0071] 201. Obtain the object mapping list for the target business module in the application to be tested. The target business module indicates the target business type of the application to be tested. The object mapping list includes the mapping relationship between the interface identifier and the number of operable objects. The interface identifier is used to uniquely identify the interface of the target business module.
[0072] Before performing memory leak detection on the application under test, the terminal device can obtain an object mapping list for the target business module in the application under test. This object mapping list reflects the number of operable objects preset for each interface of the target business module in the application under test. Specifically, the object mapping list includes the mapping relationship between interface identifiers and the number of operable objects, with each interface identifier uniquely identifying an interface in the target business module.
[0073] For example, the object mapping list may include the contents shown in Table 1:
[0074] Table 1
[0075] Field Name Data types illustrate class_name string array Class Name page_id Integer array Interface Icons reference_count Integer array Number of classes corresponding to the interface subcontrol string array Child control class name subcontrol_count Integer array Number of child controls
[0076] As shown in Table 1, the sub-control class name can include user interface button (UIbutton) or user interface image view. For example, in interface 1 of the target business module, there can be 5 button classes, all of which can be of type UI button. The specific contents included in the object mapping list of the target business module are determined according to the actual application needs and are not limited here.
[0077] Understandably, during the operation of the application under test, the number of operable objects included in each interface will vary as the process changes. The object mapping list can be dynamically updated, making memory leak detection more accurate. For example, suppose the application under test is an instant messaging application logged in through a target communication account, and the target business module is the message sending and receiving module. The message list interface corresponding to the message sending and receiving module initially displays 3 chat boxes. Then, the value of "reference_count" stored in the object mapping list corresponding to the message list interface is 3. If, during the operation of the instant messaging application, a new communication account sends a conversation message to the target communication account, a new chat box will be added to the message list. In this case, the value of "reference_count" stored in the object mapping list corresponding to the message list interface will be updated to 4.
[0078] 202. Respond to the exit operation for the application to be tested, and obtain the first operable object data, wherein the first operable object data is the sum of the number of operable objects included in M interfaces, and M interfaces include the interfaces in the target business module that are in the running state before the application to be tested exits, and M is a positive integer.
[0079] When a user triggers the exit operation of the application under test, or when the terminal device's operating system triggers the exit operation of the application under test, the terminal device will respond to the exit operation for the application under test and obtain the first operable object data. Specifically, the terminal device can call the target application to calculate the first operable object data. The target application is used to test the application under test. The calculation rule can be to call a hook function, perform code instrumentation in the init method of the class hooked into the application under test, and generate a global static variable (all count) of the class through the associated attributes in method swizzling, thus obtaining the first operable object data. This first operable object data is the sum of the number of operable objects included in the M interfaces in the running state of the target business module before the application under test exits. In other words, the first operable object data reflects the actual sum of the number of operable objects in the target business module before the application under test exits.
[0080] 203. Obtain the second operable object data according to the object mapping list, wherein the second operable object data is the sum of the number of operable objects corresponding to M interface identifiers, and the M interface identifiers correspond one-to-one with the M interfaces.
[0081] After identifying M interfaces that were running in the target business module before the application under test exited, the terminal device queries the object mapping list based on the M interface identifiers corresponding to these M interfaces to obtain the second operable data. The second operable data is the sum of the number of operable objects corresponding to these M interface identifiers. It can be understood as a pre-defined sum of the number of operable objects for these M interfaces.
[0082] 204. If the data of the first operable object is greater than the data of the second operable object, then it is determined that there is a memory leak in the target business module.
[0083] After acquiring the first operable object data and the second operable object data, the terminal device compares the relationship between the two data. If the first operable object data is greater than the second operable object data, it means that the actual memory occupied by the M interfaces is greater than the preset memory, that is, there is memory space that should be released but has not been released. The terminal device determines that the target business module in the application under test has a memory leak.
[0084] Optionally, if the data of the first operable object is equal to the data of the second operable object, it means that the memory actually occupied by the M interfaces is equal to the preset memory, and the terminal device determines that there is no memory leak in the target business module of the application to be tested.
[0085] In the memory leak detection method provided in this application embodiment, upon detecting an exit operation for the application under test, first operable object data corresponding to M interfaces is obtained. The M interfaces include those in the running state of the target business module before the application exits, and M is a positive integer. The target business module indicates the target business type in the application under test. Based on the object mapping list, second operable object data corresponding to these M interfaces is obtained. Then, the first operable object data and the second operable object data are compared. If the first operable object data is greater than the second operable object data, it is determined that the target business module in the application under test has a memory leak. In this application embodiment, the target business module indicates the target business type in the application under test. A mapping relationship between interface identifiers and the number of operable objects is preset in the object mapping list of the target business module. The interface identifier is used to uniquely identify the interface of the target business module. When detecting whether a memory leak has occurred, the comparison is made between the actual number of operable objects corresponding to each interface and the preset number of operable objects corresponding to each interface, making the comparison more targeted and improving the accuracy of memory leak detection. Simultaneously, comparing at the business module level allows for the location of the business type experiencing the memory leak, improving the granularity of the detection.
[0086] Optionally, in the above Figure 2 Based on the corresponding embodiments, in an optional embodiment of the memory leak detection method provided in this application, the method further includes:
[0087] Display the first interface, which is the first interface of the target application module and includes the target control;
[0088] In response to a touch command for a target control, a second interface is displayed, wherein the second interface corresponds to the target business module;
[0089] In response to an exit operation for the application under test, obtain the first operable object data, including:
[0090] In response to the exit operation of the second interface, retrieve the data of the first operable object.
[0091] Understandably, in practical applications, there are multiple ways to exit the application being tested. You can exit from the target application module's main interface or from other interfaces within the target application module; the specific method is not limited here. The following section describes the exit method from interfaces other than the main interface.
[0092] For example, consider exiting the application under test from a secondary interface of the target application module. The secondary interface refers to the interface displayed by the terminal device in response to an operation command from the main interface of the target application module. This operation command can be a touch command for a control on the main interface, an operation command for an input field on the main interface, or other commands; specific details are not limited here. It is understood that during the operation of the target application module, regardless of which interface is currently accessed, the main interface is always running; that is, the data related to the main interface is not destroyed during the operation of the target application module. Therefore, when exiting the application under test from the secondary interface of the target application module, the interfaces that were running before exiting the application under test include both the main interface and the secondary interface. The first operable object data obtained by the terminal device is the sum of the number of operable objects corresponding to these two interfaces.
[0093] In scenarios where the application under test exits from a secondary interface of the target application module, the interface displayed by the application under test during operation can vary. It may display only the primary and secondary interfaces, or it may display multiple layers of interfaces. The possible scenarios are described below. In this embodiment, the primary interface can also be referred to as the first interface, and the secondary interface as the second interface.
[0094] 1. The application under test displays a first interface and a second interface during operation.
[0095] For example, let's illustrate this scenario using a search application as the application to be tested. The terminal device responds to an opening command for the search application, displaying its main interface. This main interface includes controls for accessing the target application module. The terminal device responds to a touch command for this control, displaying the first interface of the target application module. This first interface includes a target control, which can be understood as the entry point to the second interface. The terminal device responds to a touch command for the target control, displaying the second interface, which corresponds to the target business module. Assuming the target business module is the sports information module within the search application, indicating the business type related to sports information within the search application, and the target control is the "basketball" control in the channel bar of the first interface, then the terminal device responds to a touch command for the "basketball" control, displaying the second interface. This second interface can be called the basketball sports information interface, which can display basketball sports news, basketball events, or other basketball-related information; the specifics are not limited here.
[0096] It is understandable that the application under test may display the first and second interfaces multiple times during operation, and the content displayed on each second interface may differ. The number of times the application under test displays the first and second interfaces during operation is determined based on the actual needs of the application, and is not limited here.
[0097] For example, consider an application under test that displays a first interface and two second interfaces during operation. Specifically, the terminal device can respond to a touch command on a target control on the first interface to display the second interface. Then, it responds to a touch command on a first return control on the second interface to return to the first interface. Then, it responds to a touch command on another target control on the first interface to display a new second interface. For example, taking a search application as the application under test, and the target business module indicating the scenic spot information business type, the terminal device responds to a touch command on the "food" control on the first interface to display the second interface, which can be called the food information interface, displaying information about food from various places. This second interface also includes a first return control. The terminal device responds to a touch command on the first return control to display the first interface. Then, it responds to a touch command on the "transportation" control on the first interface to display a new second interface, which can be called the transportation information interface, displaying transportation information for various scenic spots.
[0098] 2. The application under test displays a first interface, a second interface, and a third interface during operation.
[0099] For example, let's illustrate this scenario using a video playback application as the target application. The terminal device responds to an open command for the video playback application, displaying its main interface. This main interface includes controls for accessing the target application module. Assuming the target business module is a movie service, the terminal device responds to a touch command on the "Movie" control on the main interface, displaying the first interface of the target application module, which includes the target control. The terminal device then responds to a touch command on the target control, displaying a second interface. Assuming the target control is the "Comedy" control in the category bar on the first interface, the terminal device responds to a touch command on the "Comedy" control, displaying the second interface, which can be called a comedy movie recommendation interface. This interface can display recommendation posters for at least one comedy movie. The terminal device can respond to a touch command on a specific recommendation poster, displaying the video playback interface. The video playback interface includes a second return control, and the terminal device responds to a touch command on this second return control, displaying the second interface. In this case, the video playback interface is closed, and the corresponding data information is released. In other words, the video playback interface has been destroyed, so the first operable object data includes the sum of the number of operable objects corresponding to the first interface and the second interface.
[0100] It is understandable that in practical applications, the application under test may display the first interface, the second interface, and other interfaces multiple times during operation. The specific number of times these interfaces are displayed depends on the needs of the actual application and is not limited here.
[0101] When exiting the application under test from the second interface of the target business module, in both of the above scenarios, the final interface displayed by the application under test before exiting is the second interface. That is, before exiting the application under test, the interfaces in the target business module that are running include both the first and second interfaces. The terminal device responds to the exit operation for the second interface, exiting the application under test and obtaining the number of operable objects corresponding to the first interface and the number of operable objects corresponding to the second interface. Then, the number of operable objects corresponding to the first interface and the number of operable objects corresponding to the second interface are summed to obtain the first operable object data.
[0102] Optionally, the exit operation for the second interface can be triggered by the user or by the terminal device itself. For example, in a scenario where the application under test crashes or malfunctions, the application under test automatically exits after the second interface is displayed. The exit operation for the second interface is determined according to the actual application needs, and is not limited here.
[0103] Optionally, there are multiple ways to enter one interface from another. Taking the application under test as a search application, and entering the second interface from the first interface as an example, the terminal device can not only respond to touch commands for the target control and display the second interface, but also respond to operation commands for the search bar on the first interface and display the second interface. The second interface can be called the search results interface, and at least one search result can be displayed on the second interface. In addition, the terminal device can also enter the second interface from the first interface in other ways, for example, responding to a selection command for target information in the recommended information list on the first interface and displaying the second interface, which displays the detailed content of the target information.
[0104] It is understandable that the above examples are based on the scenario of the application being tested being a search application or a video playback application. In actual applications, the application being tested can also be other applications, such as instant messaging applications, video playback applications, etc., depending on the needs of the actual application. No specific limitations are made here. The type and presentation of the target controls will also differ depending on the application being tested, and the content of the second interface will also change accordingly. No specific limitations are made here.
[0105] In this embodiment, when the application to be tested is exited through the second interface, the first operable object data obtained by the terminal device is the sum of the number of operable objects corresponding to the first and second interfaces, which conforms to the actual situation. Furthermore, there are multiple scenarios for exiting the application to be tested through the second interface, enriching the memory leak detection method provided in this embodiment and improving the flexibility of the detection.
[0106] Optionally, in the above Figure 2 Based on the corresponding embodiments, in an optional embodiment of the memory leak detection method provided in this application, the method further includes:
[0107] Display the first interface, which is the first interface of the target application module and includes the target control;
[0108] In response to a touch command for a target control, a second interface is displayed, wherein the second interface corresponds to the target business module;
[0109] In response to an exit action from the second screen, the first screen is displayed.
[0110] In response to an exit operation for the application under test, obtain the first operable object data, including:
[0111] In response to the exit operation of the first interface, obtain the data of the first operable object.
[0112] The following describes the scenario of exiting the application under test from its initial interface. The terminal device responds to the opening command for the application under test and displays its main interface. This main interface includes controls for accessing the target application module. The terminal device responds to a touch command on these controls and displays the first interface of the target application module. Optionally, in the scenario of exiting the application under test from its first interface, the interface displayed during the application's operation can vary; it may only display the first interface, or it may display both the first interface and other interfaces. This is not limited here. However, regardless of the specific scenario, the application under test exits through its first interface. For example, the terminal device responds to a touch command on a target control on the first interface and displays a second interface, where the second interface corresponds to the target business module. Then, it responds to an exit operation on the second interface and displays the first interface. That is, during the operation of the application under test, both the first and second interfaces are displayed, and an operation command on the second interface returns the user to the first interface.
[0113] In the scenario where the application under test exits from the first interface of the target business module, the interface ultimately displayed by the application under test before exiting is the first interface. In other words, the interfaces in the target business module that are running before the application under test exits include the first interface. The terminal device responds to the exit operation for the first interface, exiting the application under test and obtaining the number of operable objects corresponding to the first interface, i.e., obtaining the first operable object data.
[0114] Optionally, the exit operation for the first screen can be triggered by the user or by the terminal device itself. For example, in a scenario where the application under test crashes or malfunctions, the application under test automatically exits after the first screen is displayed. The exit operation for the first screen is determined according to the actual application needs, and is not limited here.
[0115] In this embodiment, when the application to be tested is exited through the first interface, the first operable object data obtained by the terminal device is the number of operable objects corresponding to the first interface, which conforms to the actual situation. Furthermore, there are multiple scenarios for exiting the application to be tested through the first interface, enriching the memory leak detection method provided in this embodiment and improving the flexibility of the detection.
[0116] Optionally, besides exiting the application under test through its first or second interface, users can also exit through other interfaces of the application under test. For example, suppose the terminal device displays a second interface through the first interface of the target business module, then displays a third interface through the second interface, and then exits the application under test in response to an exit operation for the third interface. In this case, the interfaces that were running before the application under test exited include the first, second, and third interfaces. The first operable object data obtained by the terminal device is the sum of the number of operable objects corresponding to these three interfaces. In general, regardless of how many interfaces the application under test displays in actual application, the first operable object data is obtained by summing the number of operable objects corresponding to each interface that was running in the target business module before the application under test exited.
[0117] Optionally, in the above Figure 2 Based on the corresponding embodiments, in an optional embodiment of the memory leak detection method provided in this application, before obtaining the object mapping list for the application to be detected, the method further includes:
[0118] Create a target application, which is used to detect the application to be detected;
[0119] The application identifier of the application to be tested is sent to the server through the data transmission interface of the target application, so that the server can create a detection file corresponding to the application to be tested. The detection file includes an object mapping list.
[0120] In this embodiment, the terminal device will build a separate target application and transmit information such as the operation rules and running status of the application to be detected to the target application, thereby enabling the target application to perform detection. Optionally, the target application can be created in various ways, such as using Vue or Flutter. In addition, other methods can be used to create the target application, such as using React Native or Weex; the specific method is not limited here.
[0121] In this embodiment of the application, the object mapping list of the application to be detected is stored on a server. The following is in conjunction with... Figure 3a For further explanation, please refer to [link / reference]. Figure 3a , Figure 3a A schematic diagram illustrating an application scenario of the memory leak detection method provided in this application.
[0122] like Figure 3a As shown, when a terminal device first invokes the application to be tested, A, the target application can obtain the application identifier of A and send it to the server through the target application's data transmission interface. After receiving the application identifier, the server creates a detection file A corresponding to A in its database. Detection file A includes an object mapping list of each business module in application A. The database type on the server can be various, including SQLite, but other types are not limited here. The data transmission interface type can be an upload objective interface or other types, also without limitation. Detection file A can also be called Memoryleak_AppA.db.
[0123] Optionally, in this embodiment of the application, the target application can simultaneously detect memory leaks in multiple applications to be detected. Figure 3a In the illustrated embodiment, the detection of memory leaks by the target application is exemplified by application A and application B to be detected. Application A corresponds to detection file A, and application B corresponds to detection file B. In practical applications, the target application can also detect a larger number of applications to be detected; this is not limited here.
[0124] Optionally, the test files for different applications can be stored in the same database on the server, thus saving memory resources used by the server to create multiple databases. Alternatively, the test files for different applications can be stored separately in different databases on the server, ensuring independence between the files and avoiding the adverse effects of database failures caused by having all test files in the same database. In practical applications, other storage methods for different test files are also possible; for example, some can be stored separately in their own databases, while others can be stored collectively in a single database. The choice of storage method depends on the specific application requirements and is not limited here.
[0125] In this embodiment, the application to be detected is distinguished from the target application, ensuring that the normal operation of the application to be detected is not affected by memory leak detection. Furthermore, the target application can simultaneously detect memory leaks in multiple applications to be detected, improving the efficiency of the memory leak detection method provided in this embodiment. Additionally, storing the object mapping list of the applications to be detected on a server in this embodiment also saves memory resources on the terminal device.
[0126] Optionally, in the above Figure 2 Based on the corresponding embodiments, in an optional embodiment of the memory leak detection method provided in this application, the memory leak detection method further includes:
[0127] The target application is called to divide the business types of the application to be tested into target business modules, whereby the target application is used to test the application to be tested;
[0128] Obtain the mapping relationship between the interface identifier corresponding to the target business module and the number of operable objects;
[0129] The mapping relationship between the interface identifier of the target business module and the number of operable objects is sent to the server through the data transmission interface of the target application.
[0130] Understandably, in practical applications, the application under test can be divided into different business modules. Different business modules correspond to different business types, and their interfaces and operable objects will also differ. The terminal device can invoke the target application, dividing the application under test according to business type to obtain at least one business module, with the target business module contained within at least one business module. For example, suppose the application under test is a video playback application. The video playback application may include business modules such as movie business modules, TV series business modules, variety show business modules, and children's business modules. Assuming the target business module is a movie business module, the terminal device can receive the mapping relationship between the interface identifier and the number of operable objects corresponding to the movie business module, input by the developer. The movie business module can correspond to at least one interface, and the interface identifier is used to uniquely identify an interface. After obtaining the mapping relationship, the terminal device can invoke the target application's data transmission interface to send the mapping relationship to the server, so that the server can establish an object mapping list corresponding to the target business module in the test file of the application under test.
[0131] The following is combined with Figure 3b For further explanation, please refer to [link / reference]. Figure 3b , Figure 3b A schematic diagram illustrating the mapping relationship between the business modules and the object mapping list provided for the implementation of this application.
[0132] like Figure 3b As shown, the application A to be tested can be divided into business module a, business module b, and business module c, and each business module has a corresponding object mapping list. For example, business module a corresponds to object mapping list a. The business modules divided for different applications to be tested will vary, depending on the actual application needs, and are not limited here.
[0133] Optionally, the object mapping list can also store the contact information of the developers corresponding to each business module, such as email accounts or mobile phone numbers, so as to promptly notify the developers to handle the memory leak when a memory leak is detected in the business module.
[0134] In this embodiment, the application to be tested is divided into different business modules, and each business module has a corresponding object mapping list. This allows the terminal device to detect which business module of the application to be tested is causing the memory leak when performing memory leak detection, thereby further improving the accuracy of the detection.
[0135] Optionally, in the above Figure 2 Based on the corresponding embodiments, in an optional embodiment of the memory leak detection method provided in this application, obtaining an object mapping list for the application to be detected includes:
[0136] Send a list retrieval request to the server, wherein the list retrieval request carries the application identifier of the application to be detected, and the M interface identifiers corresponding to the M interfaces;
[0137] Based on the application identifier and M interface identifiers, the target application receives an object mapping list from the server through its data transmission interface. The target application is used to detect the application to be detected.
[0138] In this embodiment, the terminal device can obtain the object mapping list of the target business module in the application to be tested through the target application. Specifically, after determining that M interfaces in the target business module are running before the application to be tested exits, the terminal device can send a list retrieval request to the server. The list retrieval request carries the application identifier of the application to be tested and the M interface identifiers corresponding to these M interfaces. The list retrieval request is used to obtain the object mapping list corresponding to these M interface identifiers in the target business module.
[0139] After receiving the list retrieval request, the server can determine the detection file corresponding to the application to be tested based on the application identifier, and then determine the object mapping list corresponding to the M interface identifiers from the detection file based on the M interface identifiers. The object mapping list is then sent to the terminal device. Since the target application is the application being tested, the terminal device can receive the object mapping list from the server through the target application's data interface.
[0140] In this embodiment, the application to be tested and the target application are distinguished. The testing of the application to be tested is performed by the target application, which ensures that the application to be tested and the target application are independent of each other and do not affect the normal operation of the application to be tested.
[0141] Optionally, in the above Figure 2 Based on the corresponding embodiments, in an optional embodiment of the memory leak detection method provided in this application, before obtaining the first operable object data in response to an exit operation for the application to be detected, the method further includes:
[0142] The first creation method of the application to be tested is replaced with the second creation method, and the first release method of the application to be tested is replaced with the second release method. The first creation method is used to create an operable object, the first release method is used to destroy the operable object, the second creation method includes the function of creating an operable object and a first counting function, and the second release method includes the function of destroying an operable object and a second counting function.
[0143] Based on the number of calls to the second creation method, the first counting function, the number of calls to the second release method, and the second counting function, the number of operable objects in the target business module is recorded, wherein the number of operable objects is used to determine the first operable object data.
[0144] In this embodiment, the terminal device can replace the first creation method and the first release method of the application under test by calling the method exchange implementations. Specifically, the first creation method of the application under test is replaced with a second creation method, and the first release method is replaced with a second release method. The first creation method is used to create operable objects, and the first release method is used to destroy operable objects. The second creation method, in addition to the operable object creation function of the first creation method, also includes a first counting function. The second release method, in addition to the operable object destruction function of the first release method, also includes a second counting function. That is, the second creation method retains the execution logic of the first creation method, and the second release method retains the execution logic of the first release method, without affecting the normal operation of the application under test. Furthermore, both the second creation method and the second release method have memory leak detection capabilities.
[0145] During the operation of the application under test, it will call the second creation method or the second release method. The terminal device will record the number of times the application under test calls the second creation method and the second release method, and, in conjunction with the first counting function and / or the second counting function, record the changes in the number of operable objects in the application under test. Specifically, when the terminal device detects that the application under test has called the second creation method once, it will increment the number of operable objects by one; when it detects that the application under test has called the second release method once, it will decrement the number of operable objects by one.
[0146] In this embodiment, by replacing the first creation method and the first release method of the application to be detected, it is easier to detect changes in the number of operable objects during the operation of the application to be detected, making the detection of the application to be detected more accurate and further improving the accuracy of the memory leak detection method provided in this embodiment.
[0147] It's understandable that during the execution of the application under test, the number of certain operable objects will always be greater than zero, such as singleton objects. Besides these, other types of operable objects can also exist, such as static variables; specific examples are not limited here. A singleton object is a special class that has exactly one instance. It is not destroyed when the application under test terminates. For example, user data objects are common singletons; if destroyed, the caller retrieving user data will receive empty data, leading to display errors or crashes. Static variables refer to variables modified by the `static` keyword, such as usernames and passwords.
[0148] The following explanation uses a singleton object as an example to illustrate the process of memory leaks. Please refer to [link / reference]. Figure 4 , Figure 4 Another flowchart illustrating the memory leak detection method provided in this application embodiment includes:
[0149] 401. Start the application to be tested.
[0150] 402. Query the object mapping list of the target business module in the application to be tested.
[0151] After launching the application to be tested, the terminal device can notify the target application to obtain the object mapping list of the application to be tested.
[0152] 403. Distribute the hook files corresponding to the target business modules.
[0153] After obtaining the object mapping list of the target business module, the target application can call the hook function to perform hook operations on the object mapping list, that is, to send the hook file corresponding to the target business module, so as to record the changes in the number of operable objects corresponding to the target business module during the operation of the application under test.
[0154] 404. Monitor the operation process of the application to be tested.
[0155] Terminal devices can invoke the target application to detect the running process of the application under test. Specifically, this can be achieved by loading hook files through method swizzling technology. During the running of the application under test, the second creation method and the second release method are initialized, and the number of times the application under test calls the second creation method and the second release method is recorded to facilitate obtaining the first operable object data.
[0156] 405. Determine whether the target business module includes the target singleton object. If yes, proceed to step 406; otherwise, proceed to step 407.
[0157] The terminal device also detects the creation of the target singleton object, specifically determining whether the target business module still includes the target singleton object. The target singleton object refers to a singleton object that is not included in the object mapping list of the target business module. If the target business module still includes the target singleton object, it means the data in the object mapping list is incomplete and needs to be updated. If the target business module does not include the target singleton object, it means the data in the object mapping list is complete and does not need to be updated; the terminal device can then proceed to the memory leak detection logic.
[0158] 406. Write the target singleton object into the object mapping list of the target business module.
[0159] If the data in the object mapping list is incomplete, the terminal device will write the target singleton object into the object mapping list of the target business module in the application under test to update the object mapping list. Writing the target singleton object includes writing the corresponding interface identifier, the number of target singleton objects, and their type into the object mapping list.
[0160] Alternatively, terminal devices can use a multi-core programming solution (grand central dispatch, GCD) to automatically map singleton objects to an object mapping list while ensuring thread safety.
[0161] 407. Response to exit operations of the application under test, calculate memory leak information.
[0162] When a terminal device responds to an exit operation for the application under test, it calculates the memory leak information of the application. This memory leak information includes the first and second operable data corresponding to the M interfaces that are running in the target business module before the application exits. The first operable data is the sum of the actual number of operable objects corresponding to these M interfaces, and the second operable data is the sum of the preset number of operable objects for these M interfaces. If the first operable data is greater than the second operable data, the terminal device can determine that a memory leak has occurred in the target business module.
[0163] Optionally, after receiving the detection results, the terminal device can send a notification to the developers of the application to be tested or the target business module, so that the developers can be informed of the memory leak in a timely manner and fix it promptly.
[0164] To better implement the above-described solutions of the embodiments of this application, related apparatus for implementing the above solutions is also provided below. Please refer to... Figure 5 , Figure 5 This is a schematic diagram of a memory leak detection device provided in an embodiment of this application. The memory leak detection device 500 includes:
[0165] Acquisition unit 501 is used for:
[0166] Obtain an object mapping list for the target business module in the application to be tested. The target business module indicates the target business type of the application to be tested. The object mapping list includes the mapping relationship between the interface identifier and the number of operable objects. The interface identifier is used to uniquely identify the interface of the target business module.
[0167] In response to an exit operation for the application under test, first operable object data is obtained, wherein the first operable object data is the sum of the number of operable objects included in M interfaces, and M interfaces include the interfaces that were running in the target business module before the application under test exited, where M is a positive integer;
[0168] The second operable object data is obtained from the object mapping list. The second operable object data is the sum of the number of operable objects corresponding to M interface identifiers, and the M interface identifiers correspond one-to-one with the M interfaces.
[0169] The processing unit 502 is used to determine that there is a memory leak in the target business module if the data of the first operable object is greater than the data of the second operable object.
[0170] Optionally, in the above Figure 5 Based on the corresponding embodiments, in another embodiment of the memory leak detection device 500 provided in this application, the memory leak detection device 500 includes:
[0171] Display unit 503, used for:
[0172] Display the first interface, which is the first interface of the target application module and includes the target control;
[0173] In response to a touch command for a target control, a second interface is displayed, wherein the second interface corresponds to the target business module;
[0174] The acquisition unit 501 is specifically used to respond to the exit operation for the second interface and acquire the data of the first operable object.
[0175] Optionally, in the above Figure 5 Based on the corresponding embodiments, in another embodiment of the memory leak detection device 500 provided in this application, the memory leak detection device 500 further includes a display unit 503, used for:
[0176] Display the first interface, which is the first interface of the target application module and includes the target control;
[0177] In response to a touch command for a target control, a second interface is displayed, wherein the second interface corresponds to the target business module;
[0178] In response to an exit action from the second screen, the first screen is displayed.
[0179] The acquisition unit 501 is specifically used to respond to the exit operation for the first interface and acquire the data of the first operable object.
[0180] Optionally, in the above Figure 5 Based on the corresponding embodiments, in another embodiment of the memory leak detection device 500 provided in this application, the memory leak detection device further includes a sending unit 504;
[0181] The processing unit 502 is also configured to create a target application, wherein the target application is used to detect the application to be detected;
[0182] The sending unit 504 is also used to send the application identifier of the application to be detected to the server through the data transmission interface of the target application, so that the server can create a detection file corresponding to the application to be detected, and the detection file includes an object mapping list.
[0183] Optionally, in the above Figure 5 Based on the corresponding embodiments, in another embodiment of the memory leak detection device 500 provided in this application, the memory leak detection device 500 further includes a sending unit 504;
[0184] The processing unit 502 is also used to call the target application to divide the business type of the application to be detected and obtain the target business module, wherein the target application is used to detect the application to be detected;
[0185] The acquisition unit 501 is also used to acquire the mapping relationship between the interface identifier corresponding to the target business module and the number of operable objects;
[0186] The sending unit 504 is also used to send the mapping relationship between the interface identifier of the target business module and the number of operable objects to the server through the data transmission interface of the target application.
[0187] Optionally, in the above Figure 5 Based on the corresponding embodiments, in another embodiment of the memory leak detection device 500 provided in this application, the memory leak detection device 500 further includes a sending unit 504;
[0188] The sending unit 504 is also used to send a list retrieval request to the server, wherein the list retrieval request carries the application identifier of the application to be detected, and the M interface identifiers corresponding to the M interfaces.
[0189] The acquisition unit 501 is also used to receive an object mapping list from the server through the data transmission interface of the target application based on the application identifier and M interface identifiers, wherein the target application is used to detect the application to be detected.
[0190] Optionally, in the above Figure 5 Based on the corresponding embodiments, in another embodiment of the memory leak detection device 500 provided in this application, the memory leak detection device 500 includes:
[0191] Processing unit 502 is also used for:
[0192] The first creation method of the application to be tested is replaced with the second creation method, and the first release method of the application to be tested is replaced with the second release method. The first creation method is used to create an operable object, the first release method is used to destroy the operable object, the second creation method includes the function of creating an operable object and a first counting function, and the second release method includes the function of destroying an operable object and a second counting function.
[0193] Based on the number of calls to the second creation method, the first counting function, the number of calls to the second release method, and the second counting function, the number of operable objects in the target business module is recorded, wherein the number of operable objects is used to determine the first operable object data.
[0194] This application provides a computer device that can be based on... Figure 6 Please refer to the structure shown. Figure 6 , Figure 6 A schematic diagram of the structure of a computer device provided in an embodiment of this application.
[0195] like Figure 6 As shown, for ease of explanation, only the parts related to the embodiments of this application are shown. For specific technical details not disclosed, please refer to the method section of the embodiments of this application. The computer device can be any terminal device including a personal computer (PC), tablet computer, personal digital assistant (PDA), etc. Taking a PC as an example:
[0196] Figure 6 This is a block diagram illustrating a portion of the structure of a PC related to the computer device provided in an embodiment of this application. (Reference) Figure 6 The PC includes components such as a radio frequency (RF) circuit 610, a memory 620, an input unit 630, a display unit 640, a sensor 650, an audio circuit 660, a WiFi module 670, a processor 680, and a power supply 690. Those skilled in the art will understand that... Figure 6 The PC structure shown does not constitute a limitation on the PC and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0197] The following is combined with Figure 6 A detailed introduction to each component of a PC:
[0198] RF circuit 610 can be used for receiving and transmitting signals during information transmission or calls. Specifically, it receives downlink information from the base station and processes it with processor 680; additionally, it transmits uplink data to the base station. Typically, RF circuit 610 includes, but is not limited to, an antenna, at least one amplifier, a transceiver, a coupler, a low-noise amplifier (LNA), a duplexer, etc. Furthermore, RF circuit 610 can also communicate wirelessly with networks and other devices. The aforementioned wireless communication can use any communication standard or protocol, including but not limited to Global System for Mobile Communication (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Long Term Evolution (LTE), email, Short Message Service (SMS), etc.
[0199] The memory 620 can be used to store software programs and modules. The processor 680 executes various PC functions and data processing by running the software programs and modules stored in the memory 620. The memory 620 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a 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 PC (such as audio data, phone book, etc.). In addition, the memory 620 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.
[0200] The input unit 630 can be used to receive input numerical or character information, and to generate key signal inputs related to user settings and function control of the PC. Specifically, the input unit 630 may include a touch panel 1031 and other input devices 1032. The touch panel 1031, also known as a touch screen, can collect touch operations performed by the user on or near it (such as operations performed by the user using a finger, stylus, or any suitable object or accessory on or near the touch panel 631), and drive the corresponding connection devices according to a pre-set program. Optionally, the touch panel 631 may include two parts: a touch detection device and a touch controller. The touch detection device detects the user's touch position and the signal generated by the touch operation, and transmits the signal to the touch controller; the touch controller receives touch information from the touch detection device, converts it into touch point coordinates, sends it to the processor 680, and can receive and execute commands sent by the processor 680. In addition, the touch panel 631 can be implemented using various types such as resistive, capacitive, infrared, and surface acoustic wave. In addition to the touch panel 631, the input unit 630 may also include other input devices 632. Specifically, other input devices 632 may include, but are not limited to, one or more of the following: physical keyboard, function keys (such as volume control buttons, power buttons, etc.), trackball, mouse, joystick, etc.
[0201] Display unit 640 can be used to display information input by the user or information provided to the user, as well as various menus of the PC. Display unit 640 may include a display panel 641, optionally configured as a liquid crystal display (LCD), organic light-emitting diode (OLED), or similar form. Further, a touch panel 631 may cover the display panel 641. When the touch panel 631 detects a touch operation on or near it, it transmits the information to the processor 680 to determine the type of touch event. Subsequently, the processor 680 provides corresponding visual output on the display panel 641 based on the type of touch event. Although in Figure 6 In this embodiment, the touch panel 631 and the display panel 641 are two separate components to realize the input and output functions of the PC. However, in some embodiments, the touch panel 631 and the display panel 641 can be integrated to realize the input and output functions of the PC.
[0202] The PC may also include at least one sensor 650, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor may include an ambient light sensor and a proximity sensor. The ambient light sensor can adjust the brightness of the display panel 641 according to the ambient light level, and the proximity sensor can turn off the display panel 1041 and / or backlight when the PC is moved to the ear. As a type of motion sensor, an accelerometer sensor can detect the magnitude of acceleration in various directions (generally three axes). When stationary, it can detect the magnitude and direction of gravity, and can be used for applications that identify the PC's posture (such as landscape / portrait switching, related games, magnetometer posture calibration), vibration recognition functions (such as pedometers, taps), etc. Other sensors that the PC may be equipped with, such as gyroscopes, barometers, hygrometers, thermometers, and infrared sensors, will not be described in detail here.
[0203] Audio circuit 660, speaker 661, and microphone 662 provide an audio interface between the user and the PC. Audio circuit 660 converts received audio data into electrical signals and transmits them to speaker 661, where speaker 661 converts them into sound signals for output. On the other hand, microphone 662 converts collected sound signals into electrical signals, which are received by audio circuit 660, converted into audio data, and then output to processor 680 for processing. The audio data is then transmitted via RF circuit 610 to, for example, another PC, or output to memory 620 for further processing.
[0204] WiFi is a short-range wireless transmission technology. A PC using a WiFi module 670 can help users send and receive emails, browse web pages, and access streaming media, providing wireless broadband internet access. Although Figure 6 WiFi module 670 is shown, but it is understood that it is not an essential component of a PC and can be omitted as needed without changing the nature of the invention.
[0205] The processor 680 is the control center of the PC, connecting various parts of the PC through various interfaces and lines. It performs various PC functions and processes data by running or executing software programs and / or modules stored in the memory 620, and by calling data stored in the memory 620, thereby providing overall monitoring of the PC. Optionally, the processor 680 may include one or more processing units; optionally, the processor 680 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 aforementioned modem processor may also not be integrated into the processor 680.
[0206] The PC also includes a power supply 690 (such as a battery) that supplies power to various components. Optionally, the power supply can be logically connected to the processor 680 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system.
[0207] Although not shown, a PC may also include a camera, Bluetooth module, etc., which will not be described in detail here.
[0208] In this embodiment of the application, the processor 680 included in the computer device further has the following functions:
[0209] Obtain an object mapping list for the target business module in the application to be tested. The target business module indicates the target business type of the application to be tested. The object mapping list includes the mapping relationship between the interface identifier and the number of operable objects. The interface identifier is used to uniquely identify the interface of the target business module.
[0210] In response to the exit operation of the application to be tested, the first operable object data is obtained, wherein the first operable object data is the sum of the number of operable objects included in M interfaces, and the M interfaces include the interfaces in the target business module that are in the running state before the application to be tested exits, where M is a positive integer;
[0211] The second operable object data is obtained from the object mapping list. The second operable object data is the sum of the number of operable objects corresponding to M interface identifiers, and the M interface identifiers correspond one-to-one with the M interfaces.
[0212] If the data of the first operable object is greater than the data of the second operable object, then it is determined that there is a memory leak in the target business module.
[0213] The processor 680 included in the computer device can also perform... Figures 1 to 4 The operations performed by the terminal device will not be described in detail here.
[0214] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0215] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection between apparatuses or units through some interfaces, and may be electrical, mechanical, or other forms.
[0216] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0217] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0218] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, an interactive video management device, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0219] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. A method for detecting memory leaks, characterized in that, include: Obtain an object mapping list for a target business module in the application to be tested, wherein the target business module indicates the target business type of the application to be tested, and the object mapping list includes a mapping relationship between interface identifiers and the number of operable objects, wherein the interface identifier is used to uniquely identify the interface of the target business module; In response to the exit operation of the application to be detected, first operable object data is obtained, wherein the first operable object data is the sum of the number of operable objects included in M interfaces, the M interfaces include the interfaces in the target business module that were in running state before the application to be detected exits, and M is a positive integer; The second operable object data is obtained according to the object mapping list, wherein the second operable object data is the sum of the number of operable objects corresponding to M interface identifiers, and the M interface identifiers correspond one-to-one with the M interfaces. If the data of the first operable object is greater than the data of the second operable object, then it is determined that the target business module has a memory leak.
2. The method according to claim 1, characterized in that, The method further includes: Display a first interface, wherein the first interface is the first interface of the target application module, and the first interface includes target controls; In response to a touch command for the target control, a second interface is displayed, wherein the second interface corresponds to the target business module; The response addresses the exit operation of the application under test, and acquires first operable object data, including: In response to an exit operation on the second interface, the data of the first operable object is obtained.
3. The method according to claim 1, characterized in that, The method further includes: Display a first interface, wherein the first interface is the first interface of the target application module, and the first interface includes target controls; In response to a touch command for the target control, a second interface is displayed, wherein the second interface corresponds to the target business module; In response to an exit operation on the second interface, the first interface is displayed; The response addresses the exit operation of the application under test, and acquires first operable object data, including: In response to an exit operation on the first interface, the data of the first operable object is obtained.
4. The method according to any one of claims 1 to 3, characterized in that, Before obtaining the list of object mappings for the application to be detected, the method further includes: Create a target application, wherein the target application is used to detect the application to be detected; The application identifier of the application to be detected is sent to the server through the data transmission interface of the target application, so that the server can create a detection file corresponding to the application to be detected, and the detection file includes the object mapping list.
5. The method according to any one of claims 1 to 3, characterized in that, The method further includes: The target application is invoked to classify the business types of the application to be detected, thereby obtaining the target business modules, wherein the target application is used to detect the application to be detected; Obtain the mapping relationship between the interface identifier corresponding to the target business module and the number of operable objects; The mapping relationship between the interface identifier and the number of operable objects corresponding to the target business module is sent to the server through the data transmission interface of the target application.
6. The method according to any one of claims 1 to 3, characterized in that, The step of obtaining the object mapping list for the application to be detected includes: Send a list retrieval request to the server, wherein the list retrieval request carries the application identifier of the application to be detected, and the M interface identifiers corresponding to the M interfaces; Based on the application identifier and the M interface identifiers, the target application receives the object mapping list from the server through the data transmission interface of the target application, wherein the target application is used to detect the application to be detected.
7. The method according to any one of claims 1 to 3, characterized in that, Before obtaining the first operable object data in response to the exit operation of the application to be detected, the method further includes: The first creation method of the application to be tested is replaced with the second creation method, and the first release method of the application to be tested is replaced with the second release method. The first creation method is used to create an operable object, and the first release method is used to destroy the operable object. The second creation method includes the function of creating an operable object and a first counting function, and the second release method includes the function of destroying an operable object and a second counting function. Based on the number of calls to the second creation method, the first counting function, the number of calls to the second release method, and the second counting function, the number of operable objects in the target business module is recorded, wherein the number of operable objects is used to determine the first operable object data.
8. A memory leak detection device, characterized in that, include: The acquisition unit is used to acquire an object mapping list for a target business module in the application to be tested, wherein the target business module indicates the target business type of the application to be tested, and the object mapping list includes a mapping relationship between interface identifiers and the number of operable objects, and the interface identifier is used to uniquely identify the interface of the target business module; In response to the exit operation of the application to be detected, first operable object data is obtained, wherein the first operable object data is the sum of the number of operable objects included in M interfaces, the M interfaces include the interfaces in the target business module that were in running state before the application to be detected exits, and M is a positive integer; The second operable object data is obtained according to the object mapping list, wherein the second operable object data is the sum of the number of operable objects corresponding to M interface identifiers, and the M interface identifiers correspond one-to-one with the M interfaces. The processing unit is configured to determine that there is a memory leak in the target business module if the data of the first operable object is greater than the data of the second operable object.
9. A computer device, characterized in that, The computer device includes a processor and memory: The memory is used to store program code; the processor is used to execute the memory leak detection method according to any one of claims 1 to 7 according to the instructions in the program code.
10. A computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform the memory leak detection method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Image resource processing method, device and terminal
CN104267996A
Memory leak detection method and device, electronic equipment and readable storage medium
CN111506500A