Memory leakage object determination method and device, storage medium and electronic equipment
Patent Information
- Application Number
- CN202510573934.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-29
- Publication Date
- 2026-10-30
AI Technical Summary
[0006]本申请实施例提供了一种内存泄漏对象的确定方法和装置、存储介质及电子设备,以至少解决内存泄漏对象的确定效率较低的技术问题
[0011]根据本申请实施例的又一方面,还提供了一种电子设备,包括存储器和处理器,上述存储器中存储有计算机程序,上述处理器被设置为通过所述计算机程序执行上述的内存泄漏对象的确定方法。
Smart Images

Figure CN123011562A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computers, and more specifically, to a method and apparatus for identifying memory leak objects, a storage medium, and an electronic device. Background Technology
[0002] In modern software development, especially for complex web applications, memory leaks are a common problem that can severely impact application performance, stability, and user experience. A memory leak occurs when a program fails to release memory it no longer needs after using it, preventing this memory from being reclaimed and causing it to occupy system resources for an extended period. Furthermore, as applications become larger and more complex, the difficulty of memory management also gradually increases.
[0003] Currently, the common method for identifying memory leaks in related technologies is to use memory leak detection tools to monitor memory usage. Then, if abnormal memory usage is detected, professional technicians manually identify the objects causing memory leaks.
[0004] However, this method of relying on manually identifying memory leak objects is time-consuming, resulting in a technical problem of low efficiency in identifying memory leak objects.
[0005] There is currently no effective solution to the above problems. Summary of the Invention
[0006] This application provides a method and apparatus for determining memory leak objects, a storage medium, and an electronic device, to at least solve the technical problem of low efficiency in determining memory leak objects.
[0007] According to one aspect of the embodiments of this application, a method for determining a memory leak object is provided, comprising: creating a first data structure when the operation state of a target application is in a first operation state; adding object information of a data object corresponding to a target operation function applied in the second operation state to a first data structure and a second data structure when the operation state of the target application is switched to a second operation state; destroying the data object corresponding to the target operation function and removing the object information of the data object corresponding to the target operation function from the second data structure when the operation state of the target application is restored to the first operation state; comparing the object information stored in the first data structure and the object information stored in the second data structure; and determining the data object corresponding to the same object information as a memory leak object when the comparison result indicates that there is the same object information in the first data structure and the second data structure.
[0008] According to another aspect of the embodiments of this application, a device for determining memory leak objects is also provided, comprising: a creation unit, configured to create a first data structure when the operation state of a target application is in a first operation state; an addition unit, configured to add object information of a data object corresponding to a target operation function applied in the second operation state to the first data structure and a second data structure when the operation state of the target application is switched to a second operation state; a removal unit, configured to destroy the data object corresponding to the target operation function and remove the object information of the data object corresponding to the target operation function from the second data structure when the operation state of the target application is restored to the first operation state; a comparison unit, configured to compare the object information stored in the first data structure and the object information stored in the second data structure; and a determination unit, configured to determine the data object corresponding to the same object information as a memory leak object when the comparison result indicates that the first data structure and the second data structure contain the same object information.
[0009] According to another aspect of the embodiments of this application, a computer-readable storage medium is also provided, wherein a computer program is stored in the computer program, and the computer program is configured to execute the above-described method for determining memory leak objects at runtime.
[0010] According to another aspect of the embodiments of this application, a computer program product or computer program is provided, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the method for determining memory leak objects as described above.
[0011] According to another aspect of the embodiments of this application, an electronic device is also provided, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to execute the above-described method for determining memory leak objects through the computer program.
[0012] In this embodiment, when the target application is in a first operating state, a first data structure is created. When the target application's operating state is switched to a second operating state, the object information of the data object corresponding to the target operation function applied in the second operating state is added to both the first and second data structures. When the target application's operating state is restored to the first operating state, the data object corresponding to the target operation function is destroyed, and the object information of the data object corresponding to the target operation function is removed from the second data structure. The object information stored in the first and second data structures is compared. If the comparison result indicates that there is identical object information in the first and second data structures, the data object corresponding to the identical object information is identified as a memory leak object. In other words, by adopting this embodiment, the efficiency of identifying memory leak objects is improved, and the technical problem of low efficiency in identifying memory leak objects is solved. Attached Figure Description
[0013] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0014] Figure 1 This is a flowchart of an optional method for determining memory leak objects according to an embodiment of this application;
[0015] Figure 2 This is a schematic diagram of the organizational structure of an object according to an embodiment of this application;
[0016] Figure 3 This is a schematic diagram of another optional method for determining memory leak objects according to an embodiment of this application;
[0017] Figure 4 This is a schematic diagram of another optional method for determining memory leak objects according to an embodiment of this application;
[0018] Figure 5 This is a schematic diagram of another optional method for determining memory leak objects according to an embodiment of this application;
[0019] Figure 6 This is a schematic diagram of another optional method for determining memory leak objects according to an embodiment of this application;
[0020] Figure 7 This is a schematic diagram of another optional method for determining memory leak objects according to an embodiment of this application;
[0021] Figure 8This is a schematic diagram of another optional method for determining memory leak objects according to an embodiment of this application;
[0022] Figure 9 This is a schematic diagram of another optional method for determining memory leak objects according to an embodiment of this application;
[0023] Figure 10 This is a schematic diagram of another optional memory leak object determination device according to an embodiment of this application;
[0024] Figure 11 This is a schematic diagram of an optional memory leak object determination device according to an embodiment of this application;
[0025] Figure 12 This is a schematic diagram of the structure of an optional electronic device according to an embodiment of this application. Detailed Implementation
[0026] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0027] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific 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 in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover 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.
[0028] To better understand the technical solutions provided in the embodiments of this application, the key terms involved in the embodiments of this application will be introduced first:
[0029] Smart Sheet: A database-like spreadsheet. It controls the data format of each column through fields, treating each row as a data record, providing a well-organized data structure. It can also transform data from the same source into different view types to meet the needs of various scenarios. It can also be called a multidimensional data table.
[0030] Memory leak: A memory leak is a bug in a computer program that means the program does not properly release memory that is no longer needed. These unreleased memory blocks will continue to occupy system resources.
[0031] Build Verification Test (BVT): BVT is an automated test performed on newly built software versions during the software development process. Its main purpose is to quickly verify whether the newly built software version is basically usable and can undergo further testing or release.
[0032] A dictionary (Map) is a data structure used to store a collection of key-value pairs. Values can be quickly looked up, inserted, and deleted using a unique key.
[0033] A set is a data structure used to store unique values of any type, where duplicate values are ignored.
[0034] Instantiation: refers to the process of creating a specific instance of a class, which is the beginning of an object's lifecycle.
[0035] Alternatively, as an alternative solution, such as Figure 1 As shown, the methods for identifying the aforementioned memory leak objects include:
[0036] S102, when the target application is in the first operation state, create the first data structure.
[0037] It should be noted that the above method for identifying memory leak objects can be applied, but is not limited to, application memory leak detection scenarios. For example, in web (World Wide Web) document applications, this method can be used to detect and prevent memory leaks during the switching of different smart table views (such as table view, calendar view, Gantt chart view, etc.), ensuring effective management of browser resources and avoiding slow page loading or crashes.
[0038] Optionally, in some embodiments, the target application described above may be, but is not limited to, the application that needs to be used to indicate the application for which memory leak detection needs to be performed. The application may be, but is not limited to, a web application or a local application. This embodiment does not limit this.
[0039] S104, when the operation state of the target application is switched to the second operation state, the object information of the data object corresponding to the target operation function applied in the second operation state is added to the first data structure and the second data structure.
[0040] Optionally, in some embodiments, the aforementioned data object may be, but is not limited to, used to indicate instances of a class, which is an abstract template or blueprint describing the common attributes and methods of a class of objects. Multiple objects with the same characteristics can be created through a class. In this embodiment, the aforementioned data object refers to a destructible object created when the target operation function is executed. Specifically, a destructible object is an object that implements a dispose method, which implements the logic for releasing external resources occupied by the object, such as clearing timers or canceling resource change detectors used to acquire and respond to specific events triggered by the user or other components. These objects should theoretically be destroyed after the function is completed or the operation state is restored. Further, the aforementioned target operation function may be, but is not limited to, used to indicate a specific function or operation performed in the application, such as "switching from table view to calendar view".
[0041] Optionally, in this embodiment, the first data structure is mainly used to store snapshot information of destructible data objects generated after the operation. Its structural feature is that it stores unique elements (i.e., object information of destructible data objects generated during the operation, such as a call stack), and duplicates are not allowed. Specifically, the first data structure can be, but is not limited to, a Set. A Set is a data structure used to store unique values of any type; duplicate values are ignored. That is, in this embodiment, a Set can be used to store newly created or not yet destroyed object information obtained when the operation is completed, forming a temporary "snapshot." In other words, in this embodiment, by using the first data structure (e.g., a Set), in the scenario of detecting memory leaks, duplicate records of the same object created multiple times can be efficiently removed, retaining only the record of one instance. This not only reduces the storage space requirement but also simplifies subsequent intersection calculations, improving detection efficiency and accuracy, thereby achieving the technical effect of accurately identifying memory leak objects and simplifying the memory leak analysis process.
[0042] Optionally, in this embodiment, the second data structure is more global and dynamic, used to continuously monitor the creation and destruction of all destructible data objects during application runtime. Specifically, the second data structure can be, but is not limited to, a dictionary (Map), where a Map is a data structure used to store a collection of key-value pairs. A unique key allows for quick lookup, insertion, and deletion of corresponding values. In other words, in this embodiment, a Map can be used to store key-value pairs. The key uniquely identifies the object, such as the data object itself, while the value can contain rich information (i.e., object information, such as the call stack). When an object is created, the Map records the object's key-value pairs; when the object is destroyed, the corresponding key-value pairs are removed from the Map, thus maintaining the Map's real-time performance. In other words, in this embodiment, by using a second data structure (e.g., a Map), a unique identifier (key) is assigned to each destructible data object in the form of key-value pairs, and related object information (values) is stored. This management method achieves the goal of accurately recording the creation and destruction history of each object, including important information such as the call stack during creation, thereby providing detailed data support for analyzing the root causes of memory leaks. On the other hand, the dynamic nature of Map allows it to reflect the state changes of destructible data objects in the application in real time. Whenever an object is created, its information is added to the Map; when an object is destroyed, the corresponding key-value pair is removed from the Map. This ensures that the data in the Map is always the most accurate "real-time snapshot," helping to promptly detect potential memory leaks. In summary, this embodiment achieves real-time detection and fine-grained management of the lifecycle of destructible data objects by employing a second data structure (e.g., Map), and also provides data support for the timely detection and accurate location of memory leaks.
[0043] It's worth noting that the Map is used to perceive, from a holistic perspective, which data objects were not destroyed during an operation. It adds marking logic to the instantiation and destruction method calls of destructible data objects. When a destructible data object is instantiated, a key-value pair uniquely identifying the object is added to the Map. The value in this key-value pair stores the call stack information at the time of the object's instantiation. When the destruction method of a destructible object is executed, the corresponding key-value pair is removed from the Map. Thus, changes to the Map indirectly reveal the destruction status of destructible objects.
[0044] Furthermore, the aforementioned operation states can be, but are not limited to, indicating the state of the target application when performing different functions or operations. For example, when the application displays a view, the operation state can be "first operation state," while switching to another view can be called "second operation state." Alternatively, when the application displays a view, the operation state can be "first operation state," and after performing an operation in the view, such as editing content in the view, deleting content in the view, or adding content to the view, the operation state can switch to "second operation state."
[0045] Optionally, in some embodiments, the aforementioned object information may, but is not limited to, be used to indicate the call stack corresponding to the data object at the time of instantiation. Specifically, the call stack corresponding to the data object at the time of instantiation may include, but is not limited to, the following:
[0046] 1) Functions that create data objects: Functions that call the top of the stack are usually functions that directly call memory allocation functions (such as new, malloc, etc.), and are the direct source of data object creation.
[0047] 2) Call hierarchy (call path): The call stack shows the hierarchy of function calls, i.e., how to reach the function that creates the data object step by step. This helps to detect the context in which the object was created. In other words, call hierarchy analysis starts from the main function or application entry point and proceeds to the function that creates the data object, providing a complete path for object creation.
[0048] 3) Line number and file name: Each level in the call stack usually records the file name and line number of the code. This helps to directly locate the specific code location, making it easier for developers to understand and modify.
[0049] Furthermore, in some embodiments, when switching the operation state of the target application to the second operation state, the object information of the data object corresponding to the target operation function applied in the second operation state can be directly added to the first data structure and the second data structure, but is not limited to this. Alternatively, the key-value pairs of the data object corresponding to the target operation function can be added to the second data structure first, wherein the key in the key-value pair is the data object corresponding to the target operation function, and the value in the key-value pair is the object information of the data object corresponding to the target operation function. Then, the object information in each key-value pair in the second data structure is copied from the second data structure to the first data structure. This embodiment does not limit this approach.
[0050] S106, when the operation state of the target application is restored to the first operation state, the data object corresponding to the target operation function is destroyed, and the object information of the data object corresponding to the target operation function is removed from the second data structure.
[0051] Optionally, in some embodiments, data objects that can be managed in memory within the target application are called destructible data objects, and there are two types: atomic destructible data objects and composite destructible data objects. Atomic destructible data objects represent the smallest granularity of memory management. An atomic destructible data object implements a destruction method, which, when called, destroys the atomic destructible data object. A composite destructible data object is a data object that holds multiple other destructible data objects; its destruction method sequentially calls the destruction methods of the other destructible objects held by the data object. For example, the structure of destructible data objects (i.e., the organizational structure of destructible objects used to implement the underlying support for memory leak detection) may, but is not limited to, refer to, as shown in [example missing]. Figure 2 The destruction tree structure shown allows a composite destructible data object to include multiple composite destructible objects or atomic destructible objects. These multi-level destructible data objects form a destruction tree through unidirectional references, and the entire tree is destroyed when the destruction method of the top-level composite destructible data object is called.
[0052] It should be further noted that, in the embodiments of this application, the destruction of data objects may be used, but is not limited to, to indicate the release logic of external resources occupied by the object, such as clearing timers, canceling resource change detectors used to acquire and respond to specific events triggered by users or other components, and setting references to other objects to null, etc., which are not limited in this embodiment.
[0053] It should be noted that when removing the object information of the data object corresponding to the target operation function from the second data structure, the data object corresponding to the target operation function in the second data structure will also be removed, that is, the key-value pairs of the data object corresponding to the target operation function will be removed.
[0054] S108, compare the object information stored in the first data structure with the object information stored in the second data structure.
[0055] It should be noted that in some embodiments, but not limited to, directly comparing the object information stored in the first data structure and the object information stored in the second data structure, or first creating a third data structure of the same type as the first data structure, and copying the object information in each key-value pair of the second data structure from the second data structure to the third data structure; then performing an intersection operation on the first data structure and the third data structure to obtain the comparison result. This embodiment does not impose any limitations on this approach.
[0056] S110, if the comparison result indicates that there is the same object information in the first data structure and the second data structure, the data object corresponding to the same object information is identified as a memory leak object.
[0057] Optionally, the aforementioned target leaked objects may, but are not limited to, be used to indicate data objects that should theoretically have been destroyed but were not destroyed after the application resumes from the second operating state to the first operating state.
[0058] Alternatively, as an optional example, it can be, but is not limited to, by means of, such as Figure 3 The following steps illustrate the method for identifying memory leak objects:
[0059] S302, Start detection, specifically, call the start detection method to initialize Set (used to represent the first data structure);
[0060] S304, Operation and Restore Phase, specifically includes:
[0061] S304-1, Perform an operation in the target application;
[0062] S304-2, Add the destructible data objects generated during the operation to the Map (used to represent the second data structure);
[0063] S304-3, Call the method to create a memory snapshot and store the values in the current Map as a Set;
[0064] S304-4, restore to the initial state;
[0065] S304-5, Call the destruction method of the destructible data object and remove the destroyed data object from the Map;
[0066] S306, End of detection phase, specifically, call the end detection method;
[0067] S308, the analysis phase, specifically includes;
[0068] S308-1, Store the current values in the Map as Set1;
[0069] S308-2 indicates that a memory leak has occurred if the intersection of Set and Set1 is not empty.
[0070] It should be noted that the above examples are optional examples provided to facilitate the explanation of the method for determining memory leak objects, and there are no limitations on the specific implementation of the method for determining memory leak objects.
[0071] In this embodiment, when the target application is in a first operating state, a first data structure is created. When the target application switches to a second operating state, the object information of the data object corresponding to the target operation function applied in the second operating state is added to the first and second data structures. When the target application returns to the first operating state, the data object corresponding to the target operation function is destroyed, and the object information of the data object corresponding to the target operation function is removed from the second data structure. The object information stored in the first and second data structures is compared. If the comparison result indicates that there is the same object information in the first and second data structures, the data object corresponding to the same object information is identified as a memory leak object. In other words, using this embodiment, when the application state changes, the information of newly instantiated data objects is added to the first and second data structures. This means that when the application enters a new operating state, all newly created objects will be recorded, which helps to accurately locate which objects are generated during specific function calls, providing detailed object information records for subsequent memory leak detection and enhancing the accuracy of detection. Next, when the application recovers from the second operating state to the first operating state, theoretically all data objects used by specific functions in the second operating state should be destroyed. Information about destroyed objects is removed from the second data structure to keep the data structure up-to-date, facilitating subsequent comparison and inspection, and thus more quickly identifying potential memory leaks. Then, by comparing the object information in the first and second data structures, those data objects that still exist after the application performs the recovery operation can be quickly identified, i.e., potential memory leak objects. This method eliminates the need to manually check the lifecycle of each object, greatly simplifying the memory leak detection process, improving detection efficiency, and avoiding human error, thus enhancing detection reliability. In summary, using the embodiments of this application, the creation and destruction of data objects can be automatically detected during application state transitions without manual intervention. This not only solves the inefficiency problem of relying on manual identification of memory leak objects in existing technologies but also improves the speed and accuracy of memory leak detection, significantly improving application performance, stability, and user experience. Through automation, memory leak problems can be detected and resolved promptly, avoiding long-term occupation of system resources, reducing software maintenance costs and complexity, improving development and testing efficiency, and ensuring application quality.
[0072] Furthermore, by adopting the embodiments of this application, on the one hand, by improving the efficiency of memory leak detection, the development team can identify the root cause of memory leaks more quickly, reducing the time spent on problem analysis and debugging; on the other hand, memory leaks can lead to the unnecessary occupation of system resources, especially in long-running applications. Efficient detection and timely resolution of memory leaks can avoid excessive resource consumption, extend program runtime, and improve system performance; furthermore, memory leaks can cause application response to slow down or crash, directly affecting user experience. By improving detection efficiency, identifying memory leaks early, and resolving these issues before official release, the stability and responsiveness of smart spreadsheets can be ensured for users, thereby improving overall user satisfaction; and finally, frequent memory leaks require continuous investment in development and testing resources. An efficient detection mechanism can reduce the occurrence of these problems, lowering the costs required for subsequent software maintenance and upgrades.
[0073] Furthermore, in specific scenarios of document applications (such as smart spreadsheets), the embodiments of this application are adopted. On the one hand, as a data-intensive application, smart spreadsheets involve the generation and destruction of a large number of data objects. By improving the efficiency of memory leak detection and ensuring that data objects are correctly destroyed when no longer needed, the application can effectively prevent crashes or performance bottlenecks during data processing, thereby enhancing the stability and reliability of the application. On the other hand, smart spreadsheets support multi-view switching and rich data editing functions, the implementation of which depends on data objects in memory. Effective memory management ensures immediate response to user operations. Whether switching views, editing data, or performing data analysis, the application can maintain high execution efficiency, improving the user experience. Moreover, smart spreadsheet application scenarios often involve functions such as simultaneous online editing by multiple users and real-time analysis of large amounts of data. Efficient memory leak detection and management mechanisms enable the application to remain stable when handling large-scale data and high-concurrency user operations.
[0074] Optionally, as an alternative approach, when switching the target application's operation state to the second operation state, adding the object information of the data object corresponding to the target operation function applied in the second operation state to the first and second data structures includes:
[0075] S1, add the key-value pairs of the data objects corresponding to the target operation function to the second data structure, where the key in the key-value pair is the data object corresponding to the target operation function, and the value in the key-value pair is the object information of the data object corresponding to the target operation function.
[0076] It should be noted that in data structures, a key-value pair is a tuple consisting of a key and a value. The key uniquely identifies the tuple, while the value is the actual data stored in the tuple. In this embodiment, the key is a data object, and the value contains information about the object, such as a reference to the call stack information at the time of its creation.
[0077] S2, copy the object information in each key-value pair in the second data structure to the first data structure respectively.
[0078] In this embodiment, key-value pairs of data objects corresponding to the target operation function are added to a second data structure. The key in each key-value pair is the data object corresponding to the target operation function, and the value is the object information of the data object. Then, the object information in each key-value pair in the second data structure is copied from the second data structure to the first data structure. In other words, this embodiment ensures that detailed information of all relevant data objects is accurately and promptly recorded in both data structures each time the application state changes. When restoring from the second operation state to the first operation state, by comparing the object information stored in the first and second data structures, data objects that should theoretically be destroyed but still exist—i.e., potential memory leak objects—can be quickly identified. This avoids frequent modification or access to the original objects during application execution, reducing the impact on application performance. Simultaneously, by copying object information (i.e., references to call stack information) instead of the objects themselves, memory usage is reduced, improving the efficiency of the entire memory leak detection process. More importantly, the use of key-value pairs ensures the uniqueness and accuracy of object information, maintaining high efficiency and reliability even in complex environments.
[0079] Optionally, as an optional approach, comparing the object information stored in the first data structure and the object information stored in the second data structure includes:
[0080] S1, create a third data structure of the same type as the first data structure, and copy the object information in each key-value pair of the second data structure from the second data structure to the third data structure.
[0081] Optionally, in this embodiment, the above-mentioned copying of the object information in each key-value pair in the second data structure from the second data structure to the third data structure can be used, but is not limited to, to indicate that the object information (i.e., the reference to the call stack information) in each key-value pair in the second data structure is copied from the second data structure to the third data structure.
[0082] It should be noted that in some embodiments, the third data structure is a data structure of the same type as the first data structure, namely, a Set, which is used to temporarily store the object information in the second data structure so as to perform intersection operations with the first data structure.
[0083] S2 performs an intersection operation on the first data structure and the third data structure to obtain the comparison result.
[0084] In this embodiment, a third data structure of the same type as the first data structure is created, and the object information in each key-value pair of the second data structure is copied from the second data structure to the third data structure. An intersection operation is performed on the first and third data structures to obtain the comparison result. In other words, by using this embodiment, on the one hand, the independence and accuracy of the comparison process are ensured by creating and using the third data structure, avoiding false positives or missed detections of memory leak objects caused by residual information in the data structure. On the other hand, copying rather than directly modifying the object information in the second data structure maintains the original integrity of the second data structure, facilitating future backtracking analysis and data management, while also improving data processing efficiency.
[0085] Optionally, as an alternative approach, after comparing the object information stored in the first data structure and the object information stored in the second data structure, the method further includes:
[0086] If the comparison results indicate that there is an intersection between the first data structure and the third data structure, it is determined that there is the same object information in the first data structure and the third data structure, and the same object information is the intersection.
[0087] It should be noted that the data stored in the first, second, and third data structures can be, but is not limited to, references to object information. In other words, in this embodiment, if the first and third data structures contain the same object information (i.e., a reference to the call stack information), then a memory leak can be confirmed.
[0088] For example, such as Figure 4 As shown in (a), it is assumed that the first data structure 402 includes object information 1 and object information 2, and that the third data structure 404 includes object information 1. Figure 4 As shown in (b), an intersection operation is performed on the first and third data structures. An intersection object, information 1, is found between them. Therefore, the data object corresponding to information 1 is determined to be data object 1. Then, it can be determined that a memory leak exists when the target application switches from the first operation state to the second operation state, and the object causing the memory leak is data object 1.
[0089] It should be noted that the above examples are optional examples provided to facilitate the explanation of the method for determining memory leak objects, and there are no limitations on the specific implementation of the method for determining memory leak objects.
[0090] In this embodiment, if the comparison result indicates an intersection between the first and third data structures, it is determined that the first and third data structures contain the same object information, and this same object information constitutes the intersection. In other words, this embodiment provides specific data basis for subsequent memory leak analysis and processing. By directly detecting the intersection between data structures, data objects that should have been destroyed but were not after the application resumed from the second operating state to the first operating state can be quickly located, thereby ensuring the accuracy and effectiveness of memory leak detection.
[0091] Optionally, as an alternative approach, before creating the first data structure, if the target application is in the first operating state, the following steps are also included:
[0092] If the first operation is detected in the target application and the first control displayed in the application debug window of the target application is selected, it is determined that the operation state of the target application is in the first operation state.
[0093] It should be noted that the first operation can be, but is not limited to, a specific operation or function used to instruct the triggering of memory leak detection in the target application. The application debug window mentioned above is an interface or tool used in a development or testing environment to monitor and control the runtime state of an application, such as the console in a front-end developer tool.
[0094] Furthermore, the aforementioned first control may, but is not limited to, be used to instruct controls or buttons in the application debug window to initiate memory leak detection.
[0095] For example, suppose the target application is a web application, and that web application is a document editing program that provides intelligent table editing functionality, which can be achieved, but is not limited to, through methods such as... Figure 5 The following example illustrates the steps above:
[0096] like Figure 5 As shown in (a), when the table view control 502 under the smart table function module is clicked, the table view is displayed.
[0097] Next, as Figure 5As shown in (b), when the Record Initial State Control 506 (used to represent the first control) displayed in the Application Debug Window 504 is selected, the operation state of the target application is determined to be the first operation state, and the Start Detection Method is called. This method is used to instantiate a Set (i.e., the first data structure) to store the key-value pairs of destructible objects generated during the operation.
[0098] It should be noted that the above examples are optional examples provided to facilitate the explanation of the method for determining memory leak objects, and there are no limitations on the specific implementation of the method for determining memory leak objects.
[0099] After executing the first test case to simulate the first operation on the target application using application testing tools, it is determined that the target application's operation state is in the first operation state.
[0100] It should be noted that tools or frameworks independent of the target application are used to simulate user actions, execute automated tests, etc., such as BVT (Build Verification Test). Furthermore, the first test case mentioned above can be, but is not limited to, instructing test scripts or sequences defined in the application testing tool to simulate specific operations or functions, for example, simulating a user switching from a "table view" to a "calendar view".
[0101] It should be noted that, in this embodiment, the following memory leak detection methods may be included, but are not limited to:
[0102] Method 1: Use memory leak detection test cases and BVT program for automatic detection. Specifically, the BVT program will automatically execute these memory test cases and some other test cases to check whether the smart table UI function is normal.
[0103] Method 2: Configure the calling method of memory leak detection externally, so that the BVT program can call these methods.
[0104] In this embodiment, the target application is determined to be in a first operation state when a first operation is detected and a first control displayed in the application debugging window of the target application is selected; or the target application is determined to be in a first operation state when a first test case simulating the first operation is executed on the target application using an application testing tool. In other words, by combining automated and semi-automated detection, memory leak detection can run automatically according to a predetermined test plan, or it can be performed under the fine control of developers, improving detection efficiency while ensuring the accuracy and coverage of the detection.
[0105] Optionally, as an alternative approach, after creating the first data structure when the target application is in the first operating state, the following steps are also included:
[0106] If the second operation is detected in the target application and the second control is selected in the application debugging window of the target application, it is determined that the operation state of the target application is in the second operation state.
[0107] It should be noted that the second operation mentioned above is a specific user or system operation performed in the target application, which causes the application's operation state to switch from "first operation state" to "second operation state". For example, in a smart table application for a document, this is the operation of switching from table view to calendar view.
[0108] Furthermore, the aforementioned second control is a control associated with a specific operation (i.e., the "second operation") in the application debug window. The user selects it to invoke the method to create a memory snapshot, which stores the values of all key-value pairs in the Map in a Set.
[0109] For example, suppose the target application is a web application, and that web application is a document editing program that provides intelligent table editing functionality, which can be achieved, but is not limited to, through methods such as... Figure 6 The following example illustrates the steps above:
[0110] like Figure 6 As shown in (a), when the calendar view control 602 under the smart table function module is clicked, the following is displayed: Figure 6 The calendar view shown in (b).
[0111] then, Figure 6 As shown in (b), when the completion function operation control 606 (used to represent the second control) displayed in the application debugging window 604 is selected, it is determined that the operation state of the target application is switched to the second operation state, and the method to create a memory snapshot is called.
[0112] It should be noted that the above examples are optional examples provided to facilitate the explanation of the method for determining memory leak objects, and there are no limitations on the specific implementation of the method for determining memory leak objects.
[0113] After executing a second test case to simulate the second operation on the target application using application testing tools, it was determined that the target application's operational state was in the second operational state.
[0114] It should be noted that, in some embodiments, the aforementioned second test case is an application test case designed to simulate a specific function or operation (i.e., the "second operation"). It contains a series of instructions to trigger the application to switch from one operation state to another, such as switching from a "table view" to a "calendar view".
[0115] In this embodiment, the target application is determined to be in a second operation state when a second operation is detected in the target application and a second control is selected in the application debugging window of the target application; or when a second test case simulating the second operation is executed on the target application using an application testing tool, the target application is determined to be in a second operation state. In other words, by combining automated and semi-automated detection, memory leak detection can run automatically according to a predetermined test plan, or it can be performed under the fine control of developers, improving detection efficiency while ensuring the accuracy and coverage of the detection.
[0116] Optionally, as an alternative approach, when switching the target application's operation state to the second operation state, adding the object information of the data object corresponding to the target operation function applied in the second operation state to the first and second data structures, further includes:
[0117] If a third operation is detected in the target application and the third control is selected in the application debugging window of the target application, the operation state of the target application is restored to the first operation state.
[0118] It should be noted that, in some embodiments, the third operation described above may be, but is not limited to, an operation to instruct the application to be restored to its initial operating state (first operating state), such as switching back from "Calendar View" to "Table View".
[0119] Furthermore, the aforementioned third control may, but is not limited to, a control or button used to indicate that the application has been restored to its initial state in the application debugging window. This control is used to determine that the application's operation state has been restored to the first operation state, so as to call the end detection method to check for memory leaks. This method first generates a set Set1 based on the values in all the key-value pairs in the restored Map, and then determines whether Set1 intersects with the Set generated when the operation is completed. If there is an intersection, it means that the objects added in the second operation state were not destroyed by their own destruction method during the process of restoring back to the first operation state, i.e., a memory leak has occurred.
[0120] For example, suppose the target application is a web application, and that web application is a document editing program that provides intelligent table editing functionality, which can be achieved, but is not limited to, through methods such as... Figure 7 The following example illustrates the steps above:
[0121] like Figure 7 As shown in (a), when the table view control 702 under the smart table function module is clicked, the calendar view switches back to the display shown in Figure (a). Figure 7 The table view shown in (b) is shown in the middle.
[0122] then, Figure 7 As shown in (b), when the restore initial state control 706 (used to represent the third control) displayed in the application debugging window 704 is selected, it is determined that the operation state of the target application is restored to the first operation state, and the application testing tool is triggered to call the end detection method to generate a set Set1 based on the values in all the key-value pairs in the restored Map. Then it is determined whether Set1 intersects with the Set generated when the operation is completed. If there is an intersection, it means that the destruction method of the object added by the application when it switches to the calendar view is not called during the process of restoring back to the table view, that is, a memory leak has occurred.
[0123] Then, if the intersection is determined from Set and Set1, such as Figure 7 As shown in (c), the application debugging window displays detailed information about the objects that have memory leaks, including the number of objects that have memory leaks and the call stack of the objects that have memory leaks.
[0124] It should be noted that the above examples are optional examples provided to facilitate the explanation of the method for determining memory leak objects, and there are no limitations on the specific implementation of the method for determining memory leak objects.
[0125] After executing a third test case to simulate a third operation on the target application using application testing tools, it was determined that the target application's operational state had been restored to the first operational state.
[0126] It should be noted that, in some embodiments, the aforementioned third test case may be used, but is not limited to, to instruct a test script or sequence defined in the application testing tool to simulate a third operation, namely, restoring the application state to its initial state.
[0127] It should be further noted that each step of the above-described method for identifying memory leak objects can be performed by application testing tools using test cases, including user operation statements and memory detection statements. In some embodiments, test cases corresponding to various scenarios in the target application can be pre-edited, and then the application testing tool can automatically execute these test cases at specific times to achieve automated memory detection for various scenarios in the target application. For example, taking the smart table scenario in a web text application as an example, one of the test cases can refer to... Figure 8 The structure shown.
[0128] In this embodiment, when a third operation is detected in the target application and a third control is selected in the application debugging window of the target application, the operation state of the target application is determined to be restored to the first operation state; or when a third test case simulating a third operation is executed on the target application using an application testing tool, the operation state of the target application is determined to be restored to the first operation state. In other words, by combining automated and semi-automated detection, memory leak detection can run automatically according to a predetermined test plan, or it can be performed under the fine control of developers, improving detection efficiency while ensuring the accuracy and coverage of the detection.
[0129] Optionally, as an alternative approach, after identifying the data object corresponding to the identical object information as the memory leak object when the comparison result indicates that the first data structure and the second data structure contain the same object information, the method further includes:
[0130] When the number of memory leak objects reaches the target threshold, a target alert message is sent to the target account used to manage the target application. The target alert message includes the number of memory leak objects, the identification information of the memory leak objects, and the call stack information of the memory leak objects.
[0131] It should be noted that the aforementioned identification information may be used, but is not limited to, to indicate the name of the object causing the memory leak. The aforementioned target account may be used, but is not limited to, to indicate the account of the user or system responsible for managing or detecting the target application. It may be the email address of a developer or tester, an instant messaging account, or a dedicated account used to receive system alarms, etc., and this embodiment does not limit this.
[0132] For example, the target prompt information mentioned above may include, but is not limited to, the following: Figure 9 As shown, the test report is sent to the target account, which includes the number of memory leak objects, the creation time, name, and call stack information of the memory leak objects.
[0133] It should be noted that the above examples are optional examples provided to facilitate the explanation of the method for determining memory leak objects, and do not limit the specific implementation of the method. In this embodiment, when the number of memory leak objects reaches a target threshold, a target alert message is sent to the target account used to manage the target application. The target alert message includes the number of memory leak objects, the identification information of the memory leak objects, and the call stack information of the memory leak objects. In other words, by combining detailed memory leak object identification and call stack information, the efficiency of development and testing teams in handling problems can be significantly improved using this embodiment. Developers do not need to analyze the code from scratch; they can directly locate the source of the memory leak based on the alert information, greatly reducing the time spent troubleshooting.
[0134] Alternatively, as an alternative solution, it can be, but is not limited to, through methods such as Figure 10 The following example illustrates the overall method for identifying memory leak objects:
[0135] S1002, by selecting through the application debugging window or simulating operation through an application testing tool (e.g., BVT), the target application is switched to the first operation state to ensure that the application is in a state ready for testing.
[0136] S1004, when the target application is in the first operation state, the first data structure is initialized using the application testing tool to prepare for storing object information generated before and after the operation.
[0137] S1006, by selecting through the debug window or simulating operation using the application test tool, the application switches to the second operation state. When a new function is applied, the application test tool adds the key-value pair information (object and its call stack information) of the data object related to this function to the second data structure, and synchronously updates the call stack information to the first data structure.
[0138] S1008, by selecting the application debugging window or simulating the operation of the application testing tool, confirm that the application operation state has returned to the first state, then execute the destruction operation of the data object, and use the application testing tool to delete these key-value pair information from the second data structure.
[0139] It should be noted that the test cases used in the above-mentioned application debugging window selection or application testing tool simulation operation can be reused in the application development process to test the functionality of the application.
[0140] S1010: Using a comparison algorithm, copy object information from the first and second data structures to a temporary third data structure, and perform an intersection operation to check whether any objects have not been destroyed after restoring their original state.
[0141] S1012, determine whether there is an intersection between the first and second data structures. If there is, determine that the objects in the intersection are memory leak objects, that is, these objects should have been destroyed after the second operation state ended but were not destroyed.
[0142] S1014 If the number of memory leak objects reaches a preset threshold, send an alert to the account responsible for application maintenance. The alert includes the number, identifier, and call stack details of the leaked objects to help developers locate and fix memory leak issues.
[0143] In summary, by adopting the embodiments of this application, at least the following problems can be solved:
[0144] 1) Solve the problem of detecting macroscopic memory changes:
[0145] Customized Scenario Detection: In step S1006, this application simulates a specific user operation in the smart table (i.e., the second operation state) to detect and record in real time the creation and call stack information of the data objects (i.e., objects in a specific scenario) corresponding to the target operation function, rather than simply detecting the memory changes of the entire application macroscopically. In other words, in any use case of the smart table (such as switching from a table view to a calendar view), all newly created objects and their lifecycles will be accurately recorded, thus enabling customized detection of object destruction in that scenario.
[0146] Targeted memory leak identification: In step S1010, by performing an intersection operation on the data structures in the first and second operation states, this application can identify objects that were not properly destroyed after the operation in a specific scenario, thereby accurately locating the memory leak problem. This scenario-customized object destruction detection and identification avoids the blindness of memory change detection and improves the targeting and efficiency of memory leak detection.
[0147] 2) Simplify the complexity of memory leak troubleshooting:
[0148] User-friendly interface: This application provides a memory leak detection tool integrated into the smart spreadsheet developer tools panel, enabling developers to perform the memory leak detection process through intuitive operations (such as clicking buttons) without needing to deeply understand the underlying memory management mechanisms. This greatly reduces the difficulty of using tools to troubleshoot memory leaks.
[0149] Automated Detection Process: In steps S1004 to S1014, this application implements a fully automated process from creating data structures, recording object information, executing object destruction, to detecting memory leaks. Developers no longer need to manually write complex detection code or templates, but can rely on automated tools to perform the operation, significantly saving time costs.
[0150] 3) Implement automated memory leak detection:
[0151] BVT Integration: Through integration with Build Verification Test (BVT), this application achieves automated detection of memory leaks in step S1014. The pipeline periodically executes memory leak detection test cases, and once a memory leak is detected, it automatically sends an alert to the account responsible for application maintenance, without requiring manual periodic checks or intervention.
[0152] Code reuse: Operation statements in BVT test cases can reuse code from existing ordinary BVT test cases. This means that when performing memory leak detection, no new test code needs to be written, simplifying the setup process for automated detection and reducing maintenance costs. Furthermore, using the embodiments of this application, by recording the creation information of newly generated objects when the application state switches, and checking whether the objects have been destroyed after the state is restored, memory leak problems can be effectively detected and located. Thus, it is possible to cover common use cases of smart tables, detect memory leak objects in each scenario, and adjust them to prevent memory leaks from occurring again, ensuring that all destructible objects are cleaned up. This not only reduces the occurrence of memory leak problems but also enables the development team to quickly respond to and fix potential memory management vulnerabilities.
[0153] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0154] According to another aspect of the embodiments of this application, an apparatus for determining a memory leak object is also provided for implementing the above-described method for determining a memory leak object. For example... Figure 11 As shown, the device includes:
[0155] Creation unit 1102 is used to create a first data structure when the target application is in the first operation state;
[0156] Adding unit 1104 is used to add the object information of the data object corresponding to the target operation function applied in the second operation state to the first data structure and the second data structure when the operation state of the target application is switched to the second operation state.
[0157] The removal unit 1106 is used to destroy the data object corresponding to the target operation function and remove the object information of the data object corresponding to the target operation function from the second data structure when the operation state of the target application is restored to the first operation state.
[0158] The comparison unit 1108 is used to compare the object information stored in the first data structure with the object information stored in the second data structure.
[0159] The determining unit 1110 is used to determine the data object corresponding to the same object information as a memory leak object when the comparison result indicates that the same object information exists in the first data structure and the second data structure.
[0160] Optionally, in this embodiment, the above-mentioned adding unit includes: an adding module, used to add key-value pairs of data objects corresponding to the target operation function to the second data structure, wherein the key in the key-value pair is the data object corresponding to the target operation function, and the value in the key-value pair is the object information of the data object corresponding to the target operation function; and a first copying module, used to copy the object information in each key-value pair in the second data structure from the second data structure to the first data structure.
[0161] Optionally, in this embodiment, the comparison unit includes: a second copying module, used to create a third data structure of the same type as the first data structure, and copy the object information in each key-value pair in the second data structure from the second data structure to the third data structure; and a comparison module, used to perform an intersection operation on the first data structure and the third data structure to obtain the comparison result.
[0162] Optionally, in this embodiment, the above-mentioned device further includes: a first determining unit, configured to determine that there is the same object information in the first data structure and the third data structure, and that the same object information is the intersection, when the comparison result indicates that there is an intersection between the first data structure and the third data structure.
[0163] Optionally, in this embodiment, the above-mentioned device further includes: a second determining unit, configured to determine that the operation state of the target application is in the first operation state when the target application is detected to have performed the first operation and the first control displayed in the application debugging window of the target application is selected; and a third determining unit, configured to determine that the operation state of the target application is in the first operation state when the target application is subjected to a first test case for simulating the first operation using an application testing tool.
[0164] Optionally, in this embodiment, the above-mentioned device further includes: a fourth determining unit, configured to determine that the operation state of the target application is in the second operation state when the target application is detected to have performed the second operation and the second control is selected in the application debugging window of the target application; and a fifth determining unit, configured to determine that the operation state of the target application is in the second operation state when a second test case for simulating the second operation is executed on the target application using an application testing tool.
[0165] Optionally, in this embodiment, the above-mentioned device further includes: a sixth determining unit, configured to determine that the operation state of the target application is restored to the first operation state when the target application is detected to have performed a third operation and the third control is selected in the application debugging window of the target application; and a seventh determining unit, configured to determine that the operation state of the target application is restored to the first operation state when a third test case for simulating a third operation is performed on the target application using an application testing tool.
[0166] Optionally, in this embodiment, the above-mentioned device further includes: a sending unit, configured to send target prompt information to a target account used to manage a target application when the number of memory leak objects reaches a target threshold, wherein the target prompt information includes the number of memory leak objects, the identification information of the memory leak objects, and the call stack information of the memory leak objects.
[0167] For specific implementation examples, please refer to the examples shown in the above method for determining memory leak objects; these examples will not be repeated here.
[0168] According to another aspect of the embodiments of this application, an electronic device for implementing the above-described method for determining memory leak objects is also provided. This electronic device may be a terminal device or a server. This embodiment uses a terminal device as an example for illustration. Figure 12 As shown, the electronic device includes a memory 1202 and a processor 1204. The memory 1202 stores a computer program, and the processor 1204 is configured to execute the steps of any of the above method embodiments through the computer program.
[0169] Optionally, in this embodiment, the aforementioned electronic device may be located in at least one of a plurality of network devices in a computer network.
[0170] Optionally, in this embodiment, the processor can be configured to perform the following steps via a computer program:
[0171] S1, when the target application is in the first operation state, create the first data structure;
[0172] S2, when the operation state of the target application is switched to the second operation state, the object information of the data object corresponding to the target operation function applied in the second operation state is added to the first data structure and the second data structure.
[0173] S3, when the operation state of the target application is restored to the first operation state, the data object corresponding to the target operation function is destroyed, and the object information of the data object corresponding to the target operation function is removed from the second data structure;
[0174] S4, compare the object information stored in the first data structure with the object information stored in the second data structure;
[0175] S5, if the comparison result indicates that there is the same object information in the first data structure and the second data structure, the data object corresponding to the same object information is identified as a memory leak object.
[0176] Alternatively, as those skilled in the art will understand, Figure 12 The structure shown is for illustrative purposes only. Electronic devices can also be smartphones (such as Android phones, iOS phones, etc.), tablets, PDAs, mobile internet devices (MIDs), PADs, and other terminal devices. Figure 12 This does not limit the structure of the aforementioned electronic devices. For example, the electronic device may also include components that are more... Figure 12 The more or fewer components shown (such as network interfaces, etc.), or having the same Figure 12 The different configurations shown.
[0177] The memory 1202 can be used to store software programs and modules, such as the program instructions / modules corresponding to the method and apparatus for determining memory leak objects in this embodiment. The processor 1204 executes various functional applications and data processing by running the software programs and modules stored in the memory 1202, thereby implementing the aforementioned method for determining memory leak objects. The memory 1202 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 1202 may further include memory remotely located relative to the processor 1204, and these remote memories can be connected to the terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof. As an example, such as... Figure 12 As shown, the memory 1202 may include, but is not limited to, the creation unit 1102, addition unit 1104, removal unit 1106, comparison unit 1108, and determination unit 1110 of the memory leak object determination device. Furthermore, it may include, but is not limited to, other module units of the memory leak object determination device, which will not be described further in this example.
[0178] Optionally, the transmission device 1206 described above is used to receive or send data via a network. Specific examples of the network described above may include wired networks and wireless networks. In one example, the transmission device 1206 includes a Network Interface Controller (NIC), which can be connected to other network devices and a router via a network cable to communicate with the Internet or a local area network. In another example, the transmission device 1206 is a radio frequency (RF) module, used for wireless communication with the Internet.
[0179] In addition, the aforementioned electronic device also includes a connection bus 1208 for connecting the various module components in the aforementioned electronic device.
[0180] In other embodiments, the aforementioned terminal device or server can be a node in a distributed system, wherein the distributed system can be a blockchain system, which is a distributed system formed by connecting multiple nodes through network communication. The nodes can form a point-to-point network, and any form of computing device, such as a server, terminal, or other electronic device, can become a node in the blockchain system by joining this point-to-point network.
[0181] According to one aspect of this application, a computer program product is provided, comprising a computer program / instructions containing program code for performing the methods described above. In such embodiments, the computer program can be downloaded and installed from a network via a communication component, and / or installed from a removable medium. When the computer program is executed by a central processing unit, it performs various functions provided in the embodiments of this application.
[0182] According to one aspect of this application, another computer program product is also provided, including a non-volatile computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the methods in various embodiments of this application.
[0183] According to one aspect of this application, a computer-readable storage medium is provided, wherein a processor of a computer device reads computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the above-described method.
[0184] Optionally, in this embodiment, the computer-readable storage medium may be configured to store a computer program for performing the following steps:
[0185] S1, when the target application is in the first operation state, create the first data structure;
[0186] S2, when the operation state of the target application is switched to the second operation state, the object information of the data object corresponding to the target operation function applied in the second operation state is added to the first data structure and the second data structure.
[0187] S3, when the operation state of the target application is restored to the first operation state, the data object corresponding to the target operation function is destroyed, and the object information of the data object corresponding to the target operation function is removed from the second data structure;
[0188] S4, compare the object information stored in the first data structure with the object information stored in the second data structure;
[0189] S5. If the comparison result indicates that there is identical object information in the first data structure and the second data structure, the data object corresponding to the identical object information is identified as a memory leak object. It should be noted that the data collection and processing described in this application should strictly comply with the requirements of relevant national laws and regulations, obtain the informed consent or separate consent of the personal information subject, and conduct subsequent data use and processing within the scope of laws and regulations and the authorization of the personal information subject.
[0190] Optionally, in the embodiments of this application, the terms "module" or "unit" refer to a computer program or part of a computer program with a predetermined function, which works together with other related parts to achieve a predetermined goal, and can be implemented wholly or partially using software, hardware (such as processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memory) can be used to implement one or more modules or units. Furthermore, each module or unit can be part of an overall module or unit that includes the functionality of that module or unit.
[0191] Optionally, in this embodiment, those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by a program instructing the hardware related to the terminal device. The program can be stored in a computer-readable storage medium, which may include: flash drive, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
[0192] If the integrated units in the above embodiments are implemented as software functional units and sold or used as independent products, they can be stored in the aforementioned 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 one or more computer devices (which may be personal computers, servers, or network devices, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application.
[0193] In the above embodiments of this application, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0194] In the several embodiments provided in this application, it should be understood that the disclosed client can be implemented in other ways. The device embodiments described above are merely illustrative; for example, 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 through some interfaces, indirect coupling or communication connection between units or modules, and may be electrical or other forms.
[0195] 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.
[0196] 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.
[0197] The above description is only a preferred embodiment of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this application, and these improvements and modifications should also be considered within the scope of protection of this application.
Claims
1. A method for identifying memory leak objects, characterized in that, include: When the target application is in the first operating state, create the first data structure; When the operation state of the target application is switched to the second operation state, the object information of the data object corresponding to the target operation function applied in the second operation state is added to the first data structure and the second data structure. When the operation state of the target application is restored to the first operation state, the data object corresponding to the target operation function is destroyed, and the object information of the data object corresponding to the target operation function is removed from the second data structure; The object information stored in the first data structure is compared with the object information stored in the second data structure; If the comparison results indicate that there is the same object information in the first data structure and the second data structure, the data object corresponding to the same object information is identified as a memory leak object.
2. The method according to claim 1, characterized in that, When switching the operation state of the target application to the second operation state, adding the object information of the data object corresponding to the target operation function applied in the second operation state to the first data structure and the second data structure includes: Add the key-value pair of the data object corresponding to the target operation function to the second data structure, wherein the key in the key-value pair is the data object corresponding to the target operation function, and the value in the key-value pair is the object information of the data object corresponding to the target operation function; The object information in each key-value pair in the second data structure is copied from the second data structure to the first data structure.
3. The method according to claim 2, characterized in that, The comparison of object information stored in the first data structure and object information stored in the second data structure includes: Create a third data structure of the same type as the first data structure, and copy the object information of each key-value pair in the second data structure from the second data structure to the third data structure; The intersection operation is performed on the first data structure and the third data structure to obtain the comparison result.
4. The method according to claim 3, characterized in that, After comparing the object information stored in the first data structure and the object information stored in the second data structure, the method further includes: If the comparison result indicates that there is an intersection between the first data structure and the third data structure, it is determined that there is the same object information in the first data structure and the third data structure, and the same object information is the intersection.
5. The method according to claim 1, characterized in that, Before creating the first data structure when the target application is in a first operating state, the method further includes: If the target application is detected to have performed a first operation and the first control displayed in the application debugging window of the target application is selected, it is determined that the operation state of the target application is in the first operation state; or When the target application is tested using an application testing tool with a first test case simulating the first operation, it is determined that the target application is in the first operation state.
6. The method according to claim 1, characterized in that, After creating the first data structure when the target application is in a first operating state, the method further includes: If the target application is detected to have performed a second operation and the second control is selected in the application debugging window of the target application, it is determined that the operation state of the target application is in the second operation state; or When the target application is subjected to a second test case that simulates the second operation using an application testing tool, it is determined that the operation state of the target application is in the second operation state.
7. The method according to claim 1, characterized in that, When the operation state of the target application is switched to the second operation state, adding the object information of the data object corresponding to the target operation function applied in the second operation state to the first data structure and the second data structure further includes: If a third operation is detected in the target application and a third control is selected in the application debugging window of the target application, it is determined that the operation state of the target application is restored to the first operation state; or If a third test case simulating the third operation is executed on the target application using an application testing tool, it is determined that the operation state of the target application has been restored to the first operation state.
8. The method according to any one of claims 1 to 7, characterized in that, If the comparison result indicates that there is the same object information in the first data structure and the second data structure, after identifying the data object corresponding to the same object information as a memory leak object, the method further includes: When the number of memory leak objects reaches a target threshold, a target notification message is sent to the target account used to manage the target application. The target notification message includes the number of memory leak objects, the identification information of the memory leak objects, and the call stack information of the memory leak objects.
9. A device for determining memory leak objects, characterized in that, include: A creation unit is used to create a first data structure when the target application is in the first operating state. The adding unit is used to add the object information of the data object corresponding to the target operation function applied in the second operation state to the first data structure and the second data structure when the operation state of the target application is switched to the second operation state. The removal unit is used to destroy the data object corresponding to the target operation function and remove the object information of the data object corresponding to the target operation function from the second data structure when the operation state of the target application is restored to the first operation state. The comparison unit is used to compare the object information stored in the first data structure with the object information stored in the second data structure. The determining unit is configured to determine the data object corresponding to the same object information as a memory leak object when the comparison result indicates that the first data structure and the second data structure contain the same object information.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored program, wherein the program is executed by a processor to perform the method described in any one of claims 1 to 8.
11. A computer program product, comprising a computer program / instructions, characterized in that, When the computer program / instructions are executed by the processor, they implement the steps of the method according to any one of claims 1 to 8.
12. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to execute the method described in any one of claims 1 to 8 through the computer program.
