Memory leak location determination method and apparatus, electronic device

By acquiring and comparing script reference information from client-side script files at different time points, the problem of accurately locating memory leaks in existing technologies has been solved, enabling the determination of memory leak locations across multiple platforms.

CN115756921BActive Publication Date: 2026-11-03BEIJING XINTANG SICHUANG EDUCATIONAL TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211438900.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-11-17
Publication Date
2026-11-03
Estimated Expiration
2042-11-17

AI Technical Summary

Technical Problem

Current technology cannot accurately locate memory leaks, leading to system crashes.

Method used

The script reference information of the client script file is obtained by means of the first sampling period and the second sampling period, and the results are compared to determine the location of the memory leak. The sampling period is earlier and later than the start and stop times of the application, respectively.

Benefits of technology

It enables accurate location of memory leaks on various operating systems, preventing system crashes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115756921B_ABST
    Figure CN115756921B_ABST
Patent Text Reader

Abstract

The present disclosure provides a memory leak location determination method and device, and an electronic device. The method comprises: obtaining first script reference information from a client script file in a first sampling period, obtaining second script reference information from the client script file in a second sampling period, determining a memory leak location of an application based on a comparison result of the first script reference information and the second script reference information if the comparison result meets an application memory leak condition, the first sampling period being earlier than a starting time of the application of the client, the second sampling period being later than a closing time of the application, and the first script reference information being different from the second script information. The method of the present disclosure can not only accurately locate the memory leak location, but also can be used in various operating systems without platform limitation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to a method and apparatus for determining the location of memory leaks, and an electronic device. Background Technology

[0002] Memory leaks, also known as "storage leaks," refer to the phenomenon where dynamically allocated memory is not released after use, causing it to occupy the memory location until the program terminates. As a result, the longer an application runs, the more storage space it consumes, eventually exhausting all available storage and causing the entire system to crash.

[0003] In related technologies, an application programming interface (API) can be called to view memory, and the memory usage of the application over a period of time can be determined by observing the memory view. However, it is not possible to accurately locate the location of a memory leak. Summary of the Invention

[0004] According to one aspect of this disclosure, a method for determining the location of a memory leak is provided, comprising:

[0005] First script reference information is obtained from the client script file during the first sampling period, which is earlier than the startup time of the client application.

[0006] Second script reference information is obtained from the client script file during the second sampling period, which is later than the closing time of the application. The first script reference information and the second script information are different.

[0007] If the comparison result between the first script reference information and the second script reference information satisfies the application memory leak condition, the memory leak location of the application is determined based on the comparison result.

[0008] According to another aspect of this disclosure, a memory leak location determination apparatus is provided, comprising:

[0009] The acquisition module is used to acquire first script reference information from the client script file during a first sampling period and acquire second script reference information from the client script file during a second sampling period. The first sampling period is earlier than the start time of the client application, and the second sampling period is later than the close time of the application. The first script reference information and the second script information are different.

[0010] The location module is used to determine the location of the application's memory leak based on the comparison result between the first script reference information and the second script reference information, which shows that the comparison result meets the application's memory leak conditions.

[0011] According to another aspect of this disclosure, an electronic device is provided, comprising:

[0012] Processor; and,

[0013] Memory for stored programs;

[0014] The program includes instructions that, when executed by the processor, cause the processor to perform the method according to an exemplary embodiment of the present disclosure.

[0015] According to another aspect of this disclosure, a non-transitory computer-readable storage medium is provided, the non-transitory computer-readable storage medium storing computer instructions for causing the computer to perform the method according to exemplary embodiments of this disclosure.

[0016] One or more technical solutions provided in this disclosure obtain first script reference information from the client script file during a first sampling period and second script reference information from the client script file during a second sampling period. Since the first sampling period is earlier than the application's startup time and the second sampling period is later than the application's shutdown time, when the comparison result of the first script reference information and the second script reference information satisfies the client's application memory leak condition, the comparison result can reflect the change of the second script reference information relative to the first script reference information. Based on this change, the memory leak location of the application can be determined, thereby accurately locating the memory leak location. Moreover, the exemplary embodiments of this disclosure can be used on various operating systems and are not platform-limited. Attached Figure Description

[0017] Further details, features, and advantages of this disclosure are disclosed in the following description of exemplary embodiments in conjunction with the accompanying drawings, in which:

[0018] Figure 1 A schematic diagram of an example system in which the various methods described herein may be implemented according to exemplary embodiments of the present disclosure;

[0019] Figure 2 A schematic flowchart of a method for determining the location of a memory leak according to an exemplary embodiment of the present disclosure is shown;

[0020] Figure 3 A flowchart illustrating an exemplary embodiment of this disclosure for determining the location of a memory leak in an application based on comparison results is shown.

[0021] Figure 4 A schematic diagram illustrating the process of obtaining first script reference information in an exemplary embodiment of this disclosure is shown.

[0022] Figure 5 A schematic diagram illustrating the process of obtaining second script reference information in an exemplary embodiment of this disclosure is shown.

[0023] Figure 6 A schematic block diagram of the functional modules of a memory leak location determination apparatus according to an exemplary embodiment of the present disclosure is shown;

[0024] Figure 7 A schematic block diagram of a chip according to an exemplary embodiment of the present disclosure is shown;

[0025] Figure 8 A structural block diagram of an exemplary electronic device that can be used to implement embodiments of the present disclosure is shown. Detailed Implementation

[0026] Embodiments of this disclosure will now be described in more detail with reference to the accompanying drawings. While some embodiments of this disclosure are shown in the drawings, it should be understood that this disclosure can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of this disclosure. It should be understood that the accompanying drawings and embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of protection of this disclosure.

[0027] It should be understood that the steps described in the method embodiments of this disclosure may be performed in different orders and / or in parallel. Furthermore, the method embodiments may include additional steps and / or omit the steps shown. The scope of this disclosure is not limited in this respect.

[0028] The term "comprising" and its variations as used herein are open-ended, meaning "including but not limited to". The term "based on" means "at least partially based on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Definitions of other terms will be given in the description below. It should be noted that the concepts of "first", "second", etc., used in this disclosure are only used to distinguish different devices, modules, or units, and are not intended to limit the order of functions performed by these devices, modules, or units or their interdependencies.

[0029] It should be noted that the terms "a" and "a plurality of" used in this disclosure are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise expressly indicated in the context, they should be understood as "one or more".

[0030] The names of messages or information exchanged between multiple devices in the embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of such messages or information.

[0031] Before introducing the embodiments of this disclosure, the relevant terms involved in the embodiments of this disclosure are first defined as follows:

[0032] A memory leak occurs when space dynamically allocated using dynamic memory allocation functions is not released after use, resulting in that space occupying the memory unit until the program terminates.

[0033] Lua is a lightweight scripting language written in standard C and open-source. It is designed to be embedded in applications, providing them with flexible extension and customization capabilities.

[0034] The table is a data structure in Lua that uses associative arrays to help users create different data types, such as arrays and dictionaries.

[0035] The `rawget` function retrieves the value of `table[index]` without triggering any methods. `table` must be a table, and `index` can be any value. For example, in Lua, when querying values ​​in a table, calling `rawget(tb, i)` performs a "raw" access to `table tb`, which is a simple access without considering the metatable.

[0036] The `getinfo` function is used to obtain basic information about function calls. For example, you can call `debug.getinfo(level, arg)` to get a table containing function information. The contents of the table are determined by the parameter `arg`, and the information about which function is included is determined by `level`.

[0037] Unity natively supports the development of 3D classrooms, games, and other Unity products based on the C# programming language. However, C# is a static language and cannot be dynamically updated. Therefore, Unity products need to be developed using dynamic languages ​​such as Lua and TS to achieve "hot updates" and improve the speed of application (App) updates and iterations.

[0038] Running memory, also known as RAM, refers to the space where programs are stored or temporarily stored while running.

[0039] In related technologies, an application programming interface (API) can be called to view memory, and the memory usage of the application over a period of time can be determined by observing the memory view. However, it is not possible to accurately locate the location of a memory leak.

[0040] Currently, LuaProfiler can be used to troubleshoot Lua memory issues, but LuaProfiler is only available on the Windows platform, which is quite limiting. It can show the increase / decrease of memory over a period of time, but it does not provide details and cannot pinpoint the specific location of the memory leak.

[0041] This exemplary embodiment provides a method for determining the location of a memory leak, which can not only accurately locate the location of the memory leak, but also be used on various operating systems without platform limitations.

[0042] Figure 1 A schematic diagram of an example system in which various methods described herein can be implemented according to exemplary embodiments of this disclosure is shown. Figure 1 As shown, the system architecture 100 of this exemplary embodiment includes a client system 102 and a server system 103 connected to each other via a network 101. It should be understood that... Figure 1 The system architecture 100 shown applies to all examples of exemplary embodiments of this disclosure. The system architecture shown is for the purpose of understanding the exemplary embodiments of this disclosure and should not be construed as limiting the application scenarios, display methods, and various communication relationships of exemplary embodiments of this disclosure.

[0043] In one alternative approach, such as Figure 1 As shown, the first resource server 104 bypasses network 101 and connects to server system 103. The second resource server 105 connects to server system 103 via network 101. Alternatively, the first resource server 104 can connect to server system 103 via network 101. The second resource server 105 can connect to server system 103 by bypassing network 101. Furthermore, although... Figure 1 The illustration shows one client system 102, one server system 103, one first resource server 104, one second resource server 105, and one network 101. However, this does not constitute a limitation on the number of client systems 102, server systems 103, first resource servers 104, second resource servers 105, and networks 101. Based on this, the search network architecture 100 of the exemplary embodiments of this disclosure may include multiple client systems 102, multiple search server systems 103, multiple first resource servers 104, multiple second resource servers 105, and multiple networks 101. Figure 1As shown in the exemplary embodiments of this disclosure, the first resource server 104 and the second resource server 105 can provide services and resources to the server system 103 through different network communication methods. The resources may include, but are not limited to, multimedia resources such as video, text, and audio, and the services may include, but are not limited to, services such as computer vision recognition, speech recognition, and natural language processing. The first resource server 104 and the second resource server 105 can be configured as cloud servers such as dedicated cloud, public cloud, hybrid cloud, or private cloud, and can be deployed with the training and deployment capabilities of neural network models capable of executing the services described above.

[0044] like Figure 1 As shown, network 101 in the exemplary embodiments of this disclosure may include one or more networks 101, and any suitable network 101 may be considered. By way of example and not limitation, one or more portions of network 101 may include an ad hoc network, intranet, extranet, virtual private network (VPN), local area network (LAN), wireless local area network (WLAN), wide area network (WAN), wireless wide area network (WWAN), metropolitan area network (MAN), a portion of the Internet, a portion of the public switched telephone network (PSTN), a cellular telephone network, or a combination of two or more of these.

[0045] like Figure 1 As shown, the client system 102, server system 103, first resource server 104, and second resource server 105 of the exemplary embodiments of this disclosure can be connected to the communication network 101 or connected to each other via the network communication link 106. Any suitable network communication link 106 is considered in the exemplary embodiments of this disclosure.

[0046] For example, one or more network communication links 106 may include one or more wired lines (e.g., Digital Subscriber Line (DSL) or Data OverCable Service Interface Specifications (DOCSIS), wireless (e.g., Wireless Fidelity (WiFi) or Worldwide Interoperability for Microwave Access (WiMAX)), or optical (e.g., Synchronous Optical Network (SONET) or Synchronous Digital Hierarchy (SDH)) links.

[0047] For example, such as Figure 1 As shown, one or more network communication links 106 each include an ad hoc network, intranet, extranet, VPN, LAN, WLAN, WAN, WWAN, MAN, a portion of the Internet, a portion of the PSTN, a cellular network, a satellite communication network, another network communication link 106, or a combination of two or more such network communication links 106. Network communication links 106 are not necessarily identical throughout the entire search network architecture 100. One or more first network communication links may differ from one or more second network communication links in one or more aspects.

[0048] In one alternative approach, such as Figure 1 As shown, the client system 102 of the exemplary embodiments of this disclosure can access the server system 103 directly or via the network 101 using a web browser / multimedia application 1021 or a local application associated with the server system 103 (e.g., a mobile multimedia application, a messaging application, another suitable application, or any combination thereof).

[0049] For example, such as Figure 1 As shown, the client system 102 of the exemplary embodiments of this disclosure may be an electronic device including hardware, software or embedded logic components or a combination of two or more such components, and is capable of performing appropriate functions implemented or supported by the client system 102.

[0050] For example, such as Figure 1As shown, the client system 102 of this exemplary embodiment may include a computer system, such as a desktop computer, notebook or laptop computer, netbook, tablet computer, e-book reader, Global Positioning System (GPS) device, camera, personal digital assistant (PDA), handheld electronic device, cellular phone, smartphone, other suitable electronic device, or any suitable combination thereof. It should be understood that any suitable client system 102 is contemplated in this embodiment of the invention. The client system 102 enables network users at client system 102 to access network 101. The client system 102 enables its users to communicate with other users at other client systems 102.

[0051] In one alternative approach, such as Figure 1 As shown, the server system 103 of this exemplary embodiment can be a network-addressable computing system capable of hosting online searches. The server system 103 can generate, store, receive, and send search information. The server system 103 can be accessed directly by other components of the search network architecture 100 or via network 101. For example, as... Figure 1 As shown, the server system 103 of the exemplary embodiments of this disclosure may include one or more servers 1031. Each server 1031 may be a single server or a distributed server spanning multiple computers or multiple data centers. Servers 1031 may be of various types, such as, but not limited to, web servers, news servers, mail servers, messaging servers, advertising servers, file servers, application servers, exchange servers, database servers, proxy servers, another server adapted to perform the functions or processes described herein, or any combination thereof.

[0052] In one specific implementation, each server 1031 may include hardware, software, or embedded logic components, or a combination of two or more such components, for performing appropriate functions implemented or supported by the server 1031.

[0053] For example, such as Figure 1 As shown, the server system 103 of this exemplary embodiment may include one or more data storage devices 1032. The data storage devices 1032 can be used to store various types of information. In one specific implementation, the information stored in the data storage devices 1032 may be organized according to a specific data structure. In one specific implementation, each data storage device 1032 may be a relational database, a columnar database, a correlation database, or other suitable database. Although specific types of databases are described or illustrated in the embodiments of the present invention, any suitable type of database is contemplated in the embodiments of the present invention.

[0054] A specific implementation may provide an interface that enables client system 102, server system 103, or first resource server 104 and second resource server 105 to manage, retrieve, modify, add, or delete information stored in data storage 1032. For example, such as... Figure 1 As shown, the server system 103 of this exemplary embodiment can store multiple reading objects or multiple video objects in one or more data storage devices 1032. The server system 103 can provide users with the ability to take actions on various types of items or objects supported by the server system 103.

[0055] For example, such as Figure 1 As shown, the server system 103 of this exemplary embodiment is capable of linking various entities. By way of example, and not limitation, the server system 103 can enable users to interact with each other and receive content from a first resource server 104, a second resource server 105, or other entities, or allow users to interact with these entities through an application programming interface (API) or other communication channels. In one alternative, such as Figure 1 As shown, the first resource server 104 and the second resource server 105 in the exemplary embodiments of this disclosure may include one or more types of servers, one or more data storage devices, one or more interfaces (including but not limited to APIs), one or more network services, one or more content sources, one or more networks, or any other suitable component to which the server can communicate. The first resource server 104 and the second resource server 10525 may be operated by an entity different from the entity operating the server system 103.

[0056] In another alternative approach, such as Figure 1 As shown, the server system 103 and the first resource server 104 and second resource server 105 of the exemplary embodiments of this disclosure can cooperate with each other to provide search services to users of the server system 103 or the first resource server 104 and second resource server 105. In this sense, the server system 103 can provide a platform or backbone that other systems such as the first resource server 104 and the second resource server 105 can use to provide search services and functions to users via the Internet.

[0057] The method of this exemplary embodiment can be executed by an electronic device or by a chip applied to the electronic device. The electronic device can be a user device, or a cloud processing device such as an electronic device.

[0058] For example, the electronic device of the exemplary embodiments of this disclosure may be a user device with display function, and the terminal may be a mobile phone, tablet computer, wearable device, in-vehicle device, laptop computer, ultra-mobile personal computer (UMPC), netbook, PDA, and wearable device based on augmented reality (AR) and / or virtual reality (VR) technology, etc.

[0059] For example, when a user device is a wearable device, it can also be a general term for devices that utilize wearable technology to intelligently design and develop everyday wearables, such as glasses, gloves, watches, clothing, and shoes. Wearable devices are portable devices worn directly on the body or integrated into a user's clothing or accessories. Wearable devices are not merely hardware devices; they achieve powerful functions through software support, data interaction, and cloud interaction. Broadly defined, wearable smart devices include those with comprehensive functions, large sizes, and the ability to perform complete or partial functions without relying on a smartphone, such as smartwatches or smart glasses, as well as those focused on a specific application function that require interaction with other devices such as smartphones, such as various smart bracelets and smart jewelry for vital sign monitoring.

[0060] Figure 2 A schematic flowchart of a method for determining the location of a memory leak according to an exemplary embodiment of this disclosure is shown. Figure 2 As shown, the memory leak location determination method of the exemplary embodiments of this disclosure includes:

[0061] Step 201: Obtain the first script reference information from the client script file during the first sampling period. The first sampling period is earlier than the startup time of the client application. It should be understood that the client can be various common educational clients, video playback clients, social platform clients, etc., and is not limited to these.

[0062] The aforementioned client-side script files can contain script data with the same data structure, facilitating traversal of the file. These client-side script files can be in languages ​​such as Lua and JavaScript. For example, in Lua script files, the `table` is an associative array, allowing the creation of different data types. Similarly, in TypeScript, the data structure of a TypeScript script file can be Boolean, numeric, string, array, tuple, enumeration, arbitrary, null and undefined, void, never, or object. These client-side script files can reside in the client's runtime memory and are various files referenced by the running client, including script code files and other static code files. Therefore, during the first sampling period, the client's runtime memory can be accessed to obtain a snapshot of the first script reference information.

[0063] Step 202: Obtain the second script reference information from the client script file during the second sampling period, which is later than the application's shutdown time. The first script reference information and the second script reference information are different. Here, the first script reference information and the second script reference information are obtained at different times, but the acquisition methods can be the same.

[0064] Step 203: If the comparison result of the first script reference information and the second script reference information meets the application memory leak conditions, determine the location of the application memory leak based on the comparison result.

[0065] In practical applications, the reference information of the first script and the reference information of the second script can be compared. This comparison can be based on both the amount of data and the content of the data. Therefore, the comparison results can include the data amount comparison results and the reference information comparison results.

[0066] Considering that in actual business scenarios, the script reference information theoretically remains unchanged after the application is closed compared to the script reference information before the application started, the application memory leak condition in this exemplary embodiment can be that the data increment of the second script reference information relative to the first script reference information is greater than a preset threshold.

[0067] Figure 3 This illustration shows a flowchart of an exemplary embodiment of the present disclosure, illustrating how to determine the location of a memory leak in an application based on comparison results. For example... Figure 3 As shown, an exemplary embodiment of this disclosure determines the location of a memory leak in an application based on comparison results, including:

[0068] Step 301: Based on the script reference change information of the second script reference information relative to the first script reference information, determine the incremental information of the script reference object;

[0069] Step 302: Based on the mapping relationship between script reference objects and script reference locations, determine the script reference location corresponding to the incremental information of the script reference object;

[0070] Step 303: When the script reference location belongs to the application's script reference location, the script reference location is determined as the memory leak location. It can be seen that when the data increment of the second script reference information relative to the first script reference information is small, it can be ignored; however, when the data increment is large, the memory leak location of the application can be determined based on the comparison result. Therefore, the method of this exemplary embodiment can increase the system's memory leak tolerance by setting a preset threshold.

[0071] Taking an educational client as an example, before playing a course video, the educational client can collect the first script reference information in the running memory of the educational client. After playing the course video, it can collect the second script reference information in the running memory of the educational client, and then compare the first script reference information and the second script reference information.

[0072] If the data increment of the comparison result is less than or equal to the preset threshold, it indicates that the threads related to the course video have been completely or nearly completely released. Therefore, it can be determined that the course video does not have a memory leak issue. If the data increment of the comparison result is greater than the preset threshold, it indicates that the threads related to the course video may not have been released or not completely released, and the amount has reached a level that cannot be ignored. Based on this, the increment of the script reference object can be determined based on the comparison result. Then, based on the mapping relationship between the script reference object and the reference position, the script reference position corresponding to the increment of the script reference object can be found.

[0073] If the script reference location belongs to the application's script reference location, it indicates a memory leak in the application corresponding to the course video. Therefore, the script reference location can be identified as the memory leak location. If the script reference location does not belong to the application's script reference location, it indicates that the application corresponding to the course video does not have a memory leak problem. However, memory leaks may occur elsewhere, such as when the user actively opens another course video on the client after the application is closed, resulting in increased script reference information. Therefore, based on whether the application corresponding to the script reference location is the application corresponding to another course video on the client that the user actively opened, if not, it indicates an initial memory leak within the educational client, and the application causing the memory leak can be identified based on the location corresponding to the script reference location.

[0074] In one possible implementation, in order to achieve the purpose of automatically initiating sampling for the first sampling period, the method of the exemplary embodiment of this disclosure may further include: in response to sampling request information, determining a script storage path, the script storage path being used to indicate the storage path of the first script reference information and the second script reference file.

[0075] For example, when an application that may leak memory is easily identified, or when memory leak detection is required for a particular application, the sampling request information may include the application's identification information on the client, and the client script file may include the application's root script reference file. In this case, the client's runtime memory can be accessed directly based on the application's identification information, the application's root script reference file can be read from the runtime memory, and then the root script reference file can be traversed to obtain the first script reference information. Simultaneously, at the start of the second sampling period, the runtime memory can be accessed again, and the root script reference file can be traversed to obtain the second script reference information.

[0076] For example, if the application that may cause a memory leak is not easily identified, the sampling request information can be configured to include the client's identification information, and the client script file can include the client's reference chain root script file. That is, when the application in the client that may cause a memory leak cannot be identified, the client's identification information can be passed in. When the client's identification information is received, the client's runtime memory can be accessed based on that identification information, the client's reference chain root script file can be obtained as the client script file, and all root script files in the reference chain root script file can be traversed to extract the script reference information from all root script files as the first script reference information.

[0077] At the same time, at the start of the second sampling period, the running memory can be accessed again to obtain the root script file of the client's reference chain as the client script file. Then, all root script files in the root script file of the reference chain are traversed, and the script reference information in all root script files is extracted as the second script reference information.

[0078] In one possible implementation, in order to achieve the purpose of automatically initiating the sampling of the second sampling period, the method of the exemplary embodiment of this disclosure may further include: in response to the application's closing operation, determining the start time of the second sampling period based on the time of the closing operation.

[0079] The start time of the second sampling period can be the time of the shutdown operation, or it can be determined by setting a time delay parameter, which delays the time of the shutdown operation based on the time delay parameter.

[0080] Considering the need for internal parameter leakage location detection for the current application, if the second script reference information contains script reference information from another application, then even if the current application does not have a memory leak problem, the data increment of the first script reference information and the second script reference information will exceed a preset threshold, making it impossible to accurately determine whether the current application's memory has leaked. Therefore, the time delay parameter in the exemplary embodiment of this disclosure is controlled within a relatively small range to ensure that the user device has sufficient time to release the memory that can be released by the current application while reducing interference caused by the startup of another application.

[0081] For example, the time delay parameter can be controlled to be set from 1s to 10s, such as 1s, 7s, 4s, or 10s. Under the influence of this time delay parameter, the start time of the second sampling period can be delayed based on the start time of the shutdown operation, according to the set time delay parameter. Simultaneously, with this time delay parameter set within 1s to 10s, it is highly unlikely that the user will open another application on the client side. This avoids the situation where the collected second script reference information contains script information referenced by another application, thus ensuring the accuracy of memory leak location detection for the current application.

[0082] In one possible implementation, the data attributes contained in the second script reference information may or may not be exactly the same as those contained in the first script reference information. Regardless, the data attributes contained in both the first and second script reference information can accurately locate the position of the first script reference object.

[0083] Figure 4 A schematic diagram illustrating the process of obtaining first script reference information in an exemplary embodiment of this disclosure is shown. Figure 4 As shown, an exemplary embodiment of this disclosure, obtaining first script reference information from a client script file during the first sampling period, may include:

[0084] Step 401: Obtain the first script data from the client script file during the first sampling period. This first script data can be the smallest data unit contained in the client script file, and the data structure of this smallest data unit is related to the code language of the client script file. Taking a Lua script file as an example, the smallest data unit can essentially be regarded as the root table in Lua, and the root table object here can be regarded as a reference object.

[0085] Step 402: Record the first script reference information contained in the first script data. Since all objects in Lua can be represented by tables, we can first obtain the root table, or specify the root table, and then traverse all the properties of the table starting from the root table to find the required first script reference information.

[0086] Step 403: If the first script data contains first sub-script data, update the first script data based on the first sub-script data. Here, the first script can include the first sub-script. Taking a Lua script file as an example, when the first script data contains first sub-script data, the root table also contains child tables, i.e., child attributes. Therefore, the first script data can be updated using the first sub-script data. Then, execute step 402 until the first script data no longer contains first sub-script data, ending the attribute traversal of the current root table and starting a new root table attribute traversal. Simultaneously, while traversing the root table attributes, the first script reference information contained in the recorded first script data can be filled into the container until the root table traversal is completed, saving all the first script reference information in the container.

[0087] The first script reference information in the exemplary embodiments of this disclosure may include the identifier and / or location information of the first referenced object. Both the identifier and the location information of the first referenced object can accurately locate the position of the referenced object. Therefore, the first script reference information may include the identifier of the first referenced object, the location information of the first application object, or both.

[0088] When the first script reference information includes both the identifier and the location information of the first referenced object, it is possible not only to locate the position of the referenced object using either the identifier or the location information, but also to extract the actual location information of the first referenced object through the identifier. Theoretically, the actual location information of the first referenced object should be consistent with the location information of the first referenced object. However, to avoid data loss, the actual location information of the first referenced object can be compared with the location information of the first referenced object. If they are inconsistent, the actual location information of the first referenced object is used as the location information of the first referenced object to determine the position of the referenced object.

[0089] In practical applications, the first script data can be accessed using a fetch function to obtain the identifier of the first referenced object. This identifier can be either the class name contained within the first script data or the hexadecimal address of the first script data. The fetch function can be the `rawget` function.

[0090] For example, the `rawget` function can be used to read the root table property in Lua and determine whether class names such as `class`, `__cname`, and `_className` exist. If a class name exists, it can be identified by the name of the root table object, the hexadecimal address of the root table, or the first referenced object, making it easy to identify the referenced object. If no class name exists, the hexadecimal address of the root table is used as the name of the root table object, which is the identifier of the first referenced object.

[0091] For example, if the root table contains a class named UnityEngine UI.Text, and its hexadecimal address is 0x600012cf4bc8, then the name of the root table object can be either UnityEngine UI.Text or 0x600012cf4bc8.

[0092] For example, an introspective function can be used to access the first script data to obtain the location information of the first referenced object. Here, the introspective function can be the `debug.getinfo` function. The location information of the first referenced object can include the filename and line number, as well as the method name, and even the line number of the first referenced object in the reference chain, making the location information of the first referenced object more comprehensive. Simultaneously, the number of references to the first referenced object at the current moment can be recorded to avoid situations where the location information is the same in the first sampling period and the second sampling period, but the references differ, leading to missed or incorrect judgments of what should be memory leaks.

[0093] For example, the location information of the first referenced object may include: registry.627[line:75@file:api_manager], with a reference count of 2. Here, registry.627 records the reference chain line number as 627, line:75 records the line number of the root table of the first referenced object as 75, and file:api_manager is the file path.

[0094] Figure 5 A schematic diagram illustrating the process of obtaining second script reference information in an exemplary embodiment of this disclosure is shown. Figure 5 As shown, an exemplary embodiment of this disclosure obtains second script reference information from a client script file during the second sampling period, including:

[0095] Step 501: Starting from the second sampling period, obtain the second script data from the client script file. The first and second script data are different. The main difference here is the sampling period; the content is determined based on the actual situation.

[0096] Step 502: Record the second script reference information contained in the second script data. The second script data is different from the second script data; the main difference here is the sampling time period, and the content is mainly determined according to the actual situation.

[0097] Step 503: If the second script data contains second sub-script data, update the second script data based on the second sub-script data. The first sub-script data and the second sub-script data are different. Here, the second script may include the second sub-script. For examples related to obtaining the second script reference information, please refer to the relevant description of the first script reference information, which will not be detailed here.

[0098] For example, the second script reference information includes the identifier and / or location information of the second referenced object. Recording the first script reference information contained in the second script data includes: accessing the second script data using a fetch function to obtain the identifier of the second referenced object; and accessing the second script data using an introspection function to obtain the location information of the second referenced object. Here, the fetch function can be the `rawget` function, and the introspection function can be the `debug.getinfo` function.

[0099] One or more technical solutions provided in this disclosure obtain first script reference information from the client script file during a first sampling period and second script reference information from the client script file during a second sampling period. Since the first sampling period is earlier than the application's startup time and the second sampling period is later than the application's shutdown time, when the comparison result of the first script reference information and the second script reference information satisfies the client's application memory leak condition, the comparison result can reflect the change of the second script reference information relative to the first script reference information. Based on this change, the memory leak location of the application can be determined, thereby accurately locating the memory leak location. Moreover, the exemplary embodiments of this disclosure can be used on various operating systems and are not platform-limited.

[0100] The foregoing primarily describes the solutions provided by the embodiments of this disclosure from the perspective of the server. It is understood that, in order to implement the above functions, the server includes the corresponding hardware structures and / or software modules for executing each function. Those skilled in the art should readily recognize that, based on the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein, this disclosure can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed in hardware or by computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this disclosure.

[0101] This disclosure embodiment can divide the server into functional units according to the above method example. For example, it can divide each function into a separate functional module, or it can integrate two or more functions into one processing module. The integrated module can be implemented in hardware or as a software functional module. It should be noted that the module division in this disclosure embodiment is illustrative and only represents one logical functional division. In actual implementation, there may be other division methods.

[0102] In the case of dividing each functional module according to its corresponding function, an exemplary embodiment of this disclosure provides a memory leak location determination device, which can be an electronic device or a chip applied to an electronic device. Figure 6 A schematic block diagram of the functional modules of a memory leak location determination apparatus according to an exemplary embodiment of the present disclosure is shown. Figure 6 As shown, the memory leak location determination device 600 includes:

[0103] The acquisition module 601 is used to acquire first script reference information from the client script file during a first sampling period and acquire second script reference information from the client script file during a second sampling period. The first sampling period is earlier than the start time of the client application, and the second sampling period is later than the close time of the application. The first script reference information and the second script information are different.

[0104] The positioning module 602 is used to determine the location of the memory leak in the application based on the comparison result between the first script reference information and the second script reference information, which shows that the comparison result satisfies the application memory leak condition.

[0105] In one possible implementation, the apparatus further includes a determining module 603, configured to determine a script storage path in response to sampling request information, the script storage path indicating the storage path of the first script reference information and the second script reference file; wherein the sampling request information includes the client's identification information, and the client script file includes the root script file of the client's reference chain; or, the sampling request information includes the identification information of the application in the client, and the client script file includes the root script reference file of the application.

[0106] In one possible implementation, the acquisition module 601 is used to acquire first script data from the client script file during the first sampling period, record the first script reference information contained in the first script data, and update the first script data based on the first sub-script data if the first script data contains first sub-script data.

[0107] In one possible implementation, the acquisition module 601 is used to access the first script data using a value retrieval function to obtain the identifier of the first referenced object; and / or, to access the first script data using an introspection function to obtain the location information of the first referenced object.

[0108] In one possible implementation, the acquisition module 601 is used to acquire second script data from the client script file starting from the second sampling period, record the second script reference information contained in the second script data, and update the second script data based on the second sub-script data if the second script data contains second sub-script data. The first script data and the second script data are different, the second script data and the second sub-script data are different, the first sub-script data and the second sub-script data are different, and the second script contains the second sub-script.

[0109] In one possible implementation, the acquisition module 601 is used to access the second script data using a value retrieval function to obtain the identifier of the second referenced object; and / or, to access the second script data using an introspection function to obtain the location information of the second referenced object.

[0110] In one possible implementation, the apparatus further includes a determining module 603, configured to determine the start time of the second sampling period based on the time of the closing operation in response to a closing operation of the application.

[0111] In one possible implementation, the application memory leak condition is that the data increment of the second script reference information relative to the first script reference information is greater than a preset threshold. The positioning module 602 is used to determine the incremental information of the script reference object based on the script reference change information of the second script reference information relative to the first script reference information, determine the script reference position corresponding to the incremental information of the script reference object based on the mapping relationship between the script reference object and the script reference position, and determine the script reference position as the memory leak position of the application when the script reference position belongs to the script reference position of the application.

[0112] Figure 7 A schematic block diagram of a chip according to an exemplary embodiment of the present disclosure is shown. Figure 7 As shown, the chip 700 includes one or more processors 701 and a communication interface 702. The communication interface 702 can support the electronic device to perform the data transmission and reception steps in the above-described memory leak location determination method, and the processor 701 can support the electronic device to perform the data processing steps in the above-described memory leak location determination method.

[0113] Optional, such as Figure 7 As shown, the chip 700 also includes a memory 703, which may include read-only memory and random access memory, and provides operation instructions and data to the processor. A portion of the memory may also include non-volatile random access memory (NVRAM).

[0114] In some implementations, such as Figure 7 As shown, processor 701 executes corresponding operations by calling operation instructions stored in memory (which may be stored in the operating system). Processor 701 controls the processing operations of any terminal device; processor can also be called a central processing unit (CPU). Memory 703 may include read-only memory and random access memory, and provides instructions and data to processor 701. A portion of memory 703 may also include NVRAM. For example, in applications, memory, communication interfaces, and other components are coupled together via a bus system, which may include, in addition to a data bus, a power bus, a control bus, and a status signal bus, etc. However, for clarity, in... Figure 7 The general designated all buses as Bus System 704.

[0115] The methods disclosed in the embodiments of this disclosure can be applied to a processor or implemented by a processor. The processor may be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above methods can be completed by integrated logic circuits in the processor's hardware or by instructions in software form. The processor can be a general-purpose processor, a digital signal processor (DSP), an ASIC, a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this disclosure. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this disclosure can be directly embodied in the execution of a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor. The software modules can reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. This storage medium is located in memory; the processor reads information from the memory and, in conjunction with its hardware, completes the steps of the above methods. An exemplary embodiment of the present disclosure also provides an electronic device, including: at least one processor; and a memory communicatively connected to the at least one processor. The memory stores a computer program executable by the at least one processor, the computer program being executed by the at least one processor to cause the electronic device to perform a method according to an embodiment of the present disclosure.

[0116] Exemplary embodiments of this disclosure also provide a non-transitory computer-readable storage medium storing a computer program, wherein the computer program, when executed by a computer's processor, is used to cause the computer to perform a method according to embodiments of this disclosure.

[0117] Exemplary embodiments of this disclosure also provide a computer program product, including a computer program, wherein, when executed by a processor of a computer, the computer program is used to cause the computer to perform a method according to an embodiment of this disclosure.

[0118] refer to Figure 8The present invention describes a structural block diagram of an electronic device 800 that can serve as a server or client of the present disclosure, which is an example of a hardware device that can be applied to various aspects of the present disclosure. The electronic device is intended to represent various forms of digital electronic computer devices, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.

[0119] like Figure 8 As shown, the electronic device 800 includes a computing unit 801, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 802 or a computer program loaded from a storage unit 808 into a random access memory (RAM) 803. The RAM 803 may also store various programs and data required for the operation of the device 800. The computing unit 801, ROM 802, and RAM 803 are interconnected via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.

[0120] Multiple components in electronic device 800 are connected to I / O interface 805, including: input unit 806, output unit 807, storage unit 808, and communication unit 809. Input unit 806 can be any type of device capable of inputting information to electronic device 800. Input unit 806 can receive input digital or character information and generate key signal inputs related to user settings and / or function control of electronic device. Output unit 807 can be any type of device capable of presenting information and may include, but is not limited to, a display, speaker, video / audio output terminal, vibrator, and / or printer. Storage unit 808 may include, but is not limited to, disks and optical discs. Communication unit 809 allows electronic device 800 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks, and may include, but is not limited to, modems, network cards, infrared communication devices, wireless communication transceivers, and / or chipsets, such as Bluetooth™ devices, WiFi devices, WiMax devices, cellular communication devices, and / or the like.

[0121] The computing unit 801 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 801 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 801 performs the various methods and processes described above. For example, in some embodiments, the methods of exemplary embodiments of this disclosure can be implemented as computer software programs tangibly contained in a machine-readable medium, such as storage unit 808. In some embodiments, part or all of the computer program can be loaded and / or installed on the electronic device 800 via ROM 802 and / or communication unit 809. In some embodiments, the computing unit 801 can be configured to perform the methods of exemplary embodiments of this disclosure by any other suitable means (e.g., by means of firmware).

[0122] The program code used to implement the methods of this disclosure may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0123] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0124] As used in this disclosure, the terms "machine-readable medium" and "computer-readable medium" refer to any computer program product, device, and / or apparatus (e.g., disk, optical disk, memory, programmable logic device (PLD)) for providing machine instructions and / or data to a programmable processor, including machine-readable media that receive machine instructions as machine-readable signals. The term "machine-readable signal" refers to any signal for providing machine instructions and / or data to a programmable processor.

[0125] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).

[0126] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as a data server), or computing systems that include middleware components (e.g., an application server), or computing systems that include frontend components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with embodiments of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., a communication network). Examples of communication networks include local area networks (LANs), wide area networks (WANs), and the Internet.

[0127] Computer systems can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. Client-server relationships are created by computer programs running on the respective computers and having a client-server relationship with each other.

[0128] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented, in whole or in part, as a computer program product. The computer program product includes one or more computer programs or instructions. When the computer program or instructions are loaded and executed on a computer, the processes or functions described in the embodiments of this disclosure are performed, in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, a terminal, a user equipment, or other programmable device. The computer program or instructions can be stored in a computer-readable storage medium or transferred from one computer-readable storage medium to another. For example, the computer program or instructions can be transferred from one website, computer, server, or data center to another website, computer, server, or data center via wired or wireless means. The computer-readable storage medium can be any available medium accessible to a computer or a data storage device such as a server or data center integrating one or more available media. The available medium can be a magnetic medium, such as a floppy disk, hard disk, or magnetic tape; it can also be an optical medium, such as a digital video disc (DVD); or it can be a semiconductor medium, such as a solid-state drive (SSD).

[0129] Although this disclosure has been described in conjunction with specific features and embodiments, it will be apparent that various modifications and combinations can be made therein without departing from the spirit and scope of this disclosure. Accordingly, this specification and drawings are merely exemplary illustrations of the disclosure as defined by the appended claims and are to be considered as covering any and all modifications, variations, combinations, or equivalents within the scope of this disclosure. It is obvious that those skilled in the art can make various alterations and modifications to this disclosure without departing from its spirit and scope. Thus, this disclosure is also intended to include any such modifications and modifications that fall within the scope of the claims of this disclosure and their equivalents.

Claims

1. A method for determining the location of a memory leak, characterized in that, include: First script reference information is obtained from the client script file during the first sampling period, which is earlier than the startup time of the client application. In response to the application's closing operation, the start time of the closing operation is determined by delaying the time delay parameter, wherein the time delay parameter is set to 1s to 10s; Second script reference information is obtained from the client script file during the second sampling period, which is later than the closing time of the application. The first script reference information and the second script reference information are different. If the comparison result between the first script reference information and the second script reference information satisfies the application memory leak condition, the memory leak location of the application is determined based on the comparison result; The method further includes: In response to a sampling request, a script storage path is determined, wherein the script storage path indicates the storage path of the first script reference information and the second script reference information; wherein the sampling request information includes the client's identification information, and the client script file includes the root script file of the client's reference chain; or, the sampling request information includes the identification information of the application in the client, and the client script file includes the root script reference file of the application; During the first sampling period, the client's running memory is accessed based on the application's identification information or the client's identification information. The root script reference file of the application or the reference chain root script file of the client is read from the running memory. The root script reference file is traversed to obtain the first script reference information. During the second sampling period, the client's running memory is accessed based on the application's identification information or the client's identification information. The root script reference file of the application or the reference chain root script file of the client is read from the running memory. The root script reference file is traversed to obtain the second script reference information.

