A memory overflow management method, device, electronic device and storage medium
By monitoring and analyzing the memory space data of the target device in real time and recording memory overflow identifiers, the memory overflow detection and prevention problems in the existing technology are solved, the stability and development efficiency of the app are improved, and the system killing caused by memory overflow is avoided question.
Patent Information
- Application Number
- CN202010726007.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-07-24
- Publication Date
- 2024-12-13
- Estimated Expiration
- 2040-07-24
AI Technical Summary
The existing memory usage monitoring methods have limitations, and it is difficult to prevent and detect memory overflow problems that cause the app to be killed by the system from the source.
By obtaining the real-time memory space data and memory upper limit of the target device, recording the stack information of memory allocation, and setting a memory overflow identifier when the memory overflow risk occurs, and performing memory analysis to prevent and optimize the memory usage of the App.
It realizes that no manual memory analysis is required, which saves development time, improves development efficiency, accurately detects and optimizes the memory usage of the App, avoids system killing problems caused by memory overflow, and improves the stability and survival time of the App.
Smart Images

Figure CN111984401B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a memory overflow management method, device, electronic device and storage medium. Background Art
[0002] The operational stability of the App (Application) is the premise for business development and also the standard for measuring whether an App is excellent. At the same time, the higher the stability of the App, the better the user experience and the higher the relative number of users. The increase in the number of users and daily activity can also promote the App's operating income and other invisible benefits. Therefore, ensuring the stability of the App is a problem that every company must face.
[0003] The unstable factors of the App include excessive memory usage, excessive CPU consumption, high power consumption, frequent crashes, etc., which will cause the App to be killed. Then, re-entering the App requires a cold start process. At present, the general memory aspect is to use the instrument tool in Xcode to detect memory usage and memory leaks, or use a third-party SDK (Software Development Kit) for detection. However, the above method requires the installation of corresponding tools, which has too many limitations. Moreover, there is no tool to analyze whether the App is killed because of memory, and it is difficult to prevent the problem of the App being killed by the system after OOM (out of memory) from the source. Summary of the invention
[0004] The embodiments of the present invention provide a memory overflow management method, device, electronic device and storage medium to solve the problem that the existing memory usage monitoring method has too many limitations and it is difficult to prevent the problem of App being killed by the system after OOM occurs from the source.
[0005] In order to solve the above-mentioned technical problems, the present invention is achieved as follows:
[0006] In a first aspect, an embodiment of the present invention provides a memory overflow management method, comprising:
[0007] Acquire memory space data used in real time in a target device and a memory upper limit of the target device, wherein the memory space data includes at least one of heap memory space data and virtual memory space data;
[0008] When the distance between the memory space data and the memory upper limit is less than a preset value, the stack information of the memory allocation is recorded, and a memory overflow flag is set for the application program running in the foreground of the target device;
[0009] For each application program with a memory overflow flag set, a memory analysis is performed on the application program according to the stack information of the memory allocation.
[0010] Optionally, before the step of performing memory analysis on each application program with a memory overflow flag set according to the stack information of the memory allocation, the method further includes:
[0011] For an application program running in the foreground of the target device, if the application program receives a memory warning, stack information of memory allocation is recorded, and a memory overflow flag is set for the application program.
[0012] Optionally, the step of recording the stack information of memory allocation and setting a memory overflow flag for the application running in the foreground of the target device includes:
[0013] In the storage space locally allocated for the application program on the target device, stack information of memory allocation is recorded, and a memory overflow flag is set for the application program.
[0014] Optionally, the step of performing memory analysis on each application program for which a memory overflow flag is set according to the stack information of the memory allocation includes:
[0015] For each application program with a memory overflow flag set, if the application program is killed, when the application program is cold-started again, stack information corresponding to the application program is locally obtained from the target device;
[0016] Memory analysis is performed on the application program according to the stack information of the memory allocation.
[0017] Optionally, the step of obtaining the memory space data used in real time in the target device includes:
[0018] Acquire the allocation method and release method of the heap memory in the target device through the hook technology, and acquire the heap memory space data based on the allocation method and release method of the heap memory;
[0019] And / or, obtaining the allocation method and release method of the virtual machine memory in the target device through the hook technology, and obtaining the virtual memory space data based on the allocation method and release method of the virtual machine memory.
[0020] In a second aspect, an embodiment of the present invention provides a memory overflow management device, comprising:
[0021] A memory allocation monitoring module, used to obtain the memory space data used in real time in the target device and the memory upper limit of the target device, wherein the memory space data includes at least one of heap memory space data and virtual memory space data;
[0022] A timing analysis module, configured to record the stack information of memory allocation and set a memory overflow flag for the application program running in the foreground of the target device when the distance between the memory space data and the memory upper limit is less than a preset value;
[0023] The memory analysis module is used to perform memory analysis on each application program with a memory overflow flag set according to the stack information of the memory allocation.
[0024] Optionally, the device further comprises:
[0025] The memory warning processing module is used for recording the stack information of memory allocation and setting a memory overflow flag for the application program running in the foreground of the target device if the application program receives a memory warning.
[0026] Optionally, the timing analysis module is further used to:
[0027] In the storage space locally allocated for the application program on the target device, stack information of memory allocation is recorded, and a memory overflow flag is set for the application program.
[0028] Optionally, the memory analysis module includes:
[0029] A memory allocation information acquisition submodule is used to obtain stack information corresponding to each application program set with a memory overflow flag from the local target device when the application program is cold-started again if the application program is killed;
[0030] The memory analysis submodule is used to perform memory analysis on the application program according to the stack information of the memory allocation.
[0031] Optionally, the memory allocation monitoring module includes:
[0032] A heap memory monitoring submodule, used to obtain the allocation method and release method of the heap memory in the target device through the hook technology, and obtain the heap memory space data based on the allocation method and release method of the heap memory; and / or,
[0033] The virtual memory monitoring submodule is used to obtain the allocation method and release method of the virtual machine memory in the target device through the hook technology, and obtain the virtual memory space data based on the allocation method and release method of the virtual machine memory.
[0034] In a third aspect, an embodiment of the present invention further provides an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the memory overflow management method as described in the first aspect.
[0035] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, characterized in that a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the steps of the memory overflow management method described in the first aspect are implemented.
[0036] In the embodiment of the present invention, a specific analysis is performed by detecting the memory usage and periodically comparing it with the memory upper limit of the target device. The final conclusion of the analysis is used to determine whether OOM exists. If it exists, the stack information of the memory allocation at this time is collected and the OOM mark is recorded to perform memory analysis on the App with the OOM mark. This eliminates the need for manual memory analysis during the development phase, saves time in locating problems during demand development, saves development time, and improves development efficiency. It can accurately detect the beneficial effect of the problem of the system killing the App caused by OOM.
[0037] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented according to the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.
[0039] Figure 1 is a flowchart of the steps of a memory overflow management method in an embodiment of the present invention;
[0040] Figure 2 is a flowchart of another memory overflow management method in an embodiment of the present invention;
[0041] Figure 3 is a flow chart of a memory overflow management solution in an embodiment of the present invention;
[0042] Figure 4is a structural schematic diagram of a memory overflow management device in an embodiment of the present invention;
[0043] Figure 5 is a structural schematic diagram of another memory overflow management device in an embodiment of the present invention;
[0044] Figure 6 It is a schematic diagram of the hardware structure of an electronic device in an embodiment of the present invention. DETAILED DESCRIPTION
[0045] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0046] Reference Figure 1 , showing a step flow chart of a memory overflow management method in an embodiment of the present invention.
[0047] Step 110, obtaining memory space data used in real time in the target device and the memory upper limit of the target device, wherein the memory space data includes at least one of heap memory space data and virtual memory space data.
[0048] As mentioned above, the running stability of the App is a prerequisite for ensuring business development, and it is also a criterion for measuring whether an App is excellent. Moreover, the unstable factors of the App may include excessive memory usage, excessive CPU (Central Processing Unit / Processor) consumption, high power consumption, frequent crashes, etc., and the above unstable factors will cause the App to be killed. So how to monitor whether the App is killed by the system due to excessive memory usage, and avoid the subsequent corresponding App being killed due to the same reason? In an embodiment of the present invention, a strategy is provided to prevent the App from being killed by the system by detecting OOM (out of memory).
[0049] Among them, OOM is a common type of error, usually caused by too many open applications. In iOS, it can be divided into FOOM (Foreground Out Of Memory) and BOOM (Background Out Of Memory).
[0050] In the embodiment of the present invention, the memory space data opened by the stack in the target device is mainly monitored, and then the total opened memory space data is analyzed whether it reaches the highwater mark (memory upper limit) of the target device. If the distance between the memory space data and the memory upper limit is less than a preset value, that is, the memory space data is about to reach the memory upper limit, the data can be reported once and the called stack information can be retained.
[0051] Therefore, in order to facilitate memory overflow monitoring, the memory space data used in real time in the target device and the memory upper limit of the target device can be obtained, and the memory space data includes at least one of heap memory space data and virtual memory space data.
[0052] Among them, and in the embodiment of the present invention, the above-mentioned memory space data and the memory upper limit of the target device can be obtained by any available method, and the embodiment of the present invention does not limit this. For example, since the real-time memory space data used in the target device is changing, a timer can be turned on to periodically analyze and count the real-time memory usage of the target device to obtain the real-time memory space data used. For the same device, its memory upper limit is generally a fixed value, so it can be obtained once. Of course, according to the needs, it can also be set to periodically obtain the memory upper limit of the target device, and the embodiment of the present invention does not limit this.
[0053] In addition, in actual applications, during the running process of the App, any available memory space such as the heap memory and virtual memory of the target device may be occupied. Therefore, the memory space data in the embodiment of the present invention includes at least one of the heap memory space data and the virtual memory space data. Among them, the heap memory space data can characterize the real-time usage of the heap memory, and the virtual memory space data can characterize the real-time usage of the virtual memory. Among them, the heap memory (heap) is another memory area different from the stack area, the global data area and the code area. The heap allows the program to dynamically apply for a certain size of memory space at runtime. Virtual memory is also known as virtual memory. All programs running in the computer must be executed through the memory. If the executed program occupies a large or large amount of memory, it will cause the memory to be exhausted. To solve this problem, virtual memory technology is used in operating systems such as Windows, that is, a part of the hard disk space is allocated to serve as memory.
[0054] Step 120, when the distance between the memory space data and the memory upper limit is less than a preset value, record the stack information of the memory allocation, and set a memory overflow flag for the application running in the foreground of the target device.
[0055] If the distance between the currently acquired real-time memory space data and the memory upper limit is less than the preset value, that is, the memory space data is close to the memory upper limit, then the corresponding target device is at risk of memory overflow, or the application has been forcibly killed due to memory overflow. In order to facilitate the subsequent analysis of the cause of the memory overflow, the stack information of the current memory allocation can be recorded, and the memory overflow flag can be set for the application currently running in the foreground of the target device.
[0056] Among them, the stack information of memory allocation is also the above-mentioned call stack information. The stack information of memory allocation can record the function calls, variable calls, memory calls, instruction execution processes, and any other information related to memory allocation during the running process of each App running in the target device. That is, the stack information of memory allocation can record the memory allocation of the App during its running process.
[0057] Moreover, generally speaking, an application can be run at the same time in the foreground of the device, so the stack information of memory allocation recorded at this time generally includes the stack information of memory allocation of the App currently running in the foreground of the target device. Moreover, if the distance between the memory space data and the memory upper limit is less than the preset value, it can be characterized that the App currently running in the foreground of the target device occupies too much memory, making the target device at risk of memory overflow. Therefore, in order to identify the application that currently causes the memory overflow, a memory overflow (OOM) flag can be set for the application currently running in the foreground of the target device. Among them, the preset value can be customized according to the needs, and this embodiment of the present invention is not limited to this.
[0058] The specific form of the memory overflow indicator can be customized according to the needs, and the embodiment of the present invention does not limit this. Moreover, in the embodiment of the present invention, if the memory overflow monitoring is performed on the App running in the foreground, then the memory overflow indicator at this time can be the foreground memory overflow indicator, that is, the above-mentioned FOOM indicator; correspondingly, if the memory overflow monitoring is performed on the App running in the background, then the memory overflow indicator at this time can be the background memory overflow indicator, that is, the above-mentioned BOOM indicator, and the embodiment of the present invention does not limit this.
[0059] If the target device is set to have multiple apps running in the foreground, a memory overflow flag may be set for each application running in the foreground of the target device, which is not limited in this embodiment of the present invention.
[0060] Secondly, in the embodiment of the present invention, the stack information of memory allocation can be recorded locally on the target device, or recorded in a designated storage area, such as a cloud server, etc., and can be customized according to needs, which is not limited by the embodiment of the present invention.
[0061] Step 130: For each application program with a memory overflow flag set, perform memory analysis on the application program according to the stack information of the memory allocation.
[0062] In order to optimize the App and avoid memory overflow due to the same reason during subsequent use of the corresponding App, memory analysis can be performed on each application with a memory overflow flag set according to the stack information of the memory allocation.
[0063] In the embodiment of the present invention, the specific process of memory analysis can be customized according to the needs, and the embodiment of the present invention does not limit this. For example, for any application with a memory overflow flag set, the call operation that occupies the memory space data can be obtained according to the stack information of the memory allocation corresponding to the application, so as to provide an optimization solution for the corresponding application, and at the same time, the corresponding call operation can be optimized and improved to reduce the memory occupation of the corresponding application during operation.
[0064] Reference Figure 2 In the embodiment of the present invention, the method may further include:
[0065] Step 140: For the application program running in the foreground of the target device, if the application program receives a memory warning, the stack information of the memory allocation is recorded, and a memory overflow flag is set for the application program.
[0066] In actual applications, when the memory usage ratio of an App is too high, the corresponding App will also receive a memory warning issued by the system. At this time, the stack information of memory allocation can also be recorded, and a memory overflow flag can be set for the corresponding App. Among them, the triggering conditions for the application to receive a memory warning can be customized according to needs, and the triggering conditions for different applications to receive a memory warning can be different or completely the same, which is not limited by the present invention.
[0067] For example, you can set a single App to receive a memory warning when its running memory occupies half of the total running memory of the target device, and so on.
[0068] Optionally, in one embodiment, the step of recording the stack information of memory allocation and setting a memory overflow flag for the application running in the foreground of the target device may further include: recording the stack information of memory allocation in the storage space allocated locally for the application on the target device, and setting a memory overflow flag for the application.
[0069] In an embodiment of the present invention, in order to facilitate subsequent memory analysis of an application in a target device, the stack information of memory allocation can be recorded locally on the target device, and a memory overflow flag can also be set locally on the target device for the application. Specifically, the stack information of memory allocation can be recorded in the storage space allocated locally on the target device for the application running in the foreground, and a memory overflow flag can be set for the application.
[0070] like Figure 3 The flowchart of a memory overflow management scheme in an embodiment of the present invention is shown. It can be roughly divided into three steps. They are memory allocation monitoring, timing analysis, and reporting. In the memory allocation monitoring process, the memory allocation and memory release in the target device can be obtained by any available method such as hook technology, and then the real-time memory of the target device, that is, the memory space data used in real time, and the memory allocation information, that is, the stack information of the above-mentioned memory allocation, can be obtained by statistics. In the timing analysis process, the real-time memory space data can be periodically compared with the memory upper limit of the target device, and when the distance between the memory space data and the memory upper limit is less than a preset value, the reporting stage is entered, that is, the stack information of the memory allocation is recorded, and the memory overflow flag is set for the application running in the foreground of the target device to facilitate subsequent memory analysis. In addition, the stack information of the memory allocation and the memory overflow flag set for the application running in the foreground of the target device can also be reported to the designated storage area, which is not limited by the embodiment of the present invention.
[0071] Reference Figure 2 In one embodiment, step 130 may further include:
[0072] Step 131, for each application program with a memory overflow flag set, if the application program is killed, when the application program is cold-started again, stack information corresponding to the application program is locally obtained from the target device;
[0073] Step 132: Perform memory analysis on the application program according to the stack information of the memory allocation.
[0074] In actual applications, if the distance between the memory space data of the target device and the memory upper limit is less than a preset value, the application running in the foreground of the target device may be forcibly killed or may not be forcibly killed. Moreover, in order to perform memory analysis, it is necessary to obtain the stack information corresponding to the corresponding application, that is, the stack information of the above-mentioned memory allocation. In an embodiment of the present invention, in order to obtain the above-mentioned stack information, a channel specifically used to obtain the stack information and the memory overflow mark can be set up so as to read the memory overflow mark and the stack information for memory analysis. However, the way of setting the channel will increase the extra workload, and it may be necessary to set it up for different target devices, applications, etc., which increases the cost.
[0075] In the embodiment of the present invention, in order to reduce costs, when the application with the memory overflow flag is cold-started again, the stack information corresponding to the corresponding application can be obtained from the local target device. Among them, cold start refers to opening the App in this state after the App is killed by the background, and this startup method is called cold start; hot start: refers to opening the App again when the App is not killed by the background and is still running in the background, and this startup method is called hot start.
[0076] During the cold start process, the App can automatically read the local data related to the corresponding App on the target device. At this time, it can be determined whether there is a memory overflow mark for the App on the target device. If there is, it means that the App was killed last time due to memory overflow. Then, based on the locally recorded memory allocation stack information, memory analysis can be performed on the corresponding App.
[0077] Reference Figure 2 In one embodiment, step 110 may further include:
[0078] Step 111, obtaining the allocation method and release method of the heap memory in the target device through the hook technology, and obtaining the heap memory space data based on the allocation method and release method of the heap memory; and / or,
[0079] Step 112, obtaining the allocation method and release method of the virtual machine memory in the target device through the hook technology, and obtaining the virtual memory space data based on the allocation method and release method of the virtual machine memory.
[0080] In an embodiment of the present invention, in order to obtain the memory space data used in real time in the target device, the memory allocation method and release method in the target device can be obtained through the hook technology, and the real-time memory usage can be counted to obtain the memory space data. Among them, the Chinese translation of hook is "hook" or "hook". After hooking a specific system event, once the hooked event occurs, the program that hooks the event will receive a notification from the system, and the program can respond to the event in the first time.
[0081] Specifically, in order to obtain heap memory space data and virtual memory space data in the memory space data, the allocation method and release method of the heap memory in the target device can be obtained through the hook technology respectively, and based on the allocation method and release method of the heap memory, the heap memory space data can be obtained; and / or, the allocation method and release method of the virtual machine (Virtual Machine, VM) memory in the target device can be obtained through the hook technology, and based on the allocation method and release method of the virtual machine memory, the virtual memory space data can be obtained.
[0082] Among them, the method for allocating heap memory may include any method related to the allocation of heap memory, the method for releasing heap memory may include any method related to the release of heap memory, and the specific contents of the method for allocating heap memory and the method for releasing heap memory may also be customized according to the needs, which is not limited in the embodiments of the present invention. The method for allocating virtual machine memory may include any method related to the allocation of virtual machine memory, the method for releasing virtual machine memory may include any method related to the release of virtual machine memory, and the specific contents of the method for allocating virtual machine memory and the method for releasing virtual machine memory may also be customized according to the needs, which is not limited in the embodiments of the present invention.
[0083] In the embodiment of the present invention, a specific analysis is performed by detecting the memory usage and periodically comparing it with the high water mark of the target device. The final conclusion of the analysis is used to determine whether OOM exists. If so, the stack information of the memory allocation at this time is collected and the OOM mark is recorded. When a cold start is entered, it is determined whether there is a mark to determine whether the last exit of the App process was caused by the system being killed by OOM.
[0084] Moreover, in the embodiment of the present invention, there is no need to manually analyze the memory during the development phase, which saves time in locating problems during demand development, while saving development time and improving development efficiency. The problem of OOM causing the system to kill the App can be accurately detected, and memory allocation information can be collected to improve the efficiency of problem solving. At the same time, through OOM detection and memory analysis, the memory usage of the App can be optimized, the performance of the App can be optimized, and the survival time of the App in the foreground and background can be increased.
[0085] Reference Figure 4 , showing a structural schematic diagram of a memory overflow management device in an embodiment of the present invention.
[0086] The memory overflow management device of the embodiment of the present invention includes: a memory allocation monitoring module 210 , a timing analysis module 220 and a memory analysis module 230 .
[0087] The functions of each module and the interactions between them are introduced in detail below.
[0088] A memory allocation monitoring module 210 is used to obtain the memory space data used in real time in the target device and the memory upper limit of the target device, wherein the memory space data includes at least one of heap memory space data and virtual memory space data;
[0089] The timing analysis module 220 is used to record the stack information of the memory allocation when the distance between the memory space data and the memory upper limit is less than a preset value, and set a memory overflow flag for the application running in the foreground of the target device;
[0090] The memory analysis module 230 is used to perform memory analysis on each application program with a memory overflow flag set according to the stack information of the memory allocation.
[0091] Reference Figure 5 In an embodiment of the present invention, the device further includes:
[0092] The memory warning processing module 240 is used for recording the stack information of memory allocation for the application running in the foreground of the target device if the application receives a memory warning, and setting a memory overflow flag for the application.
[0093] Optionally, in the embodiment of the present invention, the timing analysis module 220 is further used to: record the stack information of memory allocation in the storage space locally allocated for the application on the target device, and set a memory overflow flag for the application.
[0094] Reference Figure 5In this embodiment of the present invention, the memory analysis module 230 includes:
[0095] The memory allocation information acquisition submodule 231 is used for acquiring the stack information corresponding to each application program with a memory overflow flag set therein from the local device of the target device when the application program is cold-started again if the application program is killed;
[0096] The memory analysis submodule 232 is used to perform memory analysis on the application program according to the stack information of the memory allocation.
[0097] Reference Figure 5 In this embodiment of the present invention, the memory allocation monitoring module 210 includes:
[0098] The heap memory monitoring submodule 211 is used to obtain the allocation method and release method of the heap memory in the target device through the hook technology, and obtain the heap memory space data based on the allocation method and release method of the heap memory; and / or,
[0099] The virtual memory monitoring submodule 212 is used to obtain the allocation method and release method of the virtual machine memory in the target device through the hook technology, and obtain the virtual memory space data based on the allocation method and release method of the virtual machine memory.
[0100] The memory overflow management device provided by the embodiment of the present invention can achieve Figure 1 to Figure 2 To avoid repetition, the various processes implemented in the method embodiment are not described here.
[0101] Preferably, an embodiment of the present invention also provides an electronic device, comprising: a processor, a memory, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, the various processes of the above-mentioned memory overflow management method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be described here.
[0102] The embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, each process of the above-mentioned memory overflow management method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it is not repeated here. The computer-readable storage medium is, for example, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0103] Figure 6 A schematic diagram of the hardware structure of an electronic device for implementing various embodiments of the present invention.
[0104] The electronic device 500 includes but is not limited to: a radio frequency unit 501, a network module 502, an audio output unit 503, an input unit 504, a sensor 505, a display unit 506, a user input unit 507, an interface unit 508, a memory 509, a processor 510, and a power supply 511. Those skilled in the art will appreciate that Figure 6 The electronic device structure shown in the figure does not constitute a limitation on the electronic device, and the electronic device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently. In the embodiments of the present invention, the electronic device includes but is not limited to a mobile phone, a tablet computer, a laptop computer, a PDA, a vehicle-mounted terminal, a wearable device, and a pedometer.
[0105] It should be understood that in the embodiment of the present invention, the radio frequency unit 501 can be used for receiving and sending signals during information transmission or communication. Specifically, after receiving downlink data from the base station, it is sent to the processor 510 for processing; in addition, uplink data is sent to the base station. Generally, the radio frequency unit 501 includes but is not limited to an antenna, at least one amplifier, a transceiver, a coupler, a low noise amplifier, a duplexer, etc. In addition, the radio frequency unit 501 can also communicate with the network and other devices through a wireless communication system.
[0106] The electronic device provides users with wireless broadband Internet access through the network module 502, such as helping users to send and receive emails, browse web pages, and access streaming media.
[0107] The audio output unit 503 can convert the audio data received by the RF unit 501 or the network module 502 or stored in the memory 509 into an audio signal and output it as sound. Moreover, the audio output unit 503 can also provide audio output related to a specific function performed by the electronic device 500 (for example, a call signal reception sound, a message reception sound, etc.). The audio output unit 503 includes a speaker, a buzzer, a receiver, etc.
[0108] The input unit 504 is used to receive audio or video signals. The input unit 504 may include a graphics processor (GPU) 5041 and a microphone 5042. The graphics processor 5041 processes the image data of a static picture or video obtained by an image capture device (such as a camera) in a video capture mode or an image capture mode. The processed image frame can be displayed on the display unit 506. The image frame processed by the graphics processor 5041 can be stored in the memory 509 (or other storage medium) or sent via the radio frequency unit 501 or the network module 502. The microphone 5042 can receive sound and can process such sound into audio data. The processed audio data can be converted into a format output that can be sent to a mobile communication base station via the radio frequency unit 501 in the case of a telephone call mode.
[0109] The electronic device 500 also includes at least one sensor 505, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor includes an ambient light sensor and a proximity sensor, wherein the ambient light sensor can adjust the brightness of the display panel 5061 according to the brightness of the ambient light, and the proximity sensor can turn off the display panel 5061 and / or the backlight when the electronic device 500 is moved to the ear. As a type of motion sensor, the accelerometer sensor can detect the magnitude of acceleration in each direction (generally three axes), and can detect the magnitude and direction of gravity when stationary, which can be used to identify the posture of the electronic device (such as horizontal and vertical screen switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometer, tapping), etc.; the sensor 505 can also include a fingerprint sensor, a pressure sensor, an iris sensor, a molecular sensor, a gyroscope, a barometer, a hygrometer, a thermometer, an infrared sensor, etc., which will not be repeated here.
[0110] The display unit 506 is used to display information input by the user or information provided to the user. The display unit 506 may include a display panel 5061, which may be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), or the like.
[0111] The user input unit 507 can be used to receive input digital or character information, and to generate key signal input related to user settings and function control of the electronic device. Specifically, the user input unit 507 includes a touch panel 5071 and other input devices 5072. The touch panel 5071, also known as a touch screen, can collect the user's touch operation on or near it (such as the user's operation on the touch panel 5071 or near the touch panel 5071 using any suitable object or accessory such as a finger, stylus, etc.). The touch panel 5071 may include two parts: a touch detection device and a touch controller. Among them, the touch detection device detects the user's touch orientation, detects the signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, converts it into the contact point coordinates, and then sends it to the processor 510, receives the command sent by the processor 510 and executes it. In addition, the touch panel 5071 can be implemented using multiple types such as resistive, capacitive, infrared and surface acoustic waves. In addition to the touch panel 5071, the user input unit 507 may also include other input devices 5072. Specifically, other input devices 5072 may include but are not limited to a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, and a joystick, which are not described in detail here.
[0112] Furthermore, the touch panel 5071 may be overlaid on the display panel 5061. When the touch panel 5071 detects a touch operation on or near it, it transmits the information to the processor 510 to determine the type of the touch event. Then, the processor 510 provides a corresponding visual output on the display panel 5061 according to the type of the touch event. Figure 6 In the figure, the touch panel 5071 and the display panel 5061 are used as two independent components to realize the input and output functions of the electronic device. However, in some embodiments, the touch panel 5071 and the display panel 5061 can be integrated to realize the input and output functions of the electronic device, which is not limited here.
[0113] The interface unit 508 is an interface for connecting an external device to the electronic device 500. For example, the external device may include a wired or wireless headset port, an external power supply (or battery charger) port, a wired or wireless data port, a memory card port, a port for connecting a device with an identification module, an audio input / output (I / O) port, a video I / O port, a headphone port, etc. The interface unit 508 may be used to receive input (e.g., data information, power, etc.) from an external device and transmit the received input to one or more elements within the electronic device 500 or may be used to transmit data between the electronic device 500 and an external device.
[0114] The memory 509 can be used to store software programs and various data. The memory 509 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the mobile phone (such as audio data, a phone book, etc.), etc. In addition, the memory 509 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0115] The processor 510 is the control center of the electronic device. It uses various interfaces and lines to connect various parts of the entire electronic device. By running or executing software programs and / or modules stored in the memory 509 and calling data stored in the memory 509, it performs various functions of the electronic device and processes data, thereby monitoring the electronic device as a whole. The processor 510 may include one or more processing units; preferably, the processor 510 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 510.
[0116] The electronic device 500 may also include a power supply 511 (such as a battery) for supplying power to each component. Preferably, the power supply 511 may be logically connected to the processor 510 through a power management system, thereby implementing functions such as charging, discharging, and power consumption management through the power management system.
[0117] In addition, the electronic device 500 includes some functional modules not shown, which will not be described in detail here.
[0118] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0119] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0120] The embodiments of the present invention are described above in conjunction with the accompanying drawings, but the present invention is not limited to the above-mentioned specific implementation modes, which are merely illustrative rather than restrictive. Under the guidance of the present invention, ordinary technicians in this field can also make many forms without departing from the scope of protection of the present invention and the claims, all of which are within the protection of the present invention.
[0121] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed in the embodiments of the present invention can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0122] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0123] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0124] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0125] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0126] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as USB flash drives, mobile hard disks, ROM, RAM, magnetic disks, or optical disks.
[0127] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A memory overflow management method, characterized in that: include: Acquire memory space data used in real time in a target device and a memory upper limit of the target device, wherein the memory space data includes at least one of heap memory space data and virtual memory space data; When the distance between the memory space data and the memory upper limit is less than a preset value, the stack information of the memory allocation is recorded, and a memory overflow flag is set for the application program running in the foreground of the target device; For an application running in the foreground of the target device, if the application receives a memory warning, stack information of memory allocation is recorded, and a memory overflow flag is set for the application; For each application program with a memory overflow flag set, a memory analysis is performed on the application program according to the stack information of the memory allocation.
2. The method according to claim 1, characterized in that The step of recording the stack information of memory allocation and setting a memory overflow flag for the application running in the foreground of the target device includes: In the storage space locally allocated for the application program on the target device, stack information of memory allocation is recorded, and a memory overflow flag is set for the application program.
3. The method according to any one of claims 2, characterized in that The step of performing memory analysis on each application program with a memory overflow flag set according to the stack information of the memory allocation comprises: For each application program with a memory overflow flag set, if the application program is killed, when the application program is cold-started again, stack information corresponding to the application program is locally obtained from the target device; Memory analysis is performed on the application program according to the stack information of the memory allocation.
4. The method according to claim 1, characterized in that The step of obtaining the memory space data used in real time in the target device includes: Acquire the allocation method and release method of the heap memory in the target device through the hook technology, and acquire the heap memory space data based on the allocation method and release method of the heap memory; And / or, obtaining the allocation method and release method of the virtual machine memory in the target device through the hook technology, and obtaining the virtual memory space data based on the allocation method and release method of the virtual machine memory.
5. A memory overflow management device, characterized in that: include: A memory allocation monitoring module, used to obtain the memory space data used in real time in the target device and the memory upper limit of the target device, wherein the memory space data includes at least one of heap memory space data and virtual memory space data; A timing analysis module, configured to record the stack information of memory allocation and set a memory overflow flag for the application program running in the foreground of the target device when the distance between the memory space data and the memory upper limit is less than a preset value; A memory warning processing module, for an application running in the foreground of the target device, if the application receives a memory warning, records the stack information of memory allocation, and sets a memory overflow flag for the application; The memory analysis module is used to perform memory analysis on each application program with a memory overflow flag set according to the stack information of the memory allocation.
6. The device according to claim 5, characterized in that The timing analysis module is further used for: In the storage space locally allocated for the application program on the target device, stack information of memory allocation is recorded, and a memory overflow flag is set for the application program.
7. The device according to any one of claims 6, characterized in that The memory analysis module includes: A memory allocation information acquisition submodule is used to obtain stack information corresponding to each application program set with a memory overflow flag from the target device locally when the application program is cold-started again if the application program is killed; The memory analysis submodule is used to perform memory analysis on the application program according to the stack information of the memory allocation.
8. The device according to claim 5, characterized in that The memory allocation monitoring module comprises: A heap memory monitoring submodule, used to obtain the allocation method and release method of the heap memory in the target device through the hook technology, and obtain the heap memory space data based on the allocation method and release method of the heap memory; and / or, The virtual memory monitoring submodule is used to obtain the allocation method and release method of the virtual machine memory in the target device through the hook technology, and obtain the virtual memory space data based on the allocation method and release method of the virtual machine memory.
9. An electronic device, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the memory overflow management method according to any one of claims 1 to 4.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the memory overflow management method according to any one of claims 1 to 4 are implemented.
Citation Information
Patent Citations
Memory allocation method, mobile terminal and computer-readable storage medium
CN107357656A
Application program processing method, terminal, and computer readable storage medium
CN109542689A
Memory monitoring method and device, terminal and storage medium
CN109656779A
Stack memory allocation method and device, equipment and storage medium
CN110618946A
Application memory monitoring method and device, equipment and storage medium
CN110633190A
