CN110851279A - Memory leak processing method, device, equipment and storage medium - Google Patents

Memory leak processing method, device, equipment and storage medium Download PDF

Info

Publication number
CN110851279A
CN110851279A CN201911101874.5A CN201911101874A CN110851279A CN 110851279 A CN110851279 A CN 110851279A CN 201911101874 A CN201911101874 A CN 201911101874A CN 110851279 A CN110851279 A CN 110851279A
Authority
CN
China
Prior art keywords
memory
time point
relation
relationship
pointer value
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.)
Granted
Application number
CN201911101874.5A
Other languages
Chinese (zh)
Other versions
CN110851279B (en
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.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen 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 Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN201911101874.5A priority Critical patent/CN110851279B/en
Publication of CN110851279A publication Critical patent/CN110851279A/en
Application granted granted Critical
Publication of CN110851279B publication Critical patent/CN110851279B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5022Mechanisms to release resources
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/0703Error or fault processing not based on redundancy, i.e. by taking additional measures to deal with the error or fault not making use of redundancy in operation, in hardware, or in data representation
    • G06F11/079Root cause analysis, i.e. error or fault diagnosis

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Health & Medical Sciences (AREA)
  • Biomedical Technology (AREA)
  • Quality & Reliability (AREA)
  • Storage Device Security (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the application discloses a method, a device, equipment and a storage medium for processing memory leakage, which are used for making up for a short board which cannot locate objects with memory leakage when a weak reference table is manually maintained, and realizing accurate location of the objects with memory leakage. The memory leak processing method provided by the embodiment of the application comprises the following steps: obtaining memory information of at least one memory object, wherein the memory information comprises creation information; determining a first relation set, a second relation set and a third relation set of each memory object according to the creation information of each memory object, wherein each reference relation in the first relation set, the second relation set and the third relation set respectively indicates that the memory object is referenced at a first time point, a second time point and a third time point, the first time point is earlier than the second time point, and the second time point is earlier than the third time point; and determining the target object according to each reference relation in the first relation set, the second relation set and the third relation set.

Description

Memory leak processing method, device, equipment and storage medium
Technical Field
The embodiment of the application relates to the technical field of computers, in particular to a method, a device, equipment and a storage medium for processing memory leakage.
Background
In computer science, a memory leak refers to a situation where a program fails to release memory that is no longer in use due to negligence or error. Memory leaks can reduce the performance of the computer by reducing the amount of available memory, and too much available memory being allocated can cause all or part of the device to stop working properly, or the application to crash. However, in general, memory leaks can only be analyzed by programmers of the program source code, which memory is leaked.
In order to find out memory leakage, a global weak reference table is maintained at present, that is, all resource objects to be created are placed in the same weak reference table, and memory recovery (GC) is performed forcibly after a program is run, and then the weak reference table is checked, if a certain memory object is still stored in the weak reference table at this time, it is indicated that the memory object is referred, so that the memory object is leaked.
However, the current method only realizes the discovery of the memory leak by artificially maintaining all created resource objects in the same weak reference table, but cannot clearly locate the object from which the memory leak occurs, so that the object cannot be successfully released.
Disclosure of Invention
The embodiment of the application provides a memory leak processing method, a memory leak processing device, memory leak processing equipment and a memory medium, which are used for accurately positioning a memory leak object, successfully releasing the object and making up for a short board which cannot position the memory leak and omits the memory leak object when a weak reference table is manually maintained.
In a first aspect, an embodiment of the present application provides a method for processing a memory leak, including:
obtaining memory information of at least one memory object, wherein the memory information comprises creation information;
determining a first relation set, a second relation set and a third relation set of each memory object according to the creation information of each memory object, wherein each reference relation in the first relation set indicates that the memory object is referenced at a first time point, each reference relation in the second relation set indicates that the memory object is referenced at a second time point, each reference relation in the third relation set indicates that the memory object is referenced at a third time point, the first time point is earlier than the second time point, and the second time point is earlier than the third time point;
and determining a target object according to each reference relation in the first relation set, each reference relation in the second relation set and each reference relation in the third relation set, wherein the target object is an object with memory leakage.
In a second aspect, an embodiment of the present application provides a memory leak processing apparatus, where the memory leak processing apparatus includes:
an obtaining unit, configured to obtain memory information of at least one memory object, where the memory information includes creation information;
a first determining unit, configured to determine a first relationship set, a second relationship set, and a third relationship set of each memory object according to the creation information of each memory object acquired by the acquiring unit, where each reference relationship in the first relationship set indicates that the memory object is referenced at a first time point, each reference relationship in the second relationship set indicates that the memory object is referenced at a second time point, each reference relationship in the third relationship set indicates that the memory object is referenced at a third time point, the first time point is earlier than the second time point, and the second time point is earlier than the third time point;
a second determining unit, configured to determine a target object according to each reference relationship in the first relationship set, each reference relationship in the second relationship set, and each reference relationship in the third relationship set determined by the first determining unit, where the target object is an object with a memory leak.
With reference to the second aspect, in a first possible implementation manner, the second determining unit includes:
the determining module is used for determining a target relation set from the first relation set, the first relation set and the third relation set according to a preset rule;
the determining module is configured to determine that the memory object referred to by each reference relationship in the target relationship set is a target object.
With reference to the second aspect or the first possible implementation manner of the second aspect, in a second possible implementation manner, the first determining unit includes:
a traversal module, configured to traverse the creation information of each memory object at the first time point, the second time point, and the third time point to obtain a first object pointer value, a second object pointer value, and a third object pointer value of each memory object, respectively;
a generating module, configured to generate the first relationship set from at least one reference relationship indicated by the first object pointer value, generate the second relationship set from at least one reference relationship indicated by the second object pointer value, and generate the third relationship set from at least one reference relationship indicated by the third object pointer value.
With reference to the second possible manner of the second aspect, in a third possible implementation manner, the traversing module includes:
the acquisition submodule is used for acquiring a registry in each type according to the object type, wherein the registry comprises at least one meta table;
the traversal submodule is configured to traverse, when the element table acquired by the acquisition submodule is not the weak reference table, the creation information of the memory object at the first time point through a first object function to obtain the first object pointer value, traverse, at the second time point, the creation information of the memory object through the first object function to obtain the second object pointer value, and traverse, at the third time point, the creation information of the memory object through the first object function to obtain the third object pointer value.
In a third aspect, an embodiment of the present application provides a computer device, including:
the method comprises the following steps: an input/output (I/O) interface, a processor and a memory,
the memory stores program instructions;
the processor is adapted to execute program instructions stored in the memory for implementing the method according to any one of the possible implementations of the first aspect as described above.
A fourth aspect of the present application provides a computer-readable storage medium having stored thereon computer-executable instructions for performing the method according to any one of the possible implementation manners of the first aspect and the first aspect.
A fifth aspect of embodiments of the present application provides a computer program product comprising instructions which, when run on a computer or processor, cause the computer or processor to perform the method of any of the above aspects.
According to the technical scheme, the embodiment of the application has the following advantages:
in the embodiment of the present application, by obtaining creation information of each memory object, and determining a first relationship set, a second relationship set, and a third relationship set of each memory object according to the creation information, because each reference relationship in the first relationship set indicates that a memory object is referenced at a first time point, each reference relationship in the second relationship set indicates that a memory object is referenced at a second time point, and each reference relationship in the third relationship set also indicates that a memory object is referenced at a third time point, and because the first time point is earlier than the second time point, and the second time point is earlier than the third time point, a target object which finally still has a reference relationship can be determined by difference sets and intersection sets between relationship sets at different time points, an object with memory leakage can be accurately located, and the object can be successfully released, the short board which can not locate the memory leakage and omit the object of the memory leakage when the weak reference table is maintained artificially is made up.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
FIG. 1 is a schematic diagram of an architecture provided in an embodiment of the present application;
fig. 2 is a schematic diagram illustrating an embodiment of a method for processing a memory leak provided in an embodiment of the present application;
FIG. 3 is a flow diagram of traversal of object types provided in an embodiment of the present application;
fig. 4 is a schematic diagram illustrating traversal of creation information of a table-type memory object provided in an embodiment of the present application;
fig. 5 is a schematic diagram illustrating another embodiment of a method for processing a memory leak provided in an embodiment of the present application;
fig. 6 is a schematic diagram of a memory snapshot provided in an embodiment of the present application;
FIG. 7 is a diagram of a comparative memory snapshot provided in an embodiment of the present application;
FIG. 8 is a diagram showing the results of a target object in the embodiment of the present application;
fig. 9 is a schematic diagram of an embodiment of a memory leak processing apparatus provided in an embodiment of the present application;
fig. 10 is a schematic diagram of another embodiment of a memory leak processing apparatus provided in an embodiment of the present application;
fig. 11 is a schematic structural diagram of a computer device provided in an embodiment of the present application.
Detailed Description
The embodiment of the application provides a memory leak processing method, a memory leak processing device, memory leak processing equipment and a memory medium, which are used for accurately positioning a memory leak object, successfully releasing the object and making up for a short board which cannot position the memory leak and omits the memory leak object when a weak reference table is manually maintained.
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The terms "first," "second," "third," "fourth," and the like in the description and in the claims of the present application and in the drawings described above, if any, are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the application described herein are capable of operation in sequences other than those illustrated or described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus. The naming or numbering of the steps appearing in the present application does not mean that the steps in the method flow have to be executed in the chronological/logical order indicated by the naming or numbering, and the named or numbered process steps may be executed in a modified order depending on the technical purpose to be achieved, as long as the same or similar technical effects are achieved.
The following introduces application scenarios to which the embodiments of the present application are adapted:
the method provided by the embodiment of the application is mainly applied to application scenes of a Lua script running environment, for example: and positioning memory leak at the game client, and the like. Based on the application scenario, the architecture provided in the embodiment of the present application is shown in fig. 1, and the architecture mainly includes a client, for example: game clients, web page clients, and the like. And the client determines the reference relation of each memory object at different time points based on the created creation information of each memory object, so as to locate the memory leakage object according to the reference relation.
It should be understood that the client described above may be installed on a terminal device. The "terminal device", also called User Equipment (UE), Mobile Station (MS), Mobile Terminal (MT), terminal, etc., is a device for providing voice and/or data connectivity to a user, or a chip disposed in the device, such as a handheld device, a vehicle-mounted device, etc., with wireless connectivity. Currently, some examples of terminal devices are: a mobile phone (mobile phone), a tablet computer, a notebook computer, a palm top computer, a Mobile Internet Device (MID), a wearable device, a Virtual Reality (VR) device, an Augmented Reality (AR) device, a wireless terminal in industrial control (industrial control), a wireless terminal in self driving (self driving), a wireless terminal in remote surgery (remote medical supply), a wireless terminal in smart grid (smart grid), a wireless terminal in transportation safety (smart security), a wireless terminal in city (smart city), a wireless terminal in home (smart home), and the like. The terminal device provided by the embodiment of the application can be a low-complexity terminal device and/or a terminal device in a coverage enhancement A mode and the like.
The method for processing memory leak in this embodiment may be applied to the system architecture shown in fig. 1, and may also be applied to other system architectures, which are not limited herein.
To better understand the scheme provided in the embodiment of the present application, a specific flow in the embodiment is described below, as shown in fig. 2, which is a schematic diagram of an embodiment of a method for processing a memory leak provided in the embodiment of the present application, and the method includes:
201. and acquiring the memory information of at least one memory object, wherein the memory information comprises creation information.
In this embodiment, the object refers to a section of area on the memory, and the memory information may be used to indicate information of a memory creation or release record of the object, and specifically, the memory information of each object may include creation information of all already created memories or creation information of memories to be created. It should be understood that the creation information of the memory, which is created or to be created, is generated after the terminal device or the server receives a creation request message input by the user. For example: when a user wants to purchase a product A from an XX shopping APP, the XX shopping APP is opened by the user and the product A is input, and then the terminal device receives the creation request message, generates corresponding creation information according to the creation request message and stores the corresponding creation information in the memory information.
The memory objects described above may refer to combat objects, game characters, players, articles, and the like in a game scene, and in practical applications, may also include objects in other scenes, which is not limited herein.
202. Determining a first relation set, a second relation set and a third relation set of each memory object according to the creation information of each memory object, wherein each reference relation in the first relation set indicates that the memory object is referenced at a first time point, each reference relation in the second relation set indicates that the memory object is referenced at a second time point, each reference relation in the third relation set indicates that the memory object is referenced at a third time point, the first time point is earlier than the second time point, and the second time point is earlier than the third time point.
In this embodiment, the first relationship set may include one or more reference relationships, and each reference relationship indicates that the memory object is externally referenced to a reference at the first time point, so that the memory object is not completely released at the first time point; after the first time point, the second relationship set may also include one or more reference relationships, where each reference relationship indicates that the memory object is externally referenced to a reference at the second time point, so that the memory object is not completely released at the second time point; similarly, after the second point in time, the third set of relationships may also include one or more reference relationships, each of which indicates that the memory object was externally referenced to a reference at the third point in time, such that the memory object is not fully released at the third point in time.
It should be understood that the first relationship set, the second relationship set, and the third relationship set described above are obtained by performing a snapshot on the creation information of each memory object in a memory snapshot manner at the first time point, the second time point, and the third time point, respectively, and after the snapshot is performed on the creation information of each memory object, reference relationships corresponding to each memory object are obtained correspondingly, that is, specific reference relationships between the memory object and external references are obtained, and the memory objects leaked from the memory can be located and found out through the reference relationships between the memory objects at a plurality of different time points.
It should be understood that the first point in time described above may be a point in time before entering a XXXX scene, while the second point in time may be a point in time after entering a XXXX scene and before not exiting the XXXX scene, and the third point in time may be a point in time after exiting the XXXX scene.
For example: in the game scene of the hand game or the end game, the first time point is before entering the game scene of the hand game or the end game, the second time point is in the game scene of the hand game or the end game, and the third time point is after the game scene of the hand game or the end game is finished. In practical applications, the first time point, the second time point, and the third time point should also include, but are not limited to, the time points of the game scenes of the a-hand game or the B-end game, and will not be specifically limited in the embodiments of the present application.
Optionally, in some embodiments, how to determine the relationship set may be performed in the following manner, namely:
traversing the creation information of each memory object at the first time point, the second time point and the third time point to obtain a first object pointer value, a second object pointer value and a third object pointer value of each memory object respectively; and generating the first relation set by using at least one reference relation indicated by the first object pointer value, generating the second relation set by using at least one reference relation indicated by the second object pointer value, and generating the third relation set by using at least one reference relation indicated by the third object pointer value.
In this embodiment, each memory object has an object pointer key corresponding to the memory object, and the object pointer value corresponding to the object pointer key describes at least one reference relationship in which the corresponding memory object is referred to in sufficient detail, so that the creation information of each memory object can be traversed, and the corresponding object pointer value can be obtained. In this way, after the first object pointer value is obtained at the first time point, the first relationship set may be generated from at least one reference relationship indicated by the first object pointer value; similarly, after obtaining the second object pointer value at the second time point, the second relationship set may be generated from at least one reference relationship indicated by the second object pointer value, and after obtaining the third object pointer value at the third time point, the third relationship set may be generated from at least one reference relationship indicated by the third object pointer value.
Optionally, on the basis of the above-described alternative embodiments, in other embodiments, the following may be performed for how to traverse to obtain the object pointer value, that is:
acquiring a registry in each type according to the object type, wherein the registry comprises at least one meta table; when the meta table is not a weak reference table, traversing creation information of the memory object at the first time point through a first object function to obtain the first object pointer value, traversing creation information of the memory object at the second time point through the first object function to obtain the second object pointer value, and traversing creation information of the memory object at the third time point through the first object function to obtain the third object pointer value.
In this embodiment, the object type may include, but is not limited to, a table type, a user data type, a run data type, or a thread type. As the memory objects can be distinguished by the object types, and the memory objects of different types can be traversed by different type functions, please refer to fig. 3, which is a flowchart for traversing the object types provided in the embodiment of the present application. As can be seen from fig. 3, the creation information of the table-type memory object may be traversed by a mark _ table () function, the creation information of the user data-type memory object may be traversed by a mark _ userdata () function, the creation information of the run data-type memory object may be traversed by a mark _ function () function, and the creation information of the thread-type memory object may be traversed by a mark _ thread () function. In addition, as can be seen from fig. 3, by determining the object type, if the object type is not the creation information of the memory object of the corresponding object type, the traversal process of the next object type is entered. Such as: whether the memory object is of a table type or not can be judged firstly, and if the memory object is of the table type, the mark _ table () function is utilized to traverse the creation information of the memory object of the table type; if the user data type is not the table type, judging whether the user data type is the user data type, and if the user data type is the user data type, traversing the creation information of the memory object of the user data type by using a mark _ userdata () function; if the data type is not the user data type, judging whether the data type is the operation data type, if so, traversing the creation information of the memory object of the operation data type by using a mark _ function () function; if the type of the memory object is not the operation data type, judging whether the type of the memory object is the thread type, and if the type of the memory object is the thread data type, traversing the creation information of the memory object of the thread type by using a mark _ thread () function; if not, then the next memory object traversal is entered. It should be understood that, in practical applications, the traversal order of the object types of the different types of memory objects described above will not be limited in the embodiments of the present application.
For a memory object of a certain type, a global registry of the type may be obtained, where the registry includes at least one meta table. And when the element table is not the weak reference table, traversing the creation information of the memory object in the element table according to the first object function so as to obtain an object pointer value. Therefore, the creation information of the memory object is traversed by the first object function at the first time point to obtain the first object pointer value, the creation information of the memory object is traversed by the first object function at the second time point to obtain the second object pointer value, and the creation information of the memory object is traversed by the first object function at the third time point to obtain the third object pointer value.
For example: in the embodiment of the present application, taking a table type as an example, please refer to fig. 4, which is a schematic diagram illustrating traversal performed on creation information of a memory object of the table type provided in the embodiment of the present application.
As can be seen from fig. 4, for a table type, the registry is deeply traversed by the object type function mark _ table, and it can be determined whether the meta table metadata is a weak reference table, when the meta table is not a weak reference table, the creation information of the memory object in the meta table can be traversed according to the first object function mark _ object, specifically, the value pointed by each object pointer key is traversed after the object pointer key of the memory object is traversed by the mark _ object, so that the object pointer value can be obtained. It should be understood that, in practical applications, the creation information of the memory object may also be traversed by a breadth first algorithm, and the like, which is not specifically limited in this embodiment.
203. And determining a target object according to each reference relation in the first relation set, each reference relation in the second relation set and each reference relation in the third relation set, wherein the target object is an object with memory leakage.
In this embodiment, since the first relationship set, the second relationship set, and the third relationship set each include at least one reference relationship, and each reference relationship in the three relationship sets may be the same or different, that is, it is understood that each reference relationship in the first relationship set may be the same or different from each reference relationship in the second relationship set and each reference relationship in the third relationship set, which is not specifically limited in this embodiment of the application. The target object may be determined from the reference relationships in the relationship set determined at these different time points, i.e. the memory object with memory leak is located and found.
To better understand the scheme provided in the embodiment of the present application, a specific flow in the embodiment is described below, as shown in fig. 5, which is a schematic diagram of another embodiment of a method for processing a memory leak provided in the embodiment of the present application, where the method includes:
501. and acquiring memory information of at least one memory object, wherein the memory information comprises creation information.
502. Determining a first relation set, a second relation set and a third relation set of each memory object according to the creation information of each memory object, wherein each reference relation in the first relation set indicates that the memory object is referenced at a first time point, each reference relation in the second relation set indicates that the memory object is referenced at a second time point, each reference relation in the third relation set indicates that the memory object is referenced at a third time point, the first time point is earlier than the second time point, and the second time point is earlier than the third time point.
In this embodiment, the steps 501-502 are similar to the steps 201-202 described in fig. 2, and are not described herein again.
503. Determining a target relation set from the first relation set, the first relation set and the third relation set according to a preset rule;
in this embodiment, the preset rule is a condition defined by the user to accurately locate the object with memory leak from the first relationship set, the second relationship set, and the third relationship set.
Specifically, the preset rule may be an intersection with the second relationship set based on a difference between the third relationship set and the first relationship set, and the mathematical expression may be (S3-S1) ∩ S2, where S1 is the first relationship set, S2 is the second relationship set, and S3 is the third relationship set, the meaning of the mathematical expression indicates that the reference relationship exists in S3, does not exist in S1, and exists in S2.
For example: in the game scene of the game a, assuming that the first relationship set S1 obtained at the first time point is { a1, a2, a3, a4, a5, a6}, the second relationship set S2 obtained at the second time point is { a3, a5, a9, a10, b1, b2}, and the third relationship set S3 obtained at the third time point is { a3, a5, a7, a10, b1, b3}, it is easy to obtain the target set as { a10, b1}, and at this time, the memory objects corresponding to the reference relationships a10 and b1 are target objects. It should be understood that the reference relationships in S1, S2 and S3 described above are only an example, and other reference relationships x, y and the like may also be included in practical applications, and will not be specifically limited in the embodiments of the present application.
504. And determining the memory object referenced by each reference relation in the target relation set as a target object.
Each reference relation in the target relation set indicates that the corresponding memory object is externally referenced, and the corresponding memory cannot be completely released, so that the memory object referenced by each reference relation in the target set can be used as the target object.
It should be noted that, because the first relationship set, the second relationship set, and the third relationship set are respectively at the first time point, the second time point, and the third time point, the creating information of each memory object is snapshot in a memory snapshot manner. Fig. 6 is a schematic diagram of a memory snapshot provided in the embodiment of the present application. Specifically, a "snapshot button" may be clicked at a first time point to complete a memory snapshot S1, a "snapshot button" may be clicked at a second time point to complete a memory snapshot S2, and a "snapshot button" may be clicked at a third time point to complete a memory snapshot S3. Fig. 7 is a schematic diagram of a comparative memory snapshot provided in the embodiment of the present application. That is, after obtaining the memory snapshots three times, clicking the "compare button" can automatically display the target object in the target relationship set.
It is understood that the determined target object may reveal the corresponding data result through the Windows window. Please refer to fig. 8, which shows the result of the target object in the embodiment of the present application. As can be seen from fig. 8, the result display diagram shows a target relationship set, and the target relationship set includes a plurality of target objects that cannot be completely released from the corresponding memory, such as: the target object "9307C 7D 8" is still referenced by "table ox97fcdd28: [ upvalue ]". In addition, in practical application, the target object can be displayed through a web page.
In the embodiment of the present application, by obtaining creation information of each memory object, and determining a first relationship set, a second relationship set, and a third relationship set of each memory object according to the creation information, because each reference relationship in the first relationship set indicates that a memory object is referenced at a first time point, each reference relationship in the second relationship set indicates that a memory object is referenced at a second time point, and each reference relationship in the third relationship set also indicates that a memory object is referenced at a third time point, and because the first time point is earlier than the second time point, and the second time point is earlier than the third time point, a target object which finally still has a reference relationship can be determined by difference sets and intersection sets between relationship sets at different time points, an object with memory leakage can be accurately located, and the object can be successfully released, the short board which can not locate the memory leakage and omit the object of the memory leakage when the weak reference table is maintained artificially is made up.
The scheme provided by the embodiment of the application is mainly introduced from the perspective of a method. It is to be understood that the hardware structure and/or software modules for performing the respective functions are included to realize the above functions. Those of skill in the art will readily appreciate that the various illustrative modules and algorithm steps described in connection with the embodiments disclosed herein may be implemented as hardware or combinations of hardware and computer software. Whether a function is performed as hardware or computer software drives hardware depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
In the embodiment of the present application, functional modules of the apparatus may be divided according to the above method example, for example, each functional module may be divided corresponding to each function, or two or more functions may be integrated into one processing module. The integrated module can be realized in a hardware mode, and can also be realized in a software functional module mode. It should be noted that, in the embodiment of the present application, the division of the module is schematic, and is only one logic function division, and there may be another division manner in actual implementation.
Referring to fig. 9, fig. 9 is a schematic view of an embodiment of a memory leak processing apparatus 90 according to an embodiment of the present application, where the memory leak processing apparatus 90 in the embodiment of the present application is described in detail below, and the memory leak processing apparatus 90 may include:
an obtaining unit 901, configured to obtain memory information of at least one memory object, where the memory information includes creation information;
a first determining unit 902, configured to determine, according to the creation information of each memory object acquired by the acquiring unit 901, a first relationship set, a second relationship set, and a third relationship set of each memory object, where each reference relationship in the first relationship set indicates that the memory object is referenced at a first time point, each reference relationship in the second relationship set indicates that the memory object is referenced at a second time point, each reference relationship in the third relationship set indicates that the memory object is referenced at a third time point, the first time point is earlier than the second time point, and the second time point is earlier than the third time point;
a second determining unit 903, configured to determine a target object according to each reference relationship in the first relationship set, each reference relationship in the second relationship set, and each reference relationship in the third relationship set determined by the first determining unit 902, where the target object is an object with memory leak.
Optionally, on the basis of the embodiment corresponding to fig. 9, referring to fig. 10, in another embodiment of the apparatus 90 for processing memory leak provided in the embodiment of the present application, the second determining unit 903 includes:
a determining module 9031, configured to determine a target relationship set from the first relationship set, and the third relationship set according to a preset rule;
the determining module 9031 is configured to determine that a memory object referred to by each reference relationship in the target relationship set is a target object.
Optionally, on the basis of the embodiments corresponding to fig. 9 and fig. 10, in another embodiment of the apparatus 90 for processing memory leak provided in this embodiment of the present application, the first determining unit 902 includes:
a traversal module, configured to traverse the creation information of each memory object at the first time point, the second time point, and the third time point to obtain a first object pointer value, a second object pointer value, and a third object pointer value of each memory object, respectively;
a generating module, configured to generate the first relationship set from at least one reference relationship indicated by the first object pointer value, generate the second relationship set from at least one reference relationship indicated by the second object pointer value, and generate the third relationship set from at least one reference relationship indicated by the third object pointer value.
Optionally, on the basis of the optional embodiments corresponding to fig. 9 and fig. 10, in another embodiment of the memory leak processing apparatus 90 provided in the embodiment of the present application, the traversal module includes:
the acquisition submodule is used for acquiring a registry in each type according to the object type, wherein the registry comprises at least one meta table;
the traversal submodule is configured to traverse, when the element table acquired by the acquisition submodule is not the weak reference table, the creation information of the memory object at the first time point through a first object function to obtain the first object pointer value, traverse, at the second time point, the creation information of the memory object through the first object function to obtain the second object pointer value, and traverse, at the third time point, the creation information of the memory object through the first object function to obtain the third object pointer value.
In this embodiment of the application, the creating information of each memory object is obtained by the obtaining unit 901, and the first determining unit 902 determines the first relationship set, the second relationship set, and the third relationship set of each memory object according to the creating information, because each reference relationship in the first relationship set indicates that a memory object is referenced at a first time point, each reference relationship in the second relationship set indicates that a memory object is referenced at a second time point, and each reference relationship in the third relationship set also indicates that a memory object is referenced at a third time point, and because the first time point is earlier than the second time point and the second time point is earlier than the third time point, a target object which finally still has a reference relationship can be determined by a difference set and an intersection set between relationship sets at different time points, and an object which leaks from the memory can be accurately located, and the object is successfully released, and the defects that the memory leak cannot be positioned and the object with the memory leak is missed when the weak reference table is manually maintained are overcome.
The processing apparatus 90 for memory leak in the embodiment of the present application is described above from the perspective of a modular functional entity, and the computer device in the embodiment of the present application is described below from the perspective of hardware processing. Fig. 11 is a schematic structural diagram of a computer device according to an embodiment of the present disclosure, where the computer device may include the memory leak processing apparatus 90 and the like described above, and the computer device may have a relatively large difference due to different configurations or performances, and the computer device may include at least one processor 1001, a communication line 1007, a storage 1003, and at least one communication interface 1004.
The processor 1001 may be a general-purpose Central Processing Unit (CPU), a microprocessor, an application-specific integrated circuit (server IC), or one or more ICs for controlling the execution of programs in accordance with the present disclosure.
The communication line 1007 may include a path for transmitting information between the aforementioned components.
The communication interface 1004 may be any device, such as a transceiver, for communicating with other devices or communication networks, such as an ethernet, a Radio Access Network (RAN), a Wireless Local Area Network (WLAN), etc.
The memory 1003 may be a read-only memory (ROM) or other type of static storage device that may store static information and instructions, a Random Access Memory (RAM) or other type of dynamic storage device that may store information and instructions, which may be separate and coupled to the processor via communication link 1007. The memory may also be integral to the processor.
The memory 1003 is used for storing computer-executable instructions for executing the present invention, and is controlled by the processor 1001. The processor 1001 is configured to execute computer-executable instructions stored in the storage 1003, so as to implement the method for processing memory leak provided by the foregoing embodiment of the present application.
Optionally, the computer-executable instructions in the embodiments of the present application may also be referred to as application program codes, which are not specifically limited in the embodiments of the present application.
In particular implementations, the computer device may include multiple processors, such as processor 1001 and processor 1002 of fig. 11, for example, as an embodiment. Each of these processors may be a single-core (single-CPU) processor or a multi-core (multi-CPU) processor. A processor herein may refer to one or more devices, circuits, and/or processing cores for processing data (e.g., computer program instructions).
In particular implementations, the computer device may also include an output device 1005 and an input device 1006, as one embodiment. The output device 1005 communicates with the processor 1001 and may display information in a variety of ways. The input device 1006 is in communication with the processor 1001 and may receive user input in a variety of ways. For example, the input device 1006 may be a mouse, a touch screen device, or a sensing device, among others.
The computer apparatus may be a general-purpose device or a special-purpose device. In particular implementations, the computer device may be a desktop, laptop, nas server, wireless end device, embedded device, or a device with a similar structure as in fig. 11. The embodiment of the application does not limit the type of the computer equipment.
In the embodiment of the present application, the processor 1001 included in the computer device further has the following functions:
obtaining memory information of at least one memory object, wherein the memory information comprises creation information;
determining a first relation set, a second relation set and a third relation set of each memory object according to the creation information of each memory object, wherein each reference relation in the first relation set indicates that the memory object is referenced at a first time point, each reference relation in the second relation set indicates that the memory object is referenced at a second time point, each reference relation in the third relation set indicates that the memory object is referenced at a third time point, the first time point is earlier than the second time point, and the second time point is earlier than the third time point;
and determining a target object according to each reference relation in the first relation set, each reference relation in the second relation set and each reference relation in the third relation set, wherein the target object is an object with memory leakage.
Optionally, in some embodiments of the present application, the processor 1001 may also be specifically configured to,
determining a target relation set from the first relation set, the first relation set and the third relation set according to a preset rule;
and determining the memory object referred by each reference relation in the target relation set as a target object.
Optionally, in some embodiments of the present application, the processor 1001 may also be configured to,
traversing the creation information of each memory object at the first time point, the second time point and the third time point to obtain a first object pointer value, a second object pointer value and a third object pointer value of each memory object respectively;
and generating the first relation set by using at least one reference relation indicated by the first object pointer value, generating the second relation set by using at least one reference relation indicated by the second object pointer value, and generating the third relation set by using at least one reference relation indicated by the third object pointer value.
Optionally, in some embodiments of the present application, the processor 1001 may also be specifically configured to,
acquiring a registry in each type according to the object type, wherein the registry comprises at least one meta table;
when the meta table is not a weak reference table, traversing creation information of the memory object at the first time point through a first object function to obtain the first object pointer value, traversing creation information of the memory object at the second time point through the first object function to obtain the second object pointer value, and traversing creation information of the memory object at the third time point through the first object function to obtain the third object pointer value.
Optionally, in some embodiments of the present application, the processor 1001 may further be specifically configured to enable the object type to include a table type, a user data type, a running data type, or a thread type.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the several embodiments provided in the present application, it should be understood that the disclosed system, apparatus and method may be implemented in other manners. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the unit is only one logical functional division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present application may be substantially implemented or contributed to by the prior art, or all or part of the technical solution may be embodied in a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a read-only memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
The above embodiments are only used to illustrate the technical solutions of the present application, and not to limit the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions in the embodiments of the present application.

Claims (10)

1. A method for processing memory leak is characterized by comprising the following steps:
obtaining memory information of at least one memory object, wherein the memory information comprises creation information;
determining a first relation set, a second relation set and a third relation set of each memory object according to the creation information of each memory object, wherein each reference relation in the first relation set indicates that the memory object is referenced at a first time point, each reference relation in the second relation set indicates that the memory object is referenced at a second time point, each reference relation in the third relation set indicates that the memory object is referenced at a third time point, the first time point is earlier than the second time point, and the second time point is earlier than the third time point;
and determining a target object according to each reference relation in the first relation set, each reference relation in the second relation set and each reference relation in the third relation set, wherein the target object is an object with memory leakage.
2. The method of claim 1, wherein determining a target object according to each reference relationship in the first set of relationships, each reference relationship in the second set of relationships, and each reference relationship in the third set of relationships comprises:
determining a target relation set from the first relation set, the first relation set and the third relation set according to a preset rule;
and determining the memory object referred by each reference relation in the target relation set as a target object.
3. The method according to claim 1 or 2, wherein the determining the first relationship set, the second relationship set, and the third relationship set of each memory object according to the creation information of each memory object comprises:
traversing the creation information of each memory object at the first time point, the second time point and the third time point to obtain a first object pointer value, a second object pointer value and a third object pointer value of each memory object respectively;
and generating the first relation set by using at least one reference relation indicated by the first object pointer value, generating the second relation set by using at least one reference relation indicated by the second object pointer value, and generating the third relation set by using at least one reference relation indicated by the third object pointer value.
4. The method of claim 3, wherein traversing the creation information of each memory object at the first time point, the second time point, and the third time point to obtain a first object pointer value, a second object pointer value, and a third object pointer value of each memory object, respectively, comprises:
acquiring a registry in each type according to the object type, wherein the registry comprises at least one meta table;
when the meta table is not a weak reference table, traversing creation information of the memory object at the first time point through a first object function to obtain the first object pointer value, traversing creation information of the memory object at the second time point through the first object function to obtain the second object pointer value, and traversing creation information of the memory object at the third time point through the first object function to obtain the third object pointer value.
5. The method of claim 4, wherein the object type comprises a table type, a user data type, a run data type, or a thread type.
6. A memory leak processing apparatus is characterized in that,
an obtaining unit, configured to obtain memory information of at least one memory object, where the memory information includes creation information;
a first determining unit, configured to determine a first relationship set, a second relationship set, and a third relationship set of each memory object according to the creation information of each memory object acquired by the acquiring unit, where each reference relationship in the first relationship set indicates that the memory object is referenced at a first time point, each reference relationship in the second relationship set indicates that the memory object is referenced at a second time point, each reference relationship in the third relationship set indicates that the memory object is referenced at a third time point, the first time point is earlier than the second time point, and the second time point is earlier than the third time point;
a second determining unit, configured to determine a target object according to each reference relationship in the first relationship set, each reference relationship in the second relationship set, and each reference relationship in the third relationship set determined by the first determining unit, where the target object is an object with a memory leak.
7. The processing apparatus according to claim 6, wherein the second determining unit includes:
the determining module is used for determining a target relation set from the first relation set, the first relation set and the third relation set according to a preset rule;
the determining module is configured to determine that the memory object referred to by each reference relationship in the target relationship set is a target object.
8. The processing apparatus according to claim 6 or 7, wherein the first determination unit includes:
a traversal module, configured to traverse the creation information of each memory object at the first time point, the second time point, and the third time point to obtain a first object pointer value, a second object pointer value, and a third object pointer value of each memory object, respectively;
a generating module, configured to generate the first relationship set from at least one reference relationship indicated by the first object pointer value, generate the second relationship set from at least one reference relationship indicated by the second object pointer value, and generate the third relationship set from at least one reference relationship indicated by the third object pointer value.
9. A computer device, characterized in that the computer device comprises: an input/output (I/O) interface, a processor and a memory,
the memory has stored therein program instructions;
the processor is configured to execute program instructions stored in the memory to perform the method of any of claims 1 to 5.
10. A computer-readable storage medium comprising instructions that, when executed on a computer device, cause the computer device to perform the method of any of claims 1 to 5.
CN201911101874.5A 2019-11-12 2019-11-12 Memory leakage processing method, device, equipment and storage medium Active CN110851279B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911101874.5A CN110851279B (en) 2019-11-12 2019-11-12 Memory leakage processing method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911101874.5A CN110851279B (en) 2019-11-12 2019-11-12 Memory leakage processing method, device, equipment and storage medium

Publications (2)

Publication Number Publication Date
CN110851279A true CN110851279A (en) 2020-02-28
CN110851279B CN110851279B (en) 2023-10-13

Family

ID=69600537

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911101874.5A Active CN110851279B (en) 2019-11-12 2019-11-12 Memory leakage processing method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN110851279B (en)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20110276833A1 (en) * 2010-05-04 2011-11-10 Oracle International Corporation Statistical analysis of heap dynamics for memory leak investigations
CN107992429A (en) * 2016-10-27 2018-05-04 腾讯科技(深圳)有限公司 A kind of memory object adduction relationship determines method and device
CN108845934A (en) * 2018-05-24 2018-11-20 深圳市腾讯网络信息技术有限公司 The localization method and device in memory overflow source, storage medium, electronic device

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20110276833A1 (en) * 2010-05-04 2011-11-10 Oracle International Corporation Statistical analysis of heap dynamics for memory leak investigations
CN107992429A (en) * 2016-10-27 2018-05-04 腾讯科技(深圳)有限公司 A kind of memory object adduction relationship determines method and device
CN108845934A (en) * 2018-05-24 2018-11-20 深圳市腾讯网络信息技术有限公司 The localization method and device in memory overflow source, storage medium, electronic device

Also Published As

Publication number Publication date
CN110851279B (en) 2023-10-13

Similar Documents

Publication Publication Date Title
CN107644286B (en) Workflow processing method and device
CN111552627A (en) User interface testing method and device, storage medium and computer equipment
US9280665B2 (en) Fast and accurate identification of message-based API calls in application binaries
CN109144370B (en) Screen capturing method, device, terminal and computer readable medium
KR20150064063A (en) Secure identification of computing device and secure identification methods
US10754717B2 (en) Fast and accurate identification of message-based API calls in application binaries
CN106873960A (en) The update method and equipment of a kind of application software
CN110807161A (en) Page framework rendering method, device, equipment and medium
CN109144756A (en) A kind of method and device of stack overflow processing
US10572231B1 (en) Component grouping for application development
CN111753330B (en) Determination method, apparatus, device and readable storage medium for data leakage main body
CN116701053B (en) Method, device, equipment and medium for restoring data backup of production environment database
CN107526966B (en) Composite stain propagation tracking method for Android platform
CN110851279A (en) Memory leak processing method, device, equipment and storage medium
CA2961682C (en) Information display method, terminal, and server
CN108351888B (en) Generating deferrable data streams
US10802715B2 (en) Mounting a drive to multiple computing systems
US20170104798A1 (en) System for broadcasting events
CN107678632B (en) Resource transfer method, terminal and computer readable storage medium
Kang et al. Tablet application for satellite image processing on cloud computing platform
CN113487704B (en) Dovetail arrow mark drawing method and device, storage medium and terminal equipment
CN113656606B (en) Code query method, device and equipment of application program and storage medium
CN112379912B (en) Algorithm management method and device, electronic equipment and storage medium
CN110046004B (en) Method and device for adapting automatic reference counting ARC (ARC resistance) characteristics and electronic equipment
KR20100124455A (en) Method and apparatus for providing network asynchronous input/output processing

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
REG Reference to a national code

Ref country code: HK

Ref legal event code: DE

Ref document number: 40021601

Country of ref document: HK

SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant