CN111949528A - Memory leak detection method and device, electronic equipment and storage medium - Google Patents

Memory leak detection method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN111949528A
CN111949528A CN202010779108.0A CN202010779108A CN111949528A CN 111949528 A CN111949528 A CN 111949528A CN 202010779108 A CN202010779108 A CN 202010779108A CN 111949528 A CN111949528 A CN 111949528A
Authority
CN
China
Prior art keywords
monitored
scene
class
current
page
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010779108.0A
Other languages
Chinese (zh)
Inventor
刘德平
刘青
赵哲
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing ByteDance Network Technology Co Ltd
Original Assignee
Beijing ByteDance Network Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing ByteDance Network Technology Co Ltd filed Critical Beijing ByteDance Network Technology Co Ltd
Priority to CN202010779108.0A priority Critical patent/CN111949528A/en
Publication of CN111949528A publication Critical patent/CN111949528A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/362Software debugging
    • G06F11/366Software debugging using diagnostics
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3003Monitoring arrangements specially adapted to the computing system or computing system component being monitored
    • G06F11/302Monitoring arrangements specially adapted to the computing system or computing system component being monitored where the computing system component is a software system
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3051Monitoring arrangements for monitoring the configuration of the computing system or of the computing system component, e.g. monitoring the presence of processing resources, peripherals, I/O links, software programs

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Quality & Reliability (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Hardware Design (AREA)
  • Mathematical Physics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The embodiment of the disclosure provides a method and a device for detecting memory leakage, electronic equipment and a storage medium. The method comprises the following steps: acquiring the current instantiation times and the current instantiation time threshold of a class to be monitored in a scene to be monitored; and if the current instantiation time is greater than the current instantiation time threshold, determining that the target application program to which the scene to be monitored belongs has memory leakage. By adopting the technical scheme, the memory leakage condition caused by abnormal instantiation of the class to be monitored can be detected in the running process of the scene to be monitored, manual starting and operation of a monitoring tool are not needed, the memory leakage detection is not needed to be carried out until the scene to be monitored is destroyed, and the timeliness of the memory leakage detection and the comprehensiveness of the memory leakage detection result can be improved.

Description

Memory leak detection method and device, electronic equipment and storage medium
Technical Field
The present disclosure relates to detection technologies, and in particular, to a method and an apparatus for detecting memory leakage, an electronic device, and a storage medium.
Background
In the development process of the application program, the application program needs to be detected so as to determine whether the memory leak exists in the application program. In the prior art, the detection of memory leakage is generally carried out by using open source libraries such as leak, allocation or MLeaksFinder of Instrument.
However, in some special scenarios, for example, in a scenario where a class is instantiated multiple times, the detection method in the prior art may determine that a class is instantiated multiple times as a normal scenario, which may cause a memory leak detection situation.
Disclosure of Invention
The embodiment of the disclosure provides a method and a device for detecting memory leakage, an electronic device and a storage medium, so as to reduce the probability of occurrence of memory leakage detection and improve the comprehensiveness of a memory leakage detection result.
In a first aspect, an embodiment of the present disclosure provides a method for detecting a memory leak, including:
acquiring the current instantiation times and the current instantiation time threshold of a class to be monitored in a scene to be monitored;
and if the current instantiation time is greater than the current instantiation time threshold, determining that the target application program to which the scene to be monitored belongs has memory leakage.
In a second aspect, an embodiment of the present disclosure further provides a device for detecting memory leak, including:
the system comprises a frequency acquisition module, a frequency acquisition module and a frequency comparison module, wherein the frequency acquisition module is used for acquiring the current instantiation frequency and the current instantiation frequency threshold of a class to be monitored in a scene to be monitored;
and the leakage detection module is used for determining that the target application program to which the scene to be monitored belongs has memory leakage when the current instantiation time is greater than the current instantiation time threshold.
In a third aspect, an embodiment of the present disclosure further provides an electronic device, including:
one or more processors;
a memory for storing one or more programs,
when the one or more programs are executed by the one or more processors, the one or more processors implement the method for detecting the memory leak according to the embodiment of the disclosure.
In a fourth aspect, the disclosed embodiment also provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the method for detecting a memory leak according to the disclosed embodiment.
The method, the device, the electronic device and the storage medium for detecting the memory leakage provided by the embodiment of the disclosure acquire the current instantiation time and the current instantiation time threshold of the class to be monitored in the scene to be monitored, and determine that the memory leakage exists in the target application program to which the scene to be monitored belongs when the current instantiation time is greater than the current instantiation time threshold. By adopting the technical scheme, the memory leakage condition caused by abnormal instantiation of the class to be monitored can be detected in the running process of the scene to be monitored, manual starting and operation of a monitoring tool are not needed, the memory leakage detection is not needed to be carried out until the scene to be monitored is destroyed, and the timeliness of the memory leakage detection and the comprehensiveness of the memory leakage detection result can be improved.
Drawings
The above and other features, advantages and aspects of various embodiments of the present disclosure will become more apparent by referring to the following detailed description when taken in conjunction with the accompanying drawings. Throughout the drawings, the same or similar reference numbers refer to the same or similar elements. It should be understood that the drawings are schematic and that elements and features are not necessarily drawn to scale.
Fig. 1 is a schematic flow chart illustrating a method for detecting memory leakage according to an embodiment of the present disclosure;
fig. 2 is a schematic flow chart illustrating another method for detecting a memory leak according to an embodiment of the present disclosure;
fig. 3 is a block diagram of a structure of a device for detecting memory leakage according to an embodiment of the present disclosure;
fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the present disclosure.
Detailed Description
Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While certain embodiments of the present disclosure are shown in the drawings, it is to be understood that the present disclosure may be embodied in various forms and should not be construed as limited to the embodiments set forth herein, but rather are provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the disclosure are for illustration purposes only and are not intended to limit the scope of the disclosure.
It should be understood that the various steps recited in the method embodiments of the present disclosure may be performed in a different order, and/or performed in parallel. Moreover, method embodiments may include additional steps and/or omit performing the illustrated steps. The scope of the present disclosure is not limited in this respect.
The term "include" and variations thereof as used herein are open-ended, i.e., "including but not limited to". The term "based on" is "based, at least in part, 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". Relevant definitions for other terms will be given in the following description.
It should be noted that the terms "first", "second", and the like in the present disclosure are only used for distinguishing different devices, modules or units, and are not used for limiting the order or interdependence relationship of the functions performed by the devices, modules or units. [ ordinal numbers ]
It is noted that references to "a", "an", and "the" modifications in this disclosure are intended to be illustrative rather than limiting, and that those skilled in the art will recognize that "one or more" may be used unless the context clearly dictates otherwise.
The names of messages or information exchanged between devices in the embodiments of the present disclosure are for illustrative purposes only, and are not intended to limit the scope of the messages or information.
Fig. 1 is a schematic flow chart of a method for detecting memory leakage according to an embodiment of the present disclosure. The method can be executed by a memory leak detection device, wherein the device can be implemented by software and/or hardware, and can be configured in an electronic device, typically a smart phone, a tablet computer or a computer. Optionally, the method for detecting memory leak provided in the embodiment of the present disclosure is suitable for detecting memory leak in an application program running process, and is particularly suitable for detecting whether a memory leak occurs in the application program in a development stage of the application program, where the memory leak is caused by an abnormal instantiation of a class in the application program. As shown in fig. 1, a method for detecting a memory leak provided in an embodiment of the present disclosure may include:
s110, acquiring the current instantiation times and the current instantiation time threshold of the class to be monitored in the scene to be monitored.
In this embodiment, the current instantiation time may be the time when the scene to be monitored runs to the current time and the class to be monitored has been instantiated in the scene to be monitored. The current instantiation time threshold may be the maximum number of times that the class to be monitored is allowed to be instantiated, and may be the maximum number of times that the class to be monitored is allowed to be instantiated in the scene to be monitored; the maximum number of times that the class to be monitored is allowed to be instantiated when the scene to be monitored runs to the current stage (such as loading to the current page) can also be used, so as to further improve the accuracy of the memory leak detection result.
The scenario to be monitored may be understood as a scenario in which memory leak monitoring needs to be performed in an application (i.e., a target application), such as a page or a module (which may include multiple pages) that needs to be performed memory leak monitoring, and may be any scenario currently running in the target application or a scenario currently running and needing memory leak monitoring. The class to be monitored can be understood as a class whose instantiation times are required to be monitored in the scene to be monitored, and this embodiment can monitor all classes or part of classes in the scene to be monitored, and preferably can monitor only the classes that are required to be instantiated for multiple times in the scene to be monitored, so as to further improve the detection efficiency of memory leakage. The scenes to be monitored in the target application program and the classes to be monitored in the scenes to be monitored can be set by a program developer according to needs, and the classes to be monitored can be different in different scenes to be monitored; when the number of the to-be-monitored scenes and/or the number of the to-be-monitored classes are multiple, the method for detecting the memory leakage provided by the embodiment may be executed for each to-be-monitored class in each to-be-monitored scene.
Specifically, when the current condition of the monitoring tool configured in the electronic device running the target application program meets the detection condition of the memory leak, the current instantiation time of the class to be monitored in the scene to be monitored is obtained, for example, the monitoring tool can initialize the current instantiation time of the class to be monitored to 0 when receiving the loading instruction of the scene to be monitored, and add 1 to the current instantiation time of the class to be monitored each time the instantiation request of the class to be monitored is received (or the class to be monitored is instantiated into the object to be monitored each time), so that when the current condition meets the detection condition of the memory leak, the current instantiation time obtained by accumulation can be directly obtained, and the current instantiation time threshold of the class to be monitored in the scene to be monitored is obtained, for example, the current instantiation time threshold of the target application program pre-input by a software developer is obtained and runs to the current instantiation time threshold corresponding to the current stage, or acquiring the instantiation time threshold value corresponding to each running stage of the target application program input by the software developer in advance, and summing the instantiation time threshold values of the running stages to obtain the current instantiation time threshold value and the like.
In this step, the detection condition of the memory leak may be set as required, for example, the detection condition of the memory leak may be set to a trigger time when the current time reaches the periodic detection, an instantiation request of the class to be monitored is received, or the class to be monitored is instantiated as the object to be monitored, and the like, which is not limited in this embodiment. Considering that the current instantiation frequency of the class to be monitored in the current instantiation scene does not change when the class to be monitored is not instantiated, and correspondingly, the detection result of the memory leak does not change, therefore, the monitoring tool preferably can acquire the current instantiation frequency and the current instantiation frequency threshold of the class to be monitored in the scene to be monitored each time the class to be monitored is instantiated into the object to be monitored, and perform the memory leak detection on the target application program based on the current instantiation frequency and the current instantiation frequency threshold, thereby reducing the operation resources occupied by the memory leak detection process on the premise of ensuring the timeliness of the memory leak detection.
S120, if the current instantiation time is larger than the current instantiation time threshold, determining that the target application program to which the scene to be monitored belongs has memory leakage.
In this embodiment, if the current instantiation time is greater than the current instantiation time threshold, it means that the class to be monitored is abnormally instantiated in the scene to be monitored, that is, the target application program performs redundant instantiation on the class to be monitored in the scene to be monitored, for example, the object to be monitored corresponding to the class to be monitored is additionally created (for example, the object to be monitored is created in the operation that the object to be monitored does not need to be created) or repeatedly created (for example, in the operation that the object to be monitored needs to be created, in the case that the object to be monitored is already created, the monitoring object is repeatedly created again), the redundant instantiation inevitably causes additional occupation of the memory of the electronic device, so that when the current instantiation time of the class to be monitored in the scene to be monitored is greater than the current instantiation time threshold, the situation that the memory of the target application program leaks can be judged.
The method for detecting memory leakage provided in this embodiment obtains the current instantiation time and the current instantiation time threshold of the class to be monitored in the scene to be monitored, and determines that the target application program to which the scene to be monitored belongs has memory leakage when the current instantiation time is greater than the current instantiation time threshold. By adopting the technical scheme, the condition of memory leakage caused by abnormal instantiation of the class to be monitored can be detected in the running process of the scene to be monitored, manual starting and operation of a monitoring tool are not needed, and the memory leakage detection does not need to be carried out until the scene to be monitored is destroyed, so that the timeliness of the memory leakage detection and the comprehensiveness of the memory leakage detection result can be improved.
Fig. 2 is a schematic flow chart of another method for detecting memory leakage according to an embodiment of the present disclosure, and the scheme in this embodiment may be combined with one or more of the alternatives in the foregoing embodiments. In this embodiment, optionally, the to-be-monitored scene includes at least one page, and the acquiring the current instantiation time and the current instantiation time threshold of the to-be-monitored class in the to-be-monitored scene includes: counting the number of objects to be monitored obtained by instantiating the class to be monitored in the scene to be monitored, wherein the number is used as the current instantiating times of the class to be monitored in the scene to be monitored; and calculating the sum of preset instantiation time thresholds of the class to be monitored in each loaded page of the scene to be monitored, wherein the sum is used as the current instantiation time threshold of the class to be monitored in the scene to be monitored.
Optionally, before the obtaining of the current instantiation time and the current instantiation time threshold of the class to be monitored in the scene to be monitored, the method further includes: determining a current page in a loading state in a scene to be monitored; when an instantiation request of a class to be monitored is received, instantiating the class to be monitored into an object to be monitored, and correspondingly recording target class information of the class to be monitored and target object information of the object to be monitored in an instantiation information table of a scene to be monitored.
Optionally, after instantiating the class to be monitored as the object to be monitored, the method further includes: and constructing a weak pointer pointing to the object to be monitored.
Optionally, after determining that there is a memory leak in the target application to which the scene to be monitored belongs, the method further includes: and displaying memory leakage reminding information by a control screen, wherein the memory leakage reminding information comprises at least one of scene information of the scene to be monitored, page information of the current page and target class information of the class to be monitored.
Optionally, before the obtaining of the current instantiation time and the current instantiation time threshold of the class to be monitored in the scene to be monitored, the method further includes: the method comprises the steps of starting when a loading instruction of a scene to be monitored is received, determining a class to be monitored in the scene to be monitored after the starting is completed, and obtaining a preset instantiation time threshold value of the class to be monitored in each page of the scene to be monitored; correspondingly, the method further comprises the following steps: and when a destroy instruction of the scene to be monitored is received, emptying the instantiation information table and finishing the operation.
Correspondingly, as shown in fig. 2, the method for detecting a memory leak according to this embodiment may include:
s210, when a loading instruction of a scene to be monitored is received, starting, after the starting is completed, determining a class to be monitored in the scene to be monitored, and acquiring a preset instantiation time threshold value of the class to be monitored in each page of the scene to be monitored, wherein the scene to be monitored comprises at least one page.
The loading instruction of the scene to be monitored can be understood as an instruction for instructing the target application program to load the scene to be monitored, and the loading instruction can be generated based on a trigger operation of a user. The scene to be monitored can be a page in a target application program, such as a video playing page; the monitoring method can also be a module consisting of a plurality of pages in the target application program, for example, the scene to be monitored can be a video processing module, and the video processing module can comprise a shooting page, an editing page and a publishing page.
Specifically, the monitoring tool may confirm that a loading instruction of the scene to be monitored is received when it is monitored that a user or a program developer performs a triggering operation for starting the scene to be monitored, for example, when it is monitored that a starting control of the scene to be monitored displayed in the target application program is triggered, at this time, the monitoring tool may start, and after the start is completed, obtain class information (such as a class name or a class ID of the class to be monitored) of the class to be monitored in the scene to be monitored, which is input in advance by the program developer, and a preset instantiation time threshold of each class to be monitored in each page of the scene to be monitored.
For example, a program developer can input class information of classes to be monitored in each page of the video processing module and a preset instantiation time threshold value of each class to be monitored in the page in advance, and correspondingly, a monitoring tool can be started when detecting that a user or the program developer triggers the operation of starting the video processing module; therefore, after the video processing module is started, the class information of the class to be monitored of each page input by the program developer is obtained, the class to be monitored in each page is deduplicated to obtain the class to be monitored in the video processing module, if the shooting page comprises A, B and C three classes to be monitored, the editing page comprises B and C two classes to be monitored, and the publishing page comprises C and D two classes to be monitored, the class to be monitored in the video processing module is determined to comprise A, B, C and D; and further acquiring a preset instantiation time threshold value of each class to be monitored in each page, such as respectively acquiring preset instantiation times of the class A to be monitored in a shooting page, an editing page and a publishing page, respectively acquiring preset instantiation times of the class B to be monitored in the shooting page, the editing page and the publishing page, respectively acquiring preset instantiation times of the class C to be monitored in the shooting page, the editing page and the publishing page, and respectively acquiring preset instantiation times of the class D to be monitored in the shooting page, the editing page and the publishing page.
And S220, determining the current page in the loading state in the scene to be monitored.
The current page in the loading state in the scene to be monitored can be understood as a page being loaded in the scene to be monitored at the current time, that is, a page to which the object to be monitored belongs, which is to be instantiated as the class to be monitored, and can be a page currently being displayed by the target application program.
For example, the scene to be monitored may determine a current page in a loaded state in the scene to be monitored according to a trigger operation of a user or a program developer, that is, when it is monitored that the user or the program developer performs a trigger operation of starting a certain page in the scene to be monitored, a target page to be started by the user or the program developer may be determined as the current page in the scene to be monitored in the loaded state, for example, when a first trigger operation for instructing a target application program to start a video processing module is monitored, a first page of the video processing module, that is, a shooting page, is determined as the current page; when second trigger operation for indicating that the target application program jumps from the shooting page to the editing page is monitored, determining the editing page as a current page; and when a third trigger operation for indicating that the target application program jumps from the editing page to the publishing page is monitored, determining the publishing page as the current page, and the like.
S230, when an instantiation request of a class to be monitored is received, instantiating the class to be monitored into an object to be monitored, constructing a weak pointer pointing to the object to be monitored, and correspondingly recording target class information of the class to be monitored and target object information of the object to be monitored in an instantiation information table of a scene to be monitored.
The instantiation request of the class to be monitored can be used for requesting the monitoring tool to instantiate the class to be monitored. The object to be monitored can be understood as an object obtained by instantiating the class to be monitored. The weak pointer corresponds to the strong pointer, and the object to be monitored is pointed by the weak pointer in the embodiment, that is, the object to be monitored is referred by the weak reference, so that it can be ensured that the object to be monitored is not strongly held by the monitoring tool, and thus the object to be monitored can not be normally released. The instantiation information table may be understood as an information table for recording a corresponding relationship between each class to be monitored in a scene to be monitored and an object to be monitored obtained by instantiating the class to be monitored, where the corresponding relationship may be implemented by correspondingly recording target class information of the class to be monitored and target object information of the object to be monitored, the target class information may understand class information of the currently monitored class to be monitored, which may include a class name or a class ID of the class to be monitored, and the target object information may be understood as object information of the object to be monitored, which may include an object name or an object ID of the object to be monitored.
In this embodiment, since the target application needs to call the method for initialization in the operating system of the electronic device to request the electronic device to allocate a memory space for the class to be monitored when instantiating the class to be monitored, this embodiment may determine whether an instantiation request for the class to be monitored is received by monitoring whether the target application sends a call request for the method for initialization of the class to be monitored (i.e., an initialization method call request corresponding to the class to be monitored) to the electronic device, for example, the monitoring tool may intercept, by using a hook (i.e., hook) technique, an instantiation request sent when the class to be monitored needs to be instantiated in an original running method of the target application, and after intercepting the instantiation request, execute subsequent monitoring logic based on the instantiation request.
Specifically, when an initialization method call request corresponding to a class to be monitored, which is sent by a target application program, is monitored, a monitoring tool determines that an instantiation request of the class to be monitored is received, allocates a memory space to the class to be monitored to be created according to the initialization method call request, instantiates the class to be monitored into an object to be monitored according to relevant instantiation information of the class to be monitored, stores the monitored object in the allocated memory space, constructs a weak pointer pointing to the object to be monitored according to an address of the memory space, and records target class information of the class to be monitored and target object information of the object to be monitored in a pre-established instantiation information table of the monitoring scene correspondingly.
S240, counting the number of the objects to be monitored obtained by instantiating the class to be monitored in the scene to be monitored, taking the number as the current instantiating number of the class to be monitored in the scene to be monitored, and calculating the sum of preset instantiating number threshold values of the class to be monitored in each loaded page of the scene to be monitored, and taking the sum as the current instantiating number threshold value of the class to be monitored in the scene to be monitored.
Specifically, the monitoring tool may count the number of objects to be monitored of the class to be monitored in the scene to be monitored according to the instantiation information table or the created weak pointer, so as to obtain the current instantiation times of the class to be monitored in the monitoring scene; and according to the preset instantiation times of the class to be monitored in each loaded page of the scene to be monitored, which are input in advance by a program developer, calculating the sum of the preset instantiation times of the class to be monitored in each loaded page of the scene to be monitored, so as to obtain the current instantiation time threshold of the class to be monitored in the scene to be monitored.
The number of the objects to be monitored counted by the monitoring tool may be the number of all the objects to be monitored obtained by instantiating the class to be monitored in the scene to be monitored, or the number of the objects to be monitored which are already instantiated but not yet released in the scene to be monitored; correspondingly, the loaded page in the scene to be monitored may be a page (including the current page) loaded in the scene to be monitored when the scene to be monitored is operated this time, or may be a page loaded in the scene to be monitored but not destroyed when the scene to be monitored is operated this time.
In one embodiment, the current instantiation time is the instantiation time of the class to be monitored in the scene to be monitored, that is, the number of all objects to be monitored, which have been instantiated in the scene to be monitored, and the current instantiation time threshold is the sum of the preset instantiation times of all pages loaded in the current scene. The counting of the number of the objects to be monitored obtained by instantiating the class to be monitored in the scene to be monitored comprises the following steps: counting a first quantity of the target object information recorded in the instantiation information table; correspondingly, before the calculating the sum of the preset instantiation time thresholds of the class to be monitored in each loaded page of the scene to be monitored, the method further includes: and determining each historical page before the current page in the current page and the page loading sequence information of the scene to be monitored as the loaded page of the scene to be monitored.
The page loading sequence information of the scene to be monitored can be understood as the loading sequence information of each page in the scene to be monitored, and can be set and stored in advance by a program developer in a linked list mode.
In the above embodiment, since the instantiation information table correspondingly records the target class information of the class to be monitored and the object information of all the objects to be monitored obtained by instantiating the class to be monitored in the scene to be monitored, when the monitoring tool obtains the current instantiation times of the class to be monitored in the scene to be monitored, the monitoring tool can query the instantiation information table according to the target class information of the class to be monitored to obtain the target object information of the object to be monitored, and count the number of the target object information to obtain the number of the objects to be monitored, thereby obtaining the current instantiation times of the class to be monitored in the scene to be monitored; correspondingly, when the monitoring tool obtains the current instantiation time threshold of the class to be monitored in the scene to be monitored, the preset page loading sequence information of the scene to be monitored can be obtained, the current page and each historical page located before the current page in the page loading sequence information are determined as the loaded page of the scene to be monitored, and the sum of the preset instantiation time thresholds of the class to be monitored in each loaded page is calculated and used as the current instantiation time threshold of the class to be monitored in the scene to be monitored.
In another real-time manner, the current instantiation time is the number of objects to be monitored, which are instantiated in the scene to be monitored but not released yet, of the class to be monitored, and the current instantiation time threshold is the sum of the preset instantiation times of the page loaded in the current scene but not destroyed yet. The counting of the number of the objects to be monitored obtained by instantiating the class to be monitored in the scene to be monitored comprises the following steps: traversing the weak pointers under the class to be monitored, determining target objects to be monitored which are instantiated and not released in the class to be monitored, and counting a second number of the target objects to be monitored; correspondingly, before the calculating the sum of the preset instantiation time thresholds of the class to be monitored in each loaded page of the scene to be monitored, the method further includes: determining the loaded page of the scene to be monitored, which is loaded and not destroyed in the scene to be monitored, as the loaded page of the scene to be monitored.
In the above embodiment, after the monitoring tool instantiates the class to be monitored each time, the weak pointer pointing to the object to be monitored is constructed, and when a certain object to be monitored is released, the object pointed to by the weak pointer pointing to the object to be monitored is empty, so that when the monitoring tool acquires the current instantiation times of the class to be monitored in the scene to be monitored, the monitoring tool can traverse all the weak pointers under the class to be monitored, acquire the object to be monitored of the class to be monitored through the weak pointer, and count the number of the acquired objects to be monitored, which are not empty, so as to acquire the number of the objects to be monitored, which are instantiated but not yet released, of the class to be monitored in the scene to be monitored, and further acquire the current instantiation times of the class to be monitored in the scene to be monitored; correspondingly, when the monitoring tool obtains the current instantiation time threshold of the class to be monitored in the scene to be monitored, the monitoring tool can traverse each page loaded in the scene to be monitored, determine whether each page is not destroyed, determine the page not destroyed in the scene to be monitored as the loaded page of the scene to be monitored, and calculate the sum of the preset instantiation time thresholds of the class to be monitored in each loaded page as the current instantiation time threshold of the class to be monitored in the scene to be monitored.
S250, judging whether the current instantiation time is larger than the current instantiation time threshold, if so, executing S260; if not, executing S230 or S270.
In this embodiment, whether the class to be monitored is abnormally instantiated can be determined according to whether the current instantiation time of the class to be monitored is greater than the current instantiation time threshold of the class to be monitored, so that when the class to be monitored is abnormally instantiated, it is determined that the target application program has memory leakage, and memory leakage reminding is performed; when it is determined that the class to be monitored is not abnormally instantiated, the memory leak reminding is not performed, and the subsequent loading operation of the scene to be monitored is continuously performed, for example, the step returns to perform S230, or when a destroy instruction of the scene to be monitored is received, the instantiation information table is cleared, and the like.
S260, determining that the target application program to which the scene to be monitored belongs has memory leakage, controlling a screen to display memory leakage reminding information, and executing S230 or S270, wherein the memory leakage reminding information comprises at least one of scene information of the scene to be monitored, page information of the current page and target class information of the class to be monitored.
In this embodiment, if the current instantiation time is greater than the current instantiation time threshold when the scene to be monitored is loaded on the current page, and the current instantiation time is not greater than the current instantiation time threshold when the scene to be monitored is loaded on the previous page before the current page, it means that the class to be monitored is instantiated in the current page and is instantiated abnormally, that is, the target application program has a memory leak in the current page, so that the monitoring tool can pop up a memory leak reminding popup window to remind a program developer that the target application program has a memory leak when determining that the target application program to which the scene to be monitored belongs has a memory leak.
The memory leakage reminding popup window can display at least one of scene information of a scene to be monitored with memory leakage, page information of a current page and target class information of a class to be monitored, and preferably can simultaneously display the scene information of the scene to be monitored, the page information of the current page and the target class information of the class to be monitored, so that a program developer can determine which page of which scene the target application program has memory leakage and which class has abnormal instantiation conditions based on the memory leakage reminding popup window, thereby accurately positioning a code with error in the application program code and timely modifying the code.
It can be understood that when the application program is put into use, when it is determined that the target application program to which the scene to be monitored belongs has memory leak, the memory leak reminding information can be directly reported to the server without controlling the screen to display the memory leak reminding information, so that the use experience of the user is improved.
And S270, emptying the instantiation information table and finishing the operation when the destroy instruction of the scene to be monitored is received.
The destroy instruction of the scene to be monitored may be an instruction for notifying the monitoring tool that the scene to be monitored is destroyed, and may be generated when the target application program is received and requests to execute the method for destroying the scene of the scene to be monitored, and the method for destroying the scene of the scene to be monitored may be a method executed after the scene to be monitored is destroyed.
Specifically, the monitoring tool may intercept, by using a hook technology, a call request sent by a method for calling scene destruction of a scene to be monitored in an original operation method of a target application, determine that a destruction instruction of the scene to be monitored is received after the call request is intercepted, and clear an instantiation information table of the scene to be monitored.
It can be understood that the method for detecting memory leak provided in this embodiment may detect memory leak caused by abnormal instantiation of a class to be monitored, and may also detect memory leak caused by other reasons, for example, a monitoring tool may periodically or when receiving a destroy instruction of the scene to be monitored, detect whether each target object created in the scene to be monitored and required to be released when the scene to be monitored is destroyed has been released, and when detecting that there is a target object that is not released, determine that a memory leak exists in a target application, and perform memory leak notification.
In the method for detecting memory leakage provided by this embodiment, the monitoring tool is automatically started when the to-be-monitored scene runs, after the monitoring tool is started, whether the target application program has memory leakage is determined according to the current instantiation time of the to-be-monitored class in the to-be-monitored scene and the current instantiation time threshold, when the memory leakage exists, the scene, the page and the class with the memory leakage are determined, the memory leakage is prompted to be destroyed, and the running is finished when the to-be-monitored scene exists. By adopting the technical scheme, the scene, the page and the column with the memory leakage can be accurately positioned on the premise of realizing the real-time detection of the memory leakage without manually operating and controlling a monitoring tool, so that a program developer can accurately determine the codes with errors in the target application program codes, and the time consumed by rewriting the target application program codes is reduced.
Fig. 3 is a block diagram of a structure of a device for detecting memory leakage according to an embodiment of the present disclosure. The device can be implemented by software and/or hardware, can be configured in an electronic device, and can be typically configured in a smart phone, a tablet computer or a computer, and can detect whether the memory leak exists in the application program by executing the memory leak detection method. As shown in fig. 3, the apparatus for detecting a memory leak provided by the embodiment of the present disclosure may include a number obtaining module 301 and a leak detecting module 302, wherein,
the number obtaining module 301 is configured to obtain a current instantiation number and a current instantiation number threshold of a class to be monitored in a scene to be monitored;
a detecting module 302, configured to determine that there is a memory leak in the target application to which the scene to be monitored belongs when the current instantiation time is greater than the current instantiation time threshold.
In the apparatus for detecting memory leakage provided in this embodiment, the number of times of current instantiations of the class to be monitored in the scene to be monitored and the threshold of the number of times of current instantiations are obtained by the number obtaining module, and when the number of times of current instantiations is greater than the threshold of the number of times of current instantiations, it is determined by the leakage detecting module that there is memory leakage in the target application program to which the scene to be monitored belongs. By adopting the technical scheme, the condition of memory leakage caused by abnormal instantiation of the class to be monitored can be detected in the running process of the scene to be monitored, manual starting and operation of a monitoring tool are not needed, and the memory leakage detection does not need to be carried out until the scene to be monitored is destroyed, so that the timeliness of the memory leakage detection and the comprehensiveness of the memory leakage detection result can be improved.
In the foregoing scheme, the scene to be monitored may include at least one page, and the number obtaining module 301 may include: the system comprises a time counting unit, a judging unit and a monitoring unit, wherein the time counting unit is used for counting the number of objects to be monitored obtained by instantiating a class to be monitored in a scene to be monitored, and the number is used as the current instantiating time of the class to be monitored in the scene to be monitored; and the threshold value calculating unit is used for calculating the sum of preset instantiation time threshold values of the class to be monitored in each loaded page of the scene to be monitored, and the sum is used as the current instantiation time threshold value of the class to be monitored in the scene to be monitored.
Further, the apparatus for detecting a memory leak may further include: the page determining module is used for determining a current page in a loading state in a scene to be monitored before the current instantiation times and the current instantiation time threshold of the class to be monitored in the scene to be monitored are obtained; and the information recording module is used for instantiating the class to be monitored into the object to be monitored when receiving the instantiation request of the class to be monitored, and correspondingly recording the target class information of the class to be monitored and the target object information of the object to be monitored in the instantiation information table of the scene to be monitored.
In the foregoing solution, the number-of-times counting unit may be specifically configured to: counting a first quantity of the target object information recorded in the instantiation information table, wherein the first quantity is used as the current instantiation times of the class to be monitored in the scene to be monitored; correspondingly, the threshold calculation unit may be further configured to: before the sum of preset instantiation time thresholds of the class to be monitored in each loaded page of the scene to be monitored is calculated, determining the current page and each historical page located before the current page in the page loading sequence information of the scene to be monitored as the loaded page of the scene to be monitored.
Further, the apparatus for detecting a memory leak may further include: and the pointer construction module is used for constructing a weak pointer pointing to the object to be monitored after the class to be monitored is instantiated into the object to be monitored.
In the foregoing solution, the number-of-times counting unit may be specifically configured to: traversing the weak pointer under the class to be monitored, determining target objects to be monitored which are instantiated and not released in the class to be monitored, and counting a second number of the target objects to be monitored as the current instantiation times of the class to be monitored in the scene to be monitored; correspondingly, the threshold calculation unit may be further configured to: before the sum of preset instantiation time thresholds of the class to be monitored in each loaded page of the scene to be monitored is calculated, determining the page which is loaded in the scene to be monitored and is not destroyed as the loaded page of the scene to be monitored.
Further, the apparatus for detecting a memory leak may further include: and the reminding module is used for controlling a screen to display memory leakage reminding information after the memory leakage of the target application program to which the scene to be monitored belongs is determined, wherein the memory leakage reminding information comprises at least one of scene information of the scene to be monitored, page information of the current page and target class information of the class to be monitored.
Further, the apparatus for detecting a memory leak may further include: the starting module is used for starting the system when a loading instruction of a scene to be monitored is received before the current instantiation times and the current instantiation time threshold of the class to be monitored in the scene to be monitored are obtained, determining the class to be monitored in the scene to be monitored after the starting is finished, and obtaining a preset instantiation time threshold of the class to be monitored in each page of the scene to be monitored; and the operation ending module is used for emptying the instantiation information table and ending the operation when the destruction instruction of the scene to be monitored is received.
The device for detecting memory leakage provided by the embodiment of the disclosure can execute the method for detecting memory leakage provided by any embodiment of the disclosure, and has the corresponding functional modules and beneficial effects of executing the method for detecting memory leakage. For details of the technology not described in detail in this embodiment, reference may be made to a method for detecting a memory leak provided in any embodiment of the present disclosure.
Referring now to fig. 4, a block diagram of an electronic device (e.g., a terminal device) 400 suitable for use in implementing embodiments of the present disclosure is shown. The terminal device in the embodiments of the present disclosure may include, but is not limited to, a mobile terminal such as a mobile phone, a notebook computer, a digital broadcast receiver, a PDA (personal digital assistant), a PAD (tablet computer), a PMP (portable multimedia player), a vehicle terminal (e.g., a car navigation terminal), and the like, and a stationary terminal such as a digital TV, a desktop computer, and the like. The electronic device shown in fig. 4 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
As shown in fig. 4, the electronic device 400 may include a processing means (e.g., a central processing unit, a graphics processor, etc.) 401 that may perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)402 or a program loaded from a storage device 406 into a Random Access Memory (RAM) 403. In the RAM 403, various programs and data necessary for the operation of the electronic apparatus 400 are also stored. The processing device 401, the ROM 402, and the RAM 403 are connected to each other via a bus 404. An input/output (I/O) interface 405 is also connected to bus 404.
Generally, the following devices may be connected to the I/O interface 405: input devices 406 including, for example, a touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; an output device 407 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; storage devices 406 including, for example, magnetic tape, hard disk, etc.; and a communication device 409. The communication means 409 may allow the electronic device 400 to communicate wirelessly or by wire with other devices to exchange data. While fig. 4 illustrates an electronic device 400 having various means, it is to be understood that not all illustrated means are required to be implemented or provided. More or fewer devices may alternatively be implemented or provided.
In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program carried on a non-transitory computer readable medium, the computer program containing program code for performing the method illustrated by the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network via the communication means 409, or from the storage means 406, or from the ROM 402. The computer program performs the above-described functions defined in the methods of the embodiments of the present disclosure when executed by the processing device 401.
It should be noted that the computer readable medium in the present disclosure can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In contrast, in the present disclosure, a computer readable signal medium may comprise a propagated data signal with computer readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, optical cables, RF (radio frequency), etc., or any suitable combination of the foregoing.
In some embodiments, the clients, servers may communicate using any currently known or future developed network Protocol, such as HTTP (HyperText Transfer Protocol), and may interconnect with any form or medium of digital data communication (e.g., a communications network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), the Internet (e.g., the Internet), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future developed network.
The computer readable medium may be embodied in the electronic device; or may exist separately without being assembled into the electronic device.
The computer readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to: acquiring the current instantiation times and the current instantiation time threshold of a class to be monitored in a scene to be monitored; and if the current instantiation time is greater than the current instantiation time threshold, determining that the target application program to which the scene to be monitored belongs has memory leakage. .
Computer program code for carrying out operations for the present disclosure may be written in any combination of one or more programming languages, including but not limited to an object oriented programming language such as Java, Smalltalk, C + +, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present disclosure may be implemented by software or hardware. Wherein the names of the modules do not in some cases constitute a limitation of the unit itself.
The functions described herein above may be performed, at least in part, by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field Programmable Gate Arrays (FPGAs), Application Specific Integrated Circuits (ASICs), Application Specific Standard Products (ASSPs), systems on a chip (SOCs), Complex Programmable Logic Devices (CPLDs), and the like.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
Example 1 provides a method of detecting a memory leak, according to one or more embodiments of the present disclosure, including:
acquiring the current instantiation times and the current instantiation time threshold of a class to be monitored in a scene to be monitored;
and if the current instantiation time is greater than the current instantiation time threshold, determining that the target application program to which the scene to be monitored belongs has memory leakage.
According to one or more embodiments of the present disclosure, example 2 is the method according to example 1, where the scene to be monitored includes at least one page, and the obtaining of the current instantiation time and the current instantiation time threshold of the class to be monitored in the scene to be monitored includes:
counting the number of objects to be monitored obtained by instantiating the class to be monitored in the scene to be monitored, wherein the number is used as the current instantiating times of the class to be monitored in the scene to be monitored; and the number of the first and second groups,
and calculating the sum of preset instantiation time thresholds of the class to be monitored in each loaded page of the scene to be monitored, and taking the sum as the current instantiation time threshold of the class to be monitored in the scene to be monitored.
Example 3, according to the method of example 2, before the obtaining of the current instantiation time of the class to be monitored in the scene to be monitored and the current instantiation time threshold, further includes:
determining a current page in a loading state in a scene to be monitored;
when an instantiation request of a class to be monitored is received, instantiating the class to be monitored into an object to be monitored, and correspondingly recording target class information of the class to be monitored and target object information of the object to be monitored in an instantiation information table of a scene to be monitored.
Example 4 the method of example 3, where counting the number of objects to be monitored obtained by instantiating a class to be monitored in a scene to be monitored, includes:
counting a first quantity of the target object information recorded in the instantiation information table;
correspondingly, before the calculating the sum of the preset instantiation time thresholds of the class to be monitored in each loaded page of the scene to be monitored, the method further includes:
and determining each historical page before the current page in the current page and the page loading sequence information of the scene to be monitored as the loaded page of the scene to be monitored.
Example 5 the method of example 3, after instantiating the class to be monitored as the object to be monitored, according to one or more embodiments of the present disclosure, further comprising:
and constructing a weak pointer pointing to the object to be monitored.
Example 6 the method of example 5, wherein the counting the number of objects to be monitored obtained by instantiating the class to be monitored in the scene to be monitored, includes:
traversing the weak pointers under the class to be monitored, determining target objects to be monitored which are instantiated and not released in the class to be monitored, and counting a second number of the target objects to be monitored;
correspondingly, before the calculating the sum of the preset instantiation time thresholds of the class to be monitored in each loaded page of the scene to be monitored, the method further includes:
determining the loaded page of the scene to be monitored, which is loaded and not destroyed in the scene to be monitored, as the loaded page of the scene to be monitored.
Example 7 the method of example 3, after determining that there is a memory leak in the target application to which the scene to be monitored belongs, according to one or more embodiments of the present disclosure, further includes:
and displaying memory leakage reminding information by a control screen, wherein the memory leakage reminding information comprises at least one of scene information of the scene to be monitored, page information of the current page and target class information of the class to be monitored.
Example 8 the method according to any one of examples 3 to 7, before the obtaining of the current instantiation time of the class to be monitored in the scene to be monitored and the current instantiation time threshold, further including:
the method comprises the steps of starting when a loading instruction of a scene to be monitored is received, determining a class to be monitored in the scene to be monitored after the starting is completed, and obtaining a preset instantiation time threshold value of the class to be monitored in each page of the scene to be monitored;
correspondingly, the method further comprises the following steps:
and when a destroy instruction of the scene to be monitored is received, emptying the instantiation information table and finishing the operation.
Example 9 provides an apparatus for detecting a memory leak, according to one or more embodiments of the present disclosure, including:
the system comprises a frequency acquisition module, a frequency acquisition module and a frequency comparison module, wherein the frequency acquisition module is used for acquiring the current instantiation frequency and the current instantiation frequency threshold of a class to be monitored in a scene to be monitored;
and the leakage detection module is used for determining that the target application program to which the scene to be monitored belongs has memory leakage when the current instantiation time is greater than the current instantiation time threshold.
Example 10 provides, in accordance with one or more embodiments of the present disclosure, an electronic device comprising:
one or more processors;
a memory for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method for memory leak detection as in any of examples 1-8.
Example 11 provides a computer-readable storage medium having stored thereon a computer program that, when executed by a processor, implements the method of detecting a memory leak of any of examples 1-8.
The foregoing description is only exemplary of the preferred embodiments of the disclosure and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the disclosure herein is not limited to the particular combination of features described above, but also encompasses other embodiments in which any combination of the features described above or their equivalents does not depart from the spirit of the disclosure. For example, the above features and (but not limited to) the features disclosed in this disclosure having similar functions are replaced with each other to form the technical solution.
Further, while operations are depicted in a particular order, this should not be understood as requiring that such operations be performed in the particular order shown or in sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Likewise, while several specific implementation details are included in the above discussion, these should not be construed as limitations on the scope of the disclosure. Certain features that are described in the context of separate embodiments can also be implemented in combination in a single embodiment. Conversely, various features that are described in the context of a single embodiment can also be implemented in multiple embodiments separately or in any suitable subcombination.
Although the subject matter has been described in language specific to structural features and/or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are disclosed as example forms of implementing the claims.

