CN107957941B - Method and device for processing memory leakage of mobile terminal - Google Patents

Method and device for processing memory leakage of mobile terminal Download PDF

Info

Publication number
CN107957941B
CN107957941B CN201610902954.0A CN201610902954A CN107957941B CN 107957941 B CN107957941 B CN 107957941B CN 201610902954 A CN201610902954 A CN 201610902954A CN 107957941 B CN107957941 B CN 107957941B
Authority
CN
China
Prior art keywords
information
memory
call stack
mobile terminal
leak
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.)
Active
Application number
CN201610902954.0A
Other languages
Chinese (zh)
Other versions
CN107957941A (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 CN201610902954.0A priority Critical patent/CN107957941B/en
Publication of CN107957941A publication Critical patent/CN107957941A/en
Application granted granted Critical
Publication of CN107957941B publication Critical patent/CN107957941B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

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/3636Software debugging by tracing the execution of the program

Landscapes

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

Abstract

The invention provides a method for processing memory leakage of a mobile terminal, which comprises the following steps: the mobile terminal detects whether memory leakage occurs or not; when the mobile terminal detects that the memory leaks, acquiring field information related to the memory leakage; the mobile terminal analyzes and obtains call stack information of memory leakage according to the field information; the mobile terminal reports the field information and the call stack information to the server; and the server generates a bug list according to the field information and the call stack information, and distributes the bug list to corresponding personnel according to preset configuration information. The method for processing the memory leakage of the mobile terminal realizes the automatic operation of the processes of detecting, collecting, analyzing, reporting, distributing and the like of the memory leakage, and improves the efficiency of detecting and processing the memory leakage of the mobile terminal. The invention also provides another method and device for processing the memory leakage of the mobile terminal.

Description

Method and device for processing memory leakage of mobile terminal
Technical Field
The invention relates to the technical field of computers, in particular to a method and a device for processing memory leakage of a mobile terminal.
Background
The memory leakage refers to the space dynamically opened by the dynamic memory allocation function, and is not released after the memory unit is used, so that the memory unit is always occupied. The memory leak is a software defect which is difficult to find, has great harm, and may cause the available memory of the system to be continuously reduced, and finally cause the system to be unstable in operation, even crash and restart.
The existing memory leak detection tool can only detect memory leak, but the subsequent operations of collecting, analyzing, repairing, network reporting and the like of the memory leak information are completed by manual operations of testers or developers, a large amount of time is needed, and the processing efficiency is low.
Disclosure of Invention
In view of the foregoing, it is desirable to provide a method and an apparatus for processing memory leak of a mobile terminal, which can improve the efficiency of detecting and processing memory leak.
A method for processing memory leak of a mobile terminal comprises the following steps:
the mobile terminal detects whether memory leakage occurs or not;
when the mobile terminal detects that the memory leaks, acquiring field information related to the memory leakage;
the mobile terminal analyzes and obtains call stack information of memory leakage according to the field information;
the mobile terminal reports the field information and the call stack information to the server;
and the server generates a bug list according to the field information and the call stack information, and distributes the bug list to corresponding personnel according to preset configuration information.
According to the method for processing the memory leakage of the mobile terminal, when the mobile terminal detects the memory leakage, the field information related to the memory leakage can be automatically acquired, the acquired field information is analyzed, the call stack information of the memory leakage is acquired, and the call stack information are reported to the server together. The server can generate the bug list according to the field information and the call stack information, and the bug list is distributed to corresponding personnel according to preset configuration information. The mobile terminal can automatically report the site information of the memory leakage and the call stack information obtained by analysis when detecting the memory leakage, and the server can automatically distribute the information to corresponding personnel for processing after generating the leakage order, so that the automatic operation of the processes of memory leakage detection, collection, analysis, reporting, distribution and the like is realized, and the efficiency of detecting and processing the memory leakage of the mobile terminal is improved.
A method for processing memory leak of a mobile terminal comprises the following steps:
detecting whether memory leakage occurs;
when the memory leakage is detected, acquiring field information related to the memory leakage;
analyzing and acquiring call stack information of memory leakage according to the field information;
and reporting the field information and the call stack message to a server for processing.
A memory leakage processing device of a mobile terminal comprises:
the detection module is used for detecting whether memory leakage occurs or not;
the acquisition module is used for acquiring field information related to memory leakage when the memory leakage is detected;
the analysis module is used for analyzing and acquiring call stack information of memory leakage according to the field information;
and the reporting module is used for reporting the field information and the call stack information to the server for processing.
According to the method and the device for processing the memory leakage of the mobile terminal, when the memory leakage is detected, the field information related to the memory leakage can be automatically acquired, the acquired field information is analyzed, the call stack information of the memory leakage is acquired, and the call stack information are reported to the server together. The server can perform subsequent processing according to the received field information and the call stack information. When the memory leakage is detected, the field information related to the memory leakage and the call stack information obtained by analysis can be automatically reported, so that the automatic operation of the processes of detecting, collecting, analyzing, reporting and the like of the memory leakage is realized, and the efficiency of detecting and processing the memory leakage of the mobile terminal is improved.
Drawings
FIG. 1 is a diagram illustrating an exemplary embodiment of an application environment for a method for processing memory leaks in a mobile terminal;
FIG. 2 is a diagram illustrating an internal structure of a mobile terminal according to an embodiment;
FIG. 3 is a flowchart illustrating a method for processing memory leaks in a mobile terminal according to an embodiment;
FIG. 4 is a diagram illustrating a method for handling memory leaks in a mobile terminal, according to an embodiment;
FIG. 5 is a detailed flowchart of a method for processing memory leak of a mobile terminal according to an embodiment;
FIG. 6 is a flowchart illustrating a method for processing memory leaks in a mobile terminal according to another embodiment;
FIG. 7 is a flowchart illustrating a method for processing memory leaks in a mobile terminal according to yet another embodiment;
FIG. 8 is a block diagram illustrating an exemplary embodiment of a device for processing memory leaks in a mobile terminal;
fig. 9 is a block diagram of a memory leak processing apparatus of a mobile terminal according to another embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
The method for processing the memory leak of the mobile terminal provided by the embodiment of the invention can be applied to the application environment shown in fig. 1. Referring to fig. 1, a mobile terminal 110 communicates with a server 120 through a network. Specifically, the mobile terminal detects whether a memory leak occurs in the process of running the test version or the formal version of the client, and when the mobile terminal 110 detects that the memory leak occurs, the mobile terminal automatically acquires field information related to the memory leak, analyzes the field information to obtain call stack information, and reports the field information and the call stack information to the server 120. The server 120 is preconfigured with an information table of the client to be monitored, in which version information, process name, software module name to be monitored, and personnel identifier for correspondingly processing the corresponding leak order of the client to be monitored are recorded. Further, the server 120 monitors the field information and the call stack information reported by the mobile terminal, generates a bug form according to the field information and the call stack, and distributes the bug form to corresponding personnel for processing according to a preconfigured information table.
The mobile terminal 110 may be, but is not limited to, various smart phones, tablet computers, portable wearable devices, and the like capable of operating clients. The server 120 may be a network server, such as a cloud-side server.
As shown in fig. 2, there is provided a mobile terminal including a processor, a non-volatile storage medium, an internal memory and a network interface, an input device, which are connected through a system bus. The mobile terminal comprises a nonvolatile storage medium and a mobile terminal memory leak processing device, wherein the nonvolatile storage medium of the mobile terminal stores an operating system, and the mobile terminal memory leak processing device is used for realizing a mobile terminal memory leak processing method. The processor is used to provide computing and control capabilities to support the operation of the entire mobile terminal. The internal memory in the mobile terminal provides an environment for the operation of the memory leak processing apparatus in the non-volatile storage medium, and the internal memory may store computer-readable instructions, and when the computer-readable instructions are executed by the processor, the processor may be caused to execute a method for processing the memory leak of the mobile terminal. The network interface is used for performing network communication with the server, such as sending field information and call stack information related to memory leak to the server, receiving memory leak solution data returned by the server, and the like. The display screen of the mobile terminal can be a liquid crystal display screen or an electronic ink display screen, and the input device can be a touch layer covered on the display screen, a key, a track ball or a touch pad arranged on a shell of the mobile terminal, or an external keyboard, a touch pad or a mouse.
Those skilled in the art will appreciate that the configuration shown in fig. 2 is a block diagram of only a portion of the configuration relevant to the present application, and does not constitute a limitation on the mobile terminal to which the present application is applied, and that a particular mobile terminal may include more or less components than those shown in the figures, or combine certain components, or have a different arrangement of components.
As shown in fig. 3, a method for processing memory leak of a mobile terminal is provided, which is illustrated in the environment shown in fig. 1, and includes the following steps:
in step 310, the mobile terminal detects whether a memory leak occurs.
In this embodiment, the mobile terminal detects whether a memory leak occurs in different systems by using different tools and methods, for example, detects whether a memory leak occurs in an android system by detecting an activity memory release condition in the android system; in the Linux system, a method of reloading new and delete can be used for recording distribution points and periodically printing; or the system Api for allocating memory by using microsoft's detours library and hook: the method comprises the following steps of (1) recording distribution points by adopting HeapAlloc/HeapRealloc/HeapFree (bottom layer calling of new/malloc), and periodically printing to detect memory leakage; memory leaks are detected using vs, as contained in the entry function, — crtdummemmoryleakes ().
And step 320, when the mobile terminal detects that the memory leakage occurs, acquiring field information related to the memory leakage.
In this embodiment, when the mobile terminal detects that a memory leak occurs, the field information related to the memory leak is collected, and the field information may be used to analyze the cause of the memory leak, including but not limited to client process running information, a related code class name, log information, and the like.
And step 330, the mobile terminal obtains the call stack information of the memory leakage according to the field information analysis.
In this embodiment, the field information includes a code class name, and in the process of operating the client by the mobile terminal, generally, another code class is called from one code class, and then another code class is called from another code class, and this calling relationship is a call stack. The call stack information can be analyzed and obtained after the call stack is obtained according to the field information, and the call stack information is generally displayed in the form of code class names. The call stack information can reflect the code execution logic, so that the reason causing the memory leakage can be analyzed according to the call stack information.
And step 340, the mobile terminal reports the field information and the call stack information to the server.
In this embodiment, the mobile terminal uploads the collected field information and the call stack information obtained through analysis to the server, so that the server performs subsequent processing on the memory leak.
Further, in order to improve transmission efficiency, the field information and the call stack information may be compressed and packaged and then uploaded to the server.
In this embodiment, the mobile terminal may collect the field information related to the memory leak through the client, analyze the field information to obtain the call stack information, and may upload the collected field information related to the memory leak and the call stack information obtained according to the field information analysis to the server.
And 350, the server generates a leak order according to the field information and the call stack information, and distributes the leak order to corresponding personnel according to preset configuration information.
In this embodiment, the server pre-configures an information table of the client to be monitored, where version information, process name, software module name to be monitored, and personnel identifier for correspondingly processing the corresponding leak order of the client to be monitored are recorded. And after the server monitors the field information and the call stack information reported by the mobile terminal running the client to be monitored, generating a corresponding leakage order in the corresponding software module according to the field information and the call stack information. And the server distributes the generated bug list to corresponding personnel according to the preset configured software module name and the personnel identification for correspondingly processing the corresponding bug list. Furthermore, after receiving the bug list, the corresponding personnel can process the memory leak according to the bug list.
According to the method for processing the memory leakage of the mobile terminal, when the mobile terminal detects the memory leakage, the field information related to the memory leakage can be automatically acquired, the acquired field information is analyzed, the call stack information of the memory leakage is acquired, and the call stack information are reported to the server together. The server can generate the bug list according to the field information and the call stack information, and the bug list is distributed to corresponding personnel according to preset configuration information. The mobile terminal can automatically report the site information of the memory leakage and the call stack information obtained by analysis when detecting the memory leakage, and the server can automatically distribute the information to corresponding personnel for processing after generating the leakage order, so that the automatic operation of the processes of memory leakage detection, collection, analysis, reporting, distribution and the like is realized, and the efficiency of detecting and processing the memory leakage of the mobile terminal is improved.
In an embodiment, the field information in the method for processing memory leak of a mobile terminal includes at least one of client process running information, a name of a related code class, and log information.
In this embodiment, the client process running information may be used to analyze and obtain call stack information of memory leak. For mobile terminals with different operating systems, the file formats for recording the client process running information are different. For example, for an android system, the hprof file can be used to record client process run information.
Code classes are concepts in object-oriented programming, and are types of data that are abstracted from something of a certain characteristic. When the client runs, generally, another code class is called from one code class, and then another code class calls other code classes; the call relation is a call stack, and the call stack in the memory leak is generally shown in the form of a code class name.
The log information is print information that the program developer adds by himself/herself according to the execution logic of the code, and is generally information that can indicate the logic of the program execution phase. For example, "a decoder object has been created", "video begins to play", etc. Specifically, file saving log information may be created in a storage space of the mobile terminal, and a log file may be generated. In this embodiment, the field information related to the memory leak of the mobile terminal may be used to analyze to obtain the cause of the memory leak, so as to improve the version of the client.
In an embodiment, the method for processing memory leak of a mobile terminal further includes: and when the mobile terminal detects that the memory leakage occurs, releasing the data occupying the memory resource in the page with the memory leakage.
In this embodiment, when the mobile terminal detects that the memory leak occurs, the data occupying the memory resource, such as pictures in the page with the memory leak, is released, so that the influence of the memory leak on the system memory is reduced as much as possible.
As shown in fig. 4, a schematic diagram of a method for processing memory leak of a mobile terminal is provided, which specifically includes the following steps:
at step 410, a memory leak is detected.
Specifically, when a user or a tester normally operates a client in the mobile terminal, for example, the user operates a formal version of the client, or the tester operates a test version of the client, the client may detect whether a memory leak occurs. If a memory leak is detected, the subsequent steps 420 and 470 are automatically performed.
Step 420, collecting the field information related to the memory leak. Specifically, the mobile terminal automatically collects and analyzes the field information related to the memory leak, where the field information includes client process running information, log information, and related code class names.
Step 430, analyze the call stack for memory leaks. Specifically, the mobile terminal automatically analyzes the field information and analyzes and acquires call stack information of the internal code when the memory of the mobile terminal leaks.
Step 440, repairing the memory leak of the mobile terminal. Specifically, the mobile terminal automatically releases resources occupying memory leakage in the page with the memory leakage according to the analyzed call stack information, so that the influence of the memory leakage on the system memory is reduced as much as possible.
And step 450, uploading the information to a network server. Specifically, the mobile terminal automatically reports the collected field information related to the memory leak and the call stack information obtained by analysis to the corresponding network server while repairing the memory leak of the mobile terminal.
Step 460, the web server creates a hole order. Specifically, after receiving reported field information and call stack information related to memory leak, the network server firstly queries whether the same bug form information exists in the bug form, and if so, does not create the bug form, but adds the field information and the call stack information related to the memory leak in the corresponding bug form; and if not, automatically creating the bug list of the memory leak, and adding the reported field information and call stack information related to the memory leak into the bug list.
Step 470, distribute the bug tickets to the corresponding developers. Specifically, the network server automatically allocates the bug tickets to corresponding developers according to the previously set correspondence table between the developers and the software modules and the call stack with memory leakage.
In step 480, the developer analyzes and solves the memory leak problem. Specifically, the developer processes and solves the corresponding memory leakage problem according to the leakage order distributed by the server.
The steps 410-470 are all automatically completed by the client and the web server without any manual operation. The method and the device realize the automatic processing of flows of detecting the memory leakage, collecting field information, analyzing a call stack, repairing, reporting through a network, creating a leakage order, distributing developers and the like, have higher processing efficiency for detecting the memory leakage, have wider application scenes, and can be suitable for an internal test version client and a formal release version client.
In the traditional technology, only memory leakage can be detected when a client is operated, and the subsequent processes of acquiring, analyzing and calling stacks, repairing, network reporting, creating leakage order, distributing developers and the like of the field information related to the memory leakage are completed by manual operation of corresponding personnel, so that the solution efficiency of the memory leakage problem is low; and the method can be only used in the internal test version client, developers cannot acquire the problem of memory leakage encountered by the user in the process of using the release version client, and the application range is small.
As shown in fig. 5, taking an android system as an example, a method for processing memory leak of a mobile terminal is provided, where the method is exemplified by being applied to the environment shown in fig. 1, and includes the following steps:
step 501, the client is started, and life cycle monitoring of all activities is registered.
In this embodiment, activity is one of basic components of the android system, simple description activity is an interface seen by each user, each screen is activity, and the activity includes various controls, such as a text box, buttons, and the like.
In this embodiment, an interface register activity lifecycle callbacks of the android system is called when application is initialized, and the lifecycle of all activities in the registered client is intercepted and recalled. The application is a code base class of a client in the android system, and is used for storing a global variable, which exists when the client starts to create a run in the android system.
Step 502, detecting whether an activity destruction callback occurs in the process of normally operating the client, if so, executing step 503, and if not, executing step 508.
In this embodiment, the activity destruction callback refers to an interface of the android system notification client, which is named onActivityDestroyed. When activity begins to destroy, the android system notifies the client by calling the interface. When the client application monitors the activity callback, the process of detecting the memory leak is started.
Step 503, detecting whether the activity has a weak reference, if yes, executing step 505, and if not, executing step 508.
In this embodiment, the weak reference refers to a code class that points to a program object in the android system and does not affect the recovery of the program object by the system; the method can be used for detecting the android client activity memory leak. When the fact that the activity is destroyed and called back is detected, the android system is meant to destroy the activity, namely various resources inside the activity are destroyed normally. If some resource cannot be released normally, the activity will not be destroyed, indicating that a memory leak has occurred.
Specifically, when it is detected that an activity has a destroy callback, a corresponding weak reference object (for example, may be named as ref) is created according to the activity, the weak reference object does not affect the destroy of the activity and the release of resources, and if the activity can be normally released, the pointed content of the weak reference object is empty, that is, ref.get () (null), which indicates that the activity has no memory leak; if the activity is not destroyed normally, the content pointed by the weak reference object is not empty, which indicates that the activity has a memory leak.
Step 504, collecting the relevant field information of the memory leak.
In this embodiment, when the client detects a memory leak, relevant field information of the memory leak is collected. The field information includes hprof file information of the process, related code class name, log information embedded in advance by the developer, device model information, client version information, and the like.
The hprof file information is a file format used for recording client process running information in the android system, and mainly stores memory snapshots, stack information, cpu service conditions, calls of different threads and the like of the android client process at a specific time point. The method can be used for analyzing the code call stack information when the memory leakage occurs in the android client.
Code classes are concepts in object-oriented programming, and are types of data that are abstracted from something of a certain characteristic. When the client runs, generally, another code class is called from one code class, and then another code class calls other code classes; the call relation is a call stack, and the call stack in the memory leak is generally shown in the form of a code class name.
log information is print information that a program developer adds by himself/herself according to the execution logic of code, and is generally information that can represent the logic of the program execution phase.
The device model information and the client version information facilitate the analysis and the solution of the memory leakage problem for developers, and because program source codes corresponding to different client versions are different, the developers need to analyze and solve the memory leakage problem according to the call stack and the source codes at the same time.
And 505, analyzing the call stack according to the field information.
In this embodiment, the analyzing and obtaining of the call stack information of the memory leak according to the field information is mainly to analyze and obtain the call stack information of the memory leak according to the hprof process file information in the collected field information related to the memory leak.
Step 506, the memory leak is repaired.
In this embodiment, when the mobile terminal detects that a memory leak occurs, all resources occupying the memory inside the related activity are traversed, and some data occupying the memory, such as picture resources, are released, so that it is ensured that only one empty case is leaked due to the memory leak. Namely, the memory leakage is repaired, and the memory leakage is ensured to occupy smaller system memory.
And step 507, reporting the memory leakage related information to a server.
In this embodiment, the client reports the field information and call stack information of the memory leak to the server. So that the server can carry out subsequent processing on the memory leak. For convenience of uploading, the field information and the call stack information can be compressed and packaged and then uploaded to the server.
Step 508, continue running the client.
In this embodiment, if the client does not detect the activity destruction callback, it indicates that there is no activity to be destroyed in the client operation process at this time, that is, there is no internal resource to be destroyed, and the client continues to operate.
In this embodiment, if the client detects that an activity destroy callback occurs, it is described that the client needs to destroy various resources inside the activity. When the activity destruction callback occurs, a corresponding weak reference object is created according to the activity, and the weak reference object has a pointing effect on whether the resources in the activity can be normally released. When detecting that no weak reference exists in the activity, it is indicated that the weak reference point corresponding to the activity is null, that is, the memory resource in the activity is normally released, that is, no memory leak occurs, and the client continues to operate.
In this embodiment, after the client detects that the memory leak occurs, the memory leak is collected, analyzed, and reported. After a series of processing procedures are completed, the client side can continue to operate and repeat the above operation procedures because the memory leak can not directly cause the client side to crash, and the memory leak is continuously detected and processed.
In step 509, the server monitors the memory leak related information reported by the client.
In this embodiment, before step 509, step 509A is further included, and the server configures the relevant information table.
Specifically, the server pre-configures an information table of the client to be monitored, wherein version information, a process name, a software module name to be monitored, a personnel identifier for correspondingly processing the corresponding leak order, a corresponding table of the software module and the corresponding personnel, and the like of the client to be monitored are recorded.
Step 509B, the service is initiated.
Specifically, after the configuration of the information table is completed, a service is started on the network server, so that the server monitors the site information and call stack information related to the memory leak reported by the client to be monitored.
In this embodiment, the server monitors the client that needs to be monitored according to the preset configuration information, and receives the memory leak related information uploaded by the mobile terminal running with the client, where the memory leak related information includes call stack information, hprof files, log files, client version information, and the like.
Step 510, the server creates a leak order.
In this embodiment, according to the reported memory leak information, an interface of the bug system is called, and a bug list (a leak list) of the memory leak is created. Specifically, after receiving the reported field information and call stack information related to memory leak, the server first queries whether the same bug form information exists in the bug form system, where the same bug form information refers to that the call stack is the same as the version information. If the information exists, a leakage order is not created, and the site information and call stack information related to memory leakage are added in the corresponding leakage order; and if the memory leak exists, automatically creating the bug list of the memory leak, and adding the reported field information and call stack information related to the memory leak into the bug list.
Step 511, the server allocates the hole list to the corresponding personnel.
In this embodiment, after the server generates the bug form, the bug form is distributed to the corresponding personnel according to the corresponding information of the preconfigured software module and the corresponding personnel.
Specifically, one corresponding developer corresponds to one software module, one software module may include a plurality of bug tickets, the server obtains a corresponding preconfigured software module name according to the generated bug ticket, and then distributes the generated bug information to the corresponding developer according to the correspondence table of the software module and the corresponding person.
Furthermore, developers can analyze and solve the problem of memory leakage according to the call stack information and the version information received by the server. Specifically, in the android system, program source codes corresponding to different client versions are different, and developers acquire the source codes according to version information and analyze code logic by combining with call stack information so as to analyze and solve the problem of memory leakage.
Furthermore, after the developer solves the problem of memory leakage, the updated version is uploaded, and the client can solve the problem of memory leakage by downloading the updated version.
In this embodiment, the mobile terminal equipped with the android system can automatically detect memory leakage, automatically report field information of the memory leakage and call stack information obtained by analysis after the memory leakage is detected, and automatically repair the memory leakage while reporting to the server; and the server generates a leak order according to the relevant information of the memory leak and automatically distributes the leak order to corresponding personnel according to the leak order. The method and the device realize the automatic operation of the processes of memory leak detection, collection, analysis, repair, report, distribution and the like, not only improve the efficiency of detecting and processing the memory leak of the mobile terminal, but also can be used in a formally released version, and have wider application.
As shown in fig. 6, a method for processing memory leak of a mobile terminal is provided, which is illustrated in the application of the mobile terminal shown in fig. 1 and fig. 2, and includes the following steps:
in step 610, whether a memory leak occurs is detected.
In this embodiment, in different operating systems, different tools and methods are used to detect whether a memory leak occurs, for example, by detecting an activity memory release condition in an android system, whether a memory leak occurs in the android system is detected; in the Linux system, a method of reloading new and delete can be used for recording distribution points and periodically printing; or the system Api for allocating memory by using microsoft's detours library and hook: the method comprises the following steps of (1) recording distribution points by adopting HeapAlloc/HeapRealloc/HeapFree (bottom layer calling of new/malloc), and periodically printing to detect memory leakage; memory leaks are detected using vs, as contained in the entry function, — crtdummemmoryleakes ().
Step 620, collecting the relevant field information of the memory leakage when the memory leakage is detected.
In this embodiment, when a memory leak is detected, field information related to the memory leak is collected, and the field information may be used to analyze the cause of the memory leak, including but not limited to client process running information, related code class names, log information, and the like.
And step 630, analyzing and acquiring the call stack information with memory leakage according to the field information.
In this embodiment, the field information includes a code class name, and in the process of operating the client by the mobile terminal, generally, another code class is called from one code class, and then another code class is called from another code class, and this calling relationship is a call stack. The call stack information can be analyzed and obtained after the call stack is obtained according to the field information, and the call stack information is generally displayed in the form of code class names. The call stack information can reflect the code execution logic, so that the reason causing the memory leakage can be analyzed according to the call stack information.
And step 640, reporting the field information and the call stack information to a server for processing.
In this embodiment, the collected field information and the call stack information obtained through analysis are uploaded to the server, so that the server performs subsequent processing on the memory leak.
Further, in order to improve transmission efficiency, the field information and the call stack information may be compressed and packaged and then uploaded to the server.
In the embodiment, the field information related to the memory leakage can be collected, the call stack information can be obtained according to the field information analysis, the collected field information related to the memory leakage and the call stack information obtained according to the field information analysis can be uploaded to the server, the method and the device can be applied to both an internal test version and a formal release version, and the application range is wider.
According to the method for processing the memory leakage of the mobile terminal, when the memory leakage is detected, the field information related to the memory leakage can be automatically acquired, the acquired field information is analyzed, the call stack information of the memory leakage is acquired, and the call stack information are reported to the server together. The server can perform subsequent processing according to the received field information and the call stack information. When the memory leakage is detected, the field information related to the memory leakage and the call stack information obtained by analysis can be automatically reported, so that the automatic operation of the processes of detecting, collecting, analyzing, reporting and the like of the memory leakage is realized, and the efficiency of detecting and processing the memory leakage of the mobile terminal is improved.
In an embodiment, the field information in the method for processing memory leak of a mobile terminal includes at least one of client process running information, a name of a related code class, and log information.
In this embodiment, the client process running information may be used to analyze and obtain call stack information of memory leak. The file format for recording the running information of the client process is different for different operating systems. For example, for the Android system, the hprof file may be used to record client process run information.
Code classes are concepts in object-oriented programming, and are types of data that are abstracted from something of a certain characteristic. When the client runs, generally, another code class is called from one code class, and then another code class calls other code classes; the call relation is a call stack, and the call stack in the memory leak is generally shown in the form of a code class name.
The log information is print information that the program developer adds by himself/herself according to the execution logic of the code, and is generally information that can indicate the logic of the program execution phase. For example, "a decoder object has been created", "video begins to play", etc. Specifically, file saving log information may be created in a storage space of the mobile terminal, and a log file may be generated. In this embodiment, the field information related to the memory leak may be used to analyze to obtain the cause of the memory leak, so as to improve the client version.
In an embodiment, the method for processing memory leak of a mobile terminal further includes: and when the memory leak is detected, releasing the data occupying the memory resource in the page with the memory leak.
In this embodiment, when the memory leak is detected, the data occupying the memory resource, such as the picture in the page with the memory leak, is released, so as to reduce the influence of the memory leak on the memory as much as possible.
In one embodiment, the client process running information is process file information in a binary format; analyzing and acquiring call stack information of memory leakage according to the field information, wherein the call stack information comprises: reading a binary stream in the process file information, and converting the binary stream into a corresponding character string; and extracting a call stack according to the character string to generate call stack information.
In one embodiment, reporting the field information and the call stack information to a server for processing includes: and reporting the field information and the call stack information to a server, wherein the field information and the call stack information are used for enabling the server to generate a leak list according to the field information and the call stack information, and the leak list is used for enabling the server to distribute relevant personnel according to preset configuration information.
In one embodiment, the method for distributing the bug tickets to the relevant personnel according to the preset configuration information includes: and matching the corresponding software modules according to the bug tickets, and enabling the server to distribute the bug tickets to the related personnel according to the preset software modules and the related personnel corresponding tables.
In this embodiment, the collected field information and the call stack information obtained by analysis generate the leak tickets, different leak tickets correspond to different software modules according to the difference between the field information and the call stack information, and the leak tickets are generated in the corresponding software modules, so that the server distributes the leak tickets of the software modules with memory leaks to corresponding personnel according to a preset correspondence table of the software modules and the corresponding personnel.
As shown in fig. 7, taking an android system as an example, a method for processing memory leak of a mobile terminal is provided, which is illustrated by being applied to the environment shown in fig. 1, and includes the following steps:
step 701, the client is started, and life cycle monitoring of all activities is registered.
In this embodiment, activity is one of basic components of the android system, simple description activity is an interface seen by each user, each screen is activity, and the activity includes various controls, such as a text box, buttons, and the like.
In this embodiment, an interface register activity lifecycle callbacks of the android system is called when application is initialized, and the lifecycle of all activities in the registered client is intercepted and recalled. The application is a code base class of a client in the android system, and is used for storing a global variable, which exists when the client starts to create a run in the android system.
Step 702, detecting whether an activity destruction callback occurs in the process of normally operating the client, if so, executing step 703, and if not, executing step 708.
In this embodiment, the activity destruction callback refers to an interface of the android system notification client, which is named onActivityDestroyed. When activity begins to destroy, the android system notifies the client by calling the interface. When the client application monitors the activity callback, the process of detecting the memory leak is started.
Step 703, detecting whether the activity has a weak reference, if yes, executing step 705, and if not, executing step 708.
In this embodiment, the weak reference refers to a code class that points to a program object in the android system and does not affect the recovery of the program object by the system; the method can be used for detecting the android client activity memory leak. When the fact that the activity is destroyed and called back is detected, the android system is meant to destroy the activity, namely various resources inside the activity are destroyed normally. If some resource cannot be released normally, the activity will not be destroyed, indicating that a memory leak has occurred.
Specifically, when it is detected that an activity is destroyed and recalled, a corresponding weak reference object is created according to the activity, the weak reference object does not affect destruction of the activity and release of resources, and if the activity can be normally released, the pointed content of the weak reference object is empty, that is, ref. If the activity is not destroyed normally, the content pointed by the weak reference object is not empty, which indicates that the activity has a memory leak.
Step 704, collecting the relevant field information of the memory leakage.
In this embodiment, when a memory leak is detected, relevant field information of the memory leak is collected. The field information includes hprof file information of the process, related code class name, log information embedded in advance by the developer, device model information, client version information, and the like.
The hprof file information is a file format used for recording client process running information in the android system, and mainly stores memory snapshots, stack information, cpu service conditions, calls of different threads and the like of the android client process at a specific time point. The method can be used for analyzing the code call stack information when the memory leakage occurs in the android client.
Code classes are concepts in object-oriented programming, and are types of data that are abstracted from something of a certain characteristic. When the client runs, generally, another code class is called from one code class, and then another code class calls other code classes; the call relation is a call stack, and the call stack in the memory leak is generally shown in the form of a code class name.
log information is print information that a program developer adds by himself/herself according to the execution logic of code, and is generally information that can represent the logic of the program execution phase.
The device model information and the client version information facilitate the analysis and the solution of the memory leakage problem for developers, and because program source codes corresponding to different client versions are different, the developers need to analyze and solve the memory leakage problem according to the call stack and the source codes at the same time.
Step 705, analyzing the call stack according to the field information.
In this embodiment, the analyzing and obtaining of the call stack information of the memory leak according to the field information is mainly to analyze and obtain the call stack information of the memory leak according to the hprof process file information in the collected field information related to the memory leak.
Furthermore, the hprof process file is a binary file, and call stack information is generated by reading a binary stream in the hprof process file, converting the binary stream into a character string, and extracting a call stack according to the character string.
Step 706, repair memory leaks.
In this embodiment, when a memory leak is detected, all resources occupying the memory inside the related activity are traversed, and some data occupying the memory, such as picture resources, are released, so that it is ensured that only one empty case is leaked due to the memory leak. Namely, the memory leakage is repaired, and the memory leakage is ensured to occupy smaller system memory.
And step 707, reporting the memory leakage related information to the server for processing.
In this embodiment, the field information and call stack information of the memory leak are reported to the server. So that the server can carry out subsequent processing on the memory leak. For convenience of uploading, the field information and the call stack information can be compressed and packaged and then uploaded to the server. Specifically, the site information and the call stack information are reported to the server, the site information and the call stack information are used for enabling the server to generate the leak tickets according to the site information and the call stack information, the leak tickets are used for enabling the server to match corresponding software modules according to the leak tickets, and the leak tickets are distributed to relevant personnel according to a preset software module and relevant personnel correspondence table.
At step 708, the client continues to run.
In this embodiment, if the activity destruction callback is not detected, it is indicated that there is no activity to be destroyed in the client operation process at this time, that is, there is no internal resource to be destroyed, and the client continues to operate.
In this embodiment, if it is detected that an activity destruction callback occurs, it is described that various resources inside the activity need to be destroyed, and when the activity destruction callback occurs, a corresponding weak reference object is created according to the activity, where the weak reference object has a pointing effect on whether resources in the activity can be normally released. When detecting that no weak reference exists in the activity, it is indicated that the weak reference point corresponding to the activity is null, that is, the memory resource in the activity is normally released, that is, no memory leak occurs, and the client continues to operate.
In this embodiment, when the occurrence of the memory leak is detected, the memory leak is collected, analyzed, and reported. After a series of processing procedures are completed, the client side can continue to operate and repeat the above operation procedures because the memory leak can not directly cause the client side to crash, and the memory leak is continuously detected and processed.
In this embodiment, the client is started, the activity destruction callback is monitored to detect the memory leak, the relevant field information is collected, the call stack information is obtained according to the field information analysis, the field information of the memory leak and the call stack information obtained through the analysis are reported to the server to be processed, and meanwhile, the memory leak is repaired. The method and the device realize the automatic operation of the processes of memory leak detection, collection, analysis, repair, reporting and the like, not only improve the efficiency of detecting and processing the memory leak of the mobile terminal, but also can be used in a formally released version, and have wide application scenes.
As shown in fig. 8, there is provided a memory leak processing apparatus for a mobile terminal, including:
the detecting module 810 is configured to detect whether a memory leak occurs.
The collecting module 820 is configured to collect field information related to memory leak when the memory leak is detected.
And the analysis module 830 is configured to analyze and obtain call stack information of the memory leak according to the field information.
And a reporting module 840, configured to report the field information and the call stack information to the server for processing.
According to the memory leak processing device of the mobile terminal, when the memory leak is detected, the field information related to the memory leak can be automatically acquired, the acquired field information is analyzed, the call stack information of the memory leak is acquired, and the call stack information are reported to the server together. The server can perform subsequent processing according to the received field information and the call stack information. When the memory leakage is detected, the field information related to the memory leakage and the call stack information obtained by analysis can be automatically reported, so that the automatic operation of the processes of detecting, collecting, analyzing, reporting and the like of the memory leakage is realized, and the efficiency of detecting and processing the memory leakage of the mobile terminal is improved.
In one embodiment, the locale information includes at least one of client process run information, an associated code class name, and log information.
In one embodiment, the client process running information is process file information in a binary format; the analysis module 830 is configured to read binary information in the process file information, convert the binary information into a corresponding character string, extract a call stack according to the character string, and generate call stack information.
In one embodiment, the reporting module 840 is further configured to report the field information and the call stack information to the server, where the field information and the call stack information are used to enable the server to generate a bug form according to the field information and the call stack information, and the bug form is used to enable the server to distribute to relevant people according to preset configuration information.
As shown in fig. 9, there is provided a memory leak processing apparatus for a mobile terminal, including:
the detecting module 910 is configured to detect whether a memory leak occurs.
The collecting module 920 is configured to collect field information related to memory leak when the memory leak is detected.
And the analysis module 930 is configured to analyze and obtain call stack information of the memory leak according to the field information.
And a reporting module 940, configured to report the field information and the call stack information to the server for processing.
The repairing module 950 is configured to release data occupying memory resources in the page with the memory leak when the memory leak is detected.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by a computer program, which can be stored in a non-volatile computer-readable storage medium, and can include the processes of the embodiments of the methods described above when the program is executed. The storage medium may be a magnetic disk, an optical disk, a Read-Only Memory (ROM), or the like.
The above-mentioned embodiments only express several embodiments of the present invention, and the description thereof is more specific and detailed, but not construed as limiting the scope of the present invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the inventive concept, which falls within the scope of the present invention. Therefore, the protection scope of the present patent shall be subject to the appended claims.

Claims (14)

1. A method for processing memory leak of a mobile terminal comprises the following steps:
the mobile terminal detects whether memory leakage occurs or not;
when the mobile terminal detects that the memory leaks, acquiring field information and client version information related to the memory leak; the field information comprises at least one of client process running information, related code class names and log information;
the mobile terminal analyzes the call relation among the related code class names according to the field information and acquires call stack information of memory leakage according to the call relation analysis;
the mobile terminal reports the field information, the call stack information and the client version information to a server;
the server generates a leak ticket according to the field information, the call stack information and the client version information, and distributes the leak ticket to corresponding personnel according to preset configuration information; the call stack information and the client version information are used for determining the generation mode of the leakage order.
2. A method for processing memory leak of a mobile terminal comprises the following steps:
detecting whether memory leakage occurs;
when the memory leakage is detected, acquiring field information and client version information related to the memory leakage; the field information comprises at least one of client process running information, related code class names and log information;
analyzing the calling relation among the related code class names according to the field information, and analyzing and acquiring calling stack information of memory leakage according to the calling relation;
reporting the field information, the call stack information and the client version information to a server for processing so that the server generates a leak order according to the field information, the call stack information and the client version information, and distributing the leak order to corresponding personnel according to preset configuration information; the call stack information and the client version information are used for determining the generation mode of the leakage order.
3. The method of claim 2, wherein said detecting whether a memory leak occurs comprises:
and detecting whether the memory leakage occurs in the android system by detecting the memory release condition of activity in the android system.
4. The method according to claim 2, wherein when the memory leak is detected, releasing the data occupying the memory resource in the page with the memory leak.
5. The method of claim 3, wherein the client process running information is process file information in binary format;
the analyzing and acquiring the call stack information of the memory leakage according to the field information comprises the following steps:
reading a binary stream in the process file information, and converting the binary stream into a corresponding character string;
and extracting a call stack according to the character string to generate call stack information.
6. The method of claim 2, wherein the processing the live information and the call stack information by the reporting server comprises:
and reporting the field information and the call stack information to a server, wherein the field information and the call stack information are used for enabling the server to generate a leakage order according to the field information and the call stack information, and the leakage order is used for enabling the server to distribute relevant personnel according to preset configuration information.
7. The method of claim 6, wherein the using the leak order for the server to assign to the relevant personnel according to preset configuration information comprises:
and matching the corresponding software module according to the bug order, and enabling the server to distribute the bug order to the related personnel according to a preset software module and related personnel corresponding table.
8. A memory leak processing device of a mobile terminal, the device comprising:
the detection module is used for detecting whether memory leakage occurs or not;
the system comprises an acquisition module, a storage module and a processing module, wherein the acquisition module is used for acquiring field information and client version information related to memory leakage when the memory leakage is detected; the field information comprises at least one of client process running information, related code class names and log information;
the analysis module is used for analyzing the calling relationship among the related code class names according to the field information and analyzing and acquiring the calling stack information of the memory leakage according to the calling relationship;
the reporting module is used for reporting the field information, the call stack information and the client version information to a server for processing so that the server generates a leak report according to the field information, the call stack information and the client version information, and distributes the leak report to corresponding personnel according to preset configuration information; the call stack information and the client version information are used for determining the generation mode of the leakage order.
9. The apparatus according to claim 8, wherein the detection module is further configured to detect whether a memory leak occurs in the android system by detecting an activity memory release condition in the android system.
10. The apparatus of claim 8, further comprising:
and the repairing module is used for releasing the data occupying the memory resources in the page with the memory leakage when the memory leakage is detected.
11. The apparatus of claim 9, wherein the client process running information is process file information in binary format;
the analysis module is used for reading the binary stream in the process file information, converting the binary stream into a corresponding character string, extracting a call stack according to the character string and generating call stack information.
12. The apparatus according to claim 8, wherein the reporting module is further configured to report the field information and the call stack information to a server, where the field information and the call stack information are used to enable the server to generate a bug according to the field information and the call stack information, and the bug list is used to enable the server to distribute to relevant people according to preset configuration information.
13. A computer device comprising a memory and a processor, the memory storing a computer program that, when executed by the processor, causes the processor to perform the steps of the method according to any one of claims 1 to 7.
14. A storage medium storing a computer program which, when executed by a processor, causes the processor to carry out the steps of the method according to any one of claims 1 to 7.
CN201610902954.0A 2016-10-17 2016-10-17 Method and device for processing memory leakage of mobile terminal Active CN107957941B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610902954.0A CN107957941B (en) 2016-10-17 2016-10-17 Method and device for processing memory leakage of mobile terminal

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610902954.0A CN107957941B (en) 2016-10-17 2016-10-17 Method and device for processing memory leakage of mobile terminal

Publications (2)

Publication Number Publication Date
CN107957941A CN107957941A (en) 2018-04-24
CN107957941B true CN107957941B (en) 2021-03-16

Family

ID=61954460

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610902954.0A Active CN107957941B (en) 2016-10-17 2016-10-17 Method and device for processing memory leakage of mobile terminal

Country Status (1)

Country Link
CN (1) CN107957941B (en)

Families Citing this family (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109240916B (en) * 2018-08-16 2023-04-07 中国平安人寿保险股份有限公司 Information output control method, information output control device and computer readable storage medium
CN109558308A (en) * 2018-09-29 2019-04-02 中国平安人寿保险股份有限公司 Application program method for detecting memory leakage, device, electronic equipment and storage medium
CN109828859B (en) * 2019-01-23 2023-03-07 网易(杭州)网络有限公司 Mobile terminal memory analysis method and device, storage medium and electronic equipment
CN112732513B (en) * 2019-10-28 2023-05-23 腾讯科技(深圳)有限公司 Memory monitoring method, memory monitoring device, computer readable storage medium and computer equipment
CN111046393B (en) * 2019-12-14 2022-08-02 深圳市优必选科技股份有限公司 Vulnerability information uploading method and device, terminal equipment and storage medium
CN111324534A (en) * 2020-02-18 2020-06-23 深圳中兴网信科技有限公司 Memory leak detection method and device, terminal and computer-readable storage medium
CN111400185A (en) * 2020-03-18 2020-07-10 北京字节跳动网络技术有限公司 Memory leak processing method and device, readable medium and electronic equipment
CN111984541A (en) * 2020-08-31 2020-11-24 北京达佳互联信息技术有限公司 Memory leak detection method and device and terminal
CN112016101B (en) * 2020-11-02 2021-03-02 深圳开源互联网安全技术有限公司 Software research and development safety capability dynamic evaluation and promotion method and system
CN112988447B (en) * 2021-05-20 2021-08-20 全时云商务服务股份有限公司 Method, system and readable storage medium for automatically correcting vulnerability information
CN113434364B (en) * 2021-06-25 2024-03-22 青岛海尔科技有限公司 Method and device for detecting memory of screen terminal equipment, storage medium and electronic device

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102419727A (en) * 2011-09-30 2012-04-18 宇龙计算机通信科技(深圳)有限公司 Automatic test method and device
CN105373479A (en) * 2015-12-14 2016-03-02 厦门美图移动科技有限公司 Automatic test method and device of memory leakage and mobile terminal
CN105430681A (en) * 2015-11-04 2016-03-23 努比亚技术有限公司 Automatic abnormity upload and recovery methods, automatic abnormity upload device and mobile terminal
CN105893248A (en) * 2015-12-30 2016-08-24 乐视致新电子科技(天津)有限公司 Method and device for obtaining abnormal relevant information in terminal equipment

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7614043B2 (en) * 2005-08-26 2009-11-03 Microsoft Corporation Automated product defects analysis and reporting

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102419727A (en) * 2011-09-30 2012-04-18 宇龙计算机通信科技(深圳)有限公司 Automatic test method and device
CN105430681A (en) * 2015-11-04 2016-03-23 努比亚技术有限公司 Automatic abnormity upload and recovery methods, automatic abnormity upload device and mobile terminal
CN105373479A (en) * 2015-12-14 2016-03-02 厦门美图移动科技有限公司 Automatic test method and device of memory leakage and mobile terminal
CN105893248A (en) * 2015-12-30 2016-08-24 乐视致新电子科技(天津)有限公司 Method and device for obtaining abnormal relevant information in terminal equipment

Also Published As

Publication number Publication date
CN107957941A (en) 2018-04-24

Similar Documents

Publication Publication Date Title
CN107957941B (en) Method and device for processing memory leakage of mobile terminal
CN109302522B (en) Test method, test device, computer system, and computer medium
CN107729041B (en) Application program hot updating method, device, terminal and storage medium
CN106844136B (en) Method and system for collecting program crash information
US9223681B2 (en) Automated debug trace specification
US10216527B2 (en) Automated software configuration management
CN112988284B (en) Application program starting method and device, computer equipment and storage medium
US9535811B2 (en) Agent dynamic service
US20180159724A1 (en) Automatic task tracking
CN112148606B (en) Buried point test method, buried point test device, buried point test equipment and computer readable medium
CN113094238A (en) Method and device for monitoring abnormity of business system
US9971611B2 (en) Monitoring a mobile device application
CN113760617A (en) Fault processing method and device, equipment and storage medium
CN113032224A (en) Information acquisition method and device, electronic equipment and readable storage medium
CN115794583A (en) Kernel analysis method and device
CN109460234B (en) Application slimming method and device, terminal and storage medium
CN116431443A (en) Log recording method, device, computer equipment and computer readable storage medium
CN113918373A (en) Memory leak monitoring method, memory leak detection method and corresponding devices
CN111414270B (en) Exception handling method and device
CN111459660B (en) Dynamic allocation method of cloud host on host, electronic device and storage medium
Gong et al. Who should we blame for Android app crashes? An in-depth study at scale and practical resolutions
CN111984541A (en) Memory leak detection method and device and terminal
CN114518984A (en) Reporting method and device of embedded point information, storage medium and terminal equipment
US9838488B2 (en) Agent asynchronous transaction monitor
CN112363870B (en) Application program development processing method and device, computer equipment and storage medium

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
GR01 Patent grant
GR01 Patent grant