2. The method according to claim 1, characterized in that, The client script file contains script data with the same data structure. The step of obtaining the first script reference information from the client script file during the first sampling period includes: First script data is obtained from the client script file during the first sampling period; Record the first script reference information contained in the first script data; If the first script data contains first sub-script data, the first script data is updated based on the first sub-script data, and the first script contains the first sub-script.

3. The method according to claim 2, characterized in that, The first script reference information includes the identifier and / or location information of the first referenced object. The first script reference information contained in the recorded first script data includes: Access the first script data using a value retrieval function to obtain the identifier of the first referenced object; and / or, The location information of the first referenced object is obtained by accessing the first script data using the introspection function.

4. The method according to claim 2, characterized in that, The step of obtaining the second script reference information from the client script file during the second sampling period includes: The second script data is obtained from the client script file starting from the second sampling period, and the first script data and the second script data are different. Record the second script reference information contained in the second script data, where the first script data and the second script data are different; If the second script data contains second sub-script data, update the second script data based on the second sub-script data. The first sub-script data and the second sub-script data are different, and the second script contains the second sub-script.

5. The method according to claim 4, characterized in that, The second script reference information includes the identifier and / or location information of the second referenced object, and the first script reference information contained in the record of the second script data includes: Access the second script data using a value retrieval function to obtain the identifier of the second referenced object; and / or, The location information of the second referenced object is obtained by accessing the second script data using the introspection function.

6. The method according to any one of claims 1 to 5, characterized in that, The application memory leak condition is that the data increment of the second script reference information relative to the first script reference information is greater than a preset threshold. Determining the location of the application memory leak based on the comparison result includes: Based on the script reference change information of the second script reference information relative to the first script reference information, the incremental information of the script reference object is determined; Based on the mapping relationship between script reference objects and script reference locations, the script reference location corresponding to the incremental information of the script reference object is determined; When the script reference location belongs to the script reference location of the application, the script reference location is determined to be the memory leak location of the application.

7. A device for determining the location of a memory leak, characterized in that, include: The acquisition module is used to obtain first script reference information from the client script file during the first sampling period, and in response to the application's shutdown operation, delay the moment of the shutdown operation using the time delay parameter to determine the start time of the second sampling period. Second script reference information is obtained from the client script file during the second sampling period. The first sampling period is earlier than the start time of the client application, and the second sampling period is later than the close time of the application. The first script reference information and the second script reference information are different. The time delay parameter is set to 1s to 10s. The location module is used to determine the location of the memory leak in the application based on the comparison result between the first script reference information and the second script reference information, which shows that the comparison result meets the conditions for the application memory leak. The device further includes a determining module, configured to determine a script storage path in response to sampling request information, wherein the script storage path indicates the storage path of the first script reference information and the second script reference information; wherein the sampling request information includes the client's identification information and the client script file includes the root script file of the client's reference chain; or, the sampling request information includes the identification information of the application in the client and the client script file includes the root script reference file of the application. During the first sampling period, the client's running memory is accessed based on the application's identification information. The root script reference file of the application or the reference chain root script file of the client is read from the running memory. The root script reference file is traversed to obtain the first script reference information. During the second sampling period, the client's running memory is accessed based on the application's identification information. The root script reference file of the application or the root script file of the client's reference chain is read from the running memory. The root script reference file is traversed to obtain the second script reference information.

8. An electronic device, characterized in that, include: processor; as well as, Memory for stored programs; The program includes instructions that, when executed by the processor, cause the processor to perform the method according to any one of claims 1 to 6.

9. A non-transitory computer-readable storage medium, characterized in that, The non-transitory computer-readable storage medium stores computer instructions for causing the computer to perform the method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Method and device for positioning memory leakage

    CN101819549A

  • Memory leak positioning method, server, client and system

    CN102148844A