Claims (11)

1. A method for detecting a memory leak, comprising:
acquiring the current instantiation times and the current instantiation time threshold of a class to be monitored in a scene to be monitored;
and if the current instantiation time is greater than the current instantiation time threshold, determining that the target application program to which the scene to be monitored belongs has memory leakage.
2. The method according to claim 1, wherein the scene to be monitored includes at least one page, and the obtaining the current instantiation time and the current instantiation time threshold of the class to be monitored in the scene to be monitored includes:
counting the number of objects to be monitored obtained by instantiating the class to be monitored in the scene to be monitored, wherein the number is used as the current instantiating times of the class to be monitored in the scene to be monitored; and the number of the first and second groups,
and calculating the sum of preset instantiation time thresholds of the class to be monitored in each loaded page of the scene to be monitored, and taking the sum as the current instantiation time threshold of the class to be monitored in the scene to be monitored.
3. The method according to claim 2, before the obtaining of the current instantiation time of the class to be monitored in the scene to be monitored and the current instantiation time threshold, further comprising:
determining a current page in a loading state in a scene to be monitored;
when an instantiation request of a class to be monitored is received, instantiating the class to be monitored into an object to be monitored, and correspondingly recording target class information of the class to be monitored and target object information of the object to be monitored in an instantiation information table of a scene to be monitored.
4. The method according to claim 3, wherein the counting the number of the objects to be monitored instantiated in the scene to be monitored by the class to be monitored comprises:
counting a first quantity of the target object information recorded in the instantiation information table;
correspondingly, before the calculating the sum of the preset instantiation time thresholds of the class to be monitored in each loaded page of the scene to be monitored, the method further includes:
and determining each historical page before the current page in the current page and the page loading sequence information of the scene to be monitored as the loaded page of the scene to be monitored.
5. The method according to claim 3, further comprising, after instantiating the class to be monitored as an object to be monitored:
and constructing a weak pointer pointing to the object to be monitored.
6. The method according to claim 5, wherein the counting the number of the objects to be monitored instantiated in the scene to be monitored by the class to be monitored comprises:
traversing the weak pointers under the class to be monitored, determining target objects to be monitored which are instantiated and not released in the class to be monitored, and counting a second number of the target objects to be monitored;
correspondingly, before the calculating the sum of the preset instantiation time thresholds of the class to be monitored in each loaded page of the scene to be monitored, the method further includes:
determining the loaded page of the scene to be monitored, which is loaded and not destroyed in the scene to be monitored, as the loaded page of the scene to be monitored.
7. The method according to claim 3, further comprising, after the determining that there is a memory leak in the target application to which the scene to be monitored belongs:
and displaying memory leakage reminding information by a control screen, wherein the memory leakage reminding information comprises at least one of scene information of the scene to be monitored, page information of the current page and target class information of the class to be monitored.
8. The method according to any one of claims 3 to 7, wherein before the obtaining of the current instantiation time of the class to be monitored in the scene to be monitored and the current instantiation time threshold, the method further comprises:
the method comprises the steps of starting when a loading instruction of a scene to be monitored is received, determining a class to be monitored in the scene to be monitored after the starting is completed, and obtaining a preset instantiation time threshold value of the class to be monitored in each page of the scene to be monitored;
correspondingly, the method further comprises the following steps:
and when a destroy instruction of the scene to be monitored is received, emptying the instantiation information table and finishing the operation.
9. A device for detecting a memory leak, comprising:
the system comprises a frequency acquisition module, a frequency acquisition module and a frequency comparison module, wherein the frequency acquisition module is used for acquiring the current instantiation frequency and the current instantiation frequency threshold of a class to be monitored in a scene to be monitored;
and the leakage detection module is used for determining that the target application program to which the scene to be monitored belongs has memory leakage when the current instantiation time is greater than the current instantiation time threshold.
10. An electronic device, comprising:
one or more processors;
a memory for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method for memory leak detection as recited in any of claims 1-8.
11. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the method for detecting a memory leak according to any one of claims 1 to 8.
CN202010779108.0A 2020-08-05 2020-08-05 Memory leak detection method and device, electronic equipment and storage medium Pending CN111949528A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010779108.0A CN111949528A (en) 2020-08-05 2020-08-05 Memory leak detection method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010779108.0A CN111949528A (en) 2020-08-05 2020-08-05 Memory leak detection method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN111949528A true CN111949528A (en) 2020-11-17

Family

ID=73338050

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010779108.0A Pending CN111949528A (en) 2020-08-05 2020-08-05 Memory leak detection method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN111949528A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112463603A (en) * 2020-11-25 2021-03-09 北京达佳互联信息技术有限公司 Memory leak detection method and device, terminal and storage medium

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103927305A (en) * 2013-01-11 2014-07-16 中国移动通信集团山东有限公司 Method and device for controlling memory overflow
CN104778087A (en) * 2014-01-09 2015-07-15 中国移动通信集团山东有限公司 Information processing method and information processing device
GB201617531D0 (en) * 2016-10-14 2016-11-30 Imagination Technologies Limited Detecting out-of-bounds violations in a hardware design using formal
CN107102922A (en) * 2017-04-01 2017-08-29 北京三快在线科技有限公司 Internal-memory detection method, device and electronic equipment
CN109726069A (en) * 2018-05-07 2019-05-07 平安普惠企业管理有限公司 H5 page EMS memory occupation monitoring method, device, equipment and readable storage medium storing program for executing
CN110704129A (en) * 2019-09-30 2020-01-17 北京金山安全软件有限公司 Resource instantiation method and device, electronic equipment and storage medium

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103927305A (en) * 2013-01-11 2014-07-16 中国移动通信集团山东有限公司 Method and device for controlling memory overflow
CN104778087A (en) * 2014-01-09 2015-07-15 中国移动通信集团山东有限公司 Information processing method and information processing device
GB201617531D0 (en) * 2016-10-14 2016-11-30 Imagination Technologies Limited Detecting out-of-bounds violations in a hardware design using formal
CN107102922A (en) * 2017-04-01 2017-08-29 北京三快在线科技有限公司 Internal-memory detection method, device and electronic equipment
CN109726069A (en) * 2018-05-07 2019-05-07 平安普惠企业管理有限公司 H5 page EMS memory occupation monitoring method, device, equipment and readable storage medium storing program for executing
CN110704129A (en) * 2019-09-30 2020-01-17 北京金山安全软件有限公司 Resource instantiation method and device, electronic equipment and storage medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112463603A (en) * 2020-11-25 2021-03-09 北京达佳互联信息技术有限公司 Memory leak detection method and device, terminal and storage medium

Similar Documents

Publication Publication Date Title
CN111432001B (en) Method, apparatus, electronic device and computer readable medium for jumping scenes
CN110618928A (en) Memory leak detection method and device, terminal equipment and medium
CN112099982A (en) Collapse information positioning method, device, medium and electronic equipment
CN110851281A (en) Method, server, terminal, system and storage medium for detecting memory leakage
CN111949528A (en) Memory leak detection method and device, electronic equipment and storage medium
CN113760503A (en) Task migration method and device, electronic equipment and computer readable medium
CN117093149A (en) Memory management method, device, medium and electronic equipment
CN110674050A (en) Memory out-of-range detection method and device, electronic equipment and computer storage medium
CN114296986A (en) Memory leak positioning method, device, medium and electronic equipment
CN111625326B (en) Task pipeline execution method and device and electronic equipment
CN111290812B (en) Display method, device, terminal and storage medium of application control
CN114741686A (en) Method and device for detecting program white list and related equipment
CN110795194B (en) Desktop display control method, device, terminal and storage medium
CN110502891B (en) Method, device, medium and electronic equipment for acquiring process memory leakage
CN113407309A (en) Virtual machine memory application method and device, storage medium and electronic equipment
CN113518183A (en) Camera calling method and device and electronic equipment
CN113138883A (en) Message processing method and device, storage medium and electronic equipment
CN110633141A (en) Memory management method and device of application program, terminal equipment and medium
CN110633566A (en) Intrusion detection method, device, terminal equipment and medium
CN114398233B (en) Load abnormality detection method and device, server and storage medium
CN117992204A (en) Memory detection method, device, equipment and storage medium
CN110471714B (en) Method, device, terminal and storage medium for controlling application starting
CN115952088A (en) Memory leak detection method, device, equipment and storage medium
CN112286773A (en) Method, device, medium and electronic equipment for collecting crash information
CN113268392A (en) Video memory monitoring method and device, readable medium and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination