Application management method and electronic device
By monitoring and analyzing the application's graphics buffer allocation results, if virtual memory usage exceeds a threshold, the application process is automatically terminated, resolving system crashes and freezes caused by memory leaks and improving the user experience.
Patent Information
- Application Number
- CN202211578199.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-30
- Publication Date
- 2026-11-20
- Estimated Expiration
- 2041-09-30
AI Technical Summary
Memory leaks can cause system crashes and application anomalies that are difficult to detect and locate, leading to serious consequences such as memory overflows and system crashes.
By monitoring the application's graphics buffer allocation results and analyzing the failure types, if virtual memory usage exceeds the threshold, the self-destruct recovery function is activated to terminate the application process to release memory and avoid memory leaks.
This effectively avoids system crashes and freezes caused by memory leaks, improves user experience, and reduces the impact on users.
Smart Images

Figure CN116107922B_ABST
Abstract
Description
[0001] This application is a divisional application. The original application has the application number 202111157747.4 and the application date is September 30, 2021. The entire contents of the original application are incorporated herein by reference. Technical Field
[0002] This application relates to the field of electronics, and more particularly to a method for managing an application and an electronic device. Background Technology
[0003] A memory leak refers to the phenomenon where dynamically allocated heap memory in an application is not released or cannot be released in a timely manner for some reason, resulting in a waste of system memory.
[0004] However, since memory leaks are not considered fault-based errors, they are currently difficult to detect and locate, which can ultimately lead to serious consequences such as memory overflow, abnormal application operation, or even system crashes. Summary of the Invention
[0005] This application provides a method for managing applications that can avoid system crashes caused by memory leaks.
[0006] In a first aspect, an application management method is provided, comprising: monitoring the application request result of a graphics buffer during application operation; if the application request result is a failure, analyzing the failure type based on the request result; if the failure type is a memory mapping failure, obtaining the application's virtual memory usage; and if the virtual memory used by the application exceeds a preset threshold, activating the application's self-destruct recovery function.
[0007] During application execution, in order to draw the interface and save the drawn data, the running process requests a graphics buffer from the system memory.
[0008] For example, a graphics buffer shared between processes can be requested through the graphicbuffermapper, or a graphics buffer used by the application can be requested through the graphicbufferallocator process interface.
[0009] Since memory leaks may occur when requesting a graphics buffer from the memory manager, a memory allocation monitoring function can be enabled when the application process initiates a graphics buffer request to monitor the allocation result.
[0010] It should be noted that the memory allocation monitoring function can also be started when the application starts running, and the application's virtual memory usage can be obtained in real time. When the application's virtual memory usage exceeds a certain value (this value can be set according to the actual application scenario, and this application does not impose any restrictions on it), the memory allocation monitoring function can be started. Alternatively, the memory allocation monitoring function can be started only when the application's virtual memory usage exceeds a certain value and the application's process initiates a graphics buffer request. Of course, the memory allocation monitoring function can also be started under other circumstances.
[0011] For example, enabling memory allocation monitoring can include: the user actively enabling the memory allocation monitoring function, the electronic device automatically enabling the memory allocation monitoring function, and the default enabling of the memory allocation monitoring function.
[0012] The results of the above graphics buffer application include successful application and application failure.
[0013] The memory manager will return a successful request when the system has sufficient available memory to satisfy the request and the requested memory can be mapped to the address of the process's virtual memory.
[0014] The memory manager will return a failure result when there is insufficient available system memory (the memory occupied by the requested graphics buffer is greater than the available system memory), the requested memory cannot be mapped to the address of the process's virtual memory, or other abnormal situations.
[0015] The virtual memory usage of an application can be checked using the ` / proc / self / status` function.
[0016] The preset threshold can be set according to the application. For example, for a 32-bit application, the preset threshold can be set to 3.7G. Of course, for a 32-bit application, the preset threshold can be set to a value lower than 3.7G, such as 3.5G or 3.2G.
[0017] As can be seen from the above, by monitoring the application process's request for graphics buffers from the system memory, if the memory request fails due to excessive virtual memory usage, the self-destruct recovery function is activated to release the memory occupied by the application, thereby avoiding serious consequences such as system crashes and freezes caused by memory leaks and reducing the impact on user experience.
[0018] In one possible implementation of the first aspect, the above-mentioned "if the virtual memory occupied by the application exceeds a preset threshold, then start the suicide recovery function" includes: when the virtual memory occupied by the application exceeds the preset threshold, terminating all processes of the application.
[0019] When an application's virtual memory usage exceeds a preset threshold, a command can be sent to the process manager to terminate all processes of the application. In response to this command, the process manager will terminate all processes of the application and release the system memory occupied by the application.
[0020] The Task Manager displays all currently running processes on the system. By ending all processes associated with the application's name using the Task Manager, you can release the system memory occupied by that application.
[0021] The aforementioned automatic application termination can involve directly ending all processes of the application. In this case, the electronic device's display will immediately jump to the device's home screen, meaning the user will experience the application crashing. Directly ending all processes of the application releases all the memory it occupies, preventing serious consequences such as system crashes and freezes caused by memory leaks.
[0022] In one possible implementation of the first aspect, the above-mentioned "if the virtual memory occupied by the application exceeds a preset threshold, the suicide recovery function is activated" includes: when the virtual memory occupied by the application exceeds the preset threshold, determining whether the process requesting the graphics buffer is the main process of the application.
[0023] If the process requesting the graphics buffer is not the main process of the application, then terminate all processes of the application and restart the main process of the application; otherwise, terminate all processes of the application.
[0024] If the process requesting the graphics buffer is the main process of the application, then the interface displayed on the electronic device will be the main display interface of the application. Therefore, after all processes of the application are terminated, the main process of the application will be automatically restarted, and the display interface of the electronic device will jump directly to the main display interface of the application.
[0025] Because the interval between ending and restarting the application's main process is very short, the user is unaware of this; they only perceive the electronic device's display returning to the application's main screen. In this way, the user doesn't experience an application crash, thus freeing up system memory occupied by the application while avoiding impacting user experience and improving overall user satisfaction.
[0026] In one possible implementation of the first aspect, after monitoring the allocation result of the graphics buffer during application execution, the method further includes:
[0027] If the graphics buffer allocation is successful, the allocated memory will be mapped to the address of the process's virtual memory.
[0028] After the graphics buffer is successfully requested (i.e., the system allocates memory to the process), the graphics buffer needs to be mapped to the address space of the virtual memory corresponding to the process before the process can display and draw the interface.
[0029] In one possible implementation of the first aspect, the management method of the above application further includes: if the failure type is not memory mapping failure, then outputting an exception log corresponding to the failure type.
[0030] The failure types when the above application fails can include insufficient available system memory, memory mapping failure, other abnormal situations, etc., which are not limited here.
[0031] In some embodiments, the electronic device can determine the failure type based on the allocation result returned by the memory manager. For example, the failure type can be determined by analyzing the binary representation of the allocation result.
[0032] For example, when the application result includes two fields, where the first field indicates whether the application was successful and the second field indicates the failure type, the encoding of the second field can be read, and the memory application result can be determined based on the encoding of the second field.
[0033] For example, if the application result is "01, 001", then the content of the second field, "001", is read. Based on the pre-determined meaning of this code, the failure type is insufficient available system memory. As another example, if the application result is "01, 010", then the content of the second field is read as "010". Based on the pre-determined meaning of this code, the failure type is memory mapping failure.
[0034] For example, when the application result contains only one field, where the second to fourth bits of the field are used to indicate the failure type, the encoding of the second to fourth bits is read, and the application result of the memory application is determined based on the encoding of the second to fourth bits.
[0035] For example, if the request result is "1001", then the second to fourth bits of the code "001" are read. Based on the pre-determined meaning of this code, the failure type is insufficient available system memory. As another example, if the request result is "1010", then the second to fourth bits of the code "010" are read. Based on the pre-determined meaning of this code, the failure type is memory mapping failure.
[0036] For example, when the application result is returned as an error with an error code, the failure type can be determined by the error code.
[0037] Since the failure type is not memory mapping failure, it is unlikely to cause a memory leak. Therefore, no action needs to be taken on the application; simply output the exception log corresponding to this failure type.
[0038] In some embodiments, the aforementioned exception log may include the name of the process that initiated the request, the time of the exception, and the content of the exception. The content of the exception includes the failure to request a graphics buffer and the failure type. For example, when the failure type is insufficient system available memory, the aforementioned exception content may be: Process B of application A failed to request a graphics buffer at xx time due to insufficient system memory.
[0039] In some embodiments, when the failure type is insufficient system memory, the electronic device can initiate the LMK mechanism based on the exception log.
[0040] In some embodiments, the aforementioned exception logs can be stored in a log manager, and electronic devices can read the exception logs through the log manager.
[0041] In one possible implementation of the first aspect, the above application management method further includes: if the virtual memory occupied by the application does not exceed a preset threshold, then outputting an exception log indicating that memory mapping failed and virtual memory did not exceed the threshold.
[0042] Since the virtual memory used by the application does not exceed the preset threshold, meaning this will not cause a memory leak, no action needs to be taken on the application. Only an exception log should be output indicating that memory mapping failed and virtual memory did not exceed the threshold.
[0043] In one possible implementation of the first aspect, the above-mentioned application management method further includes: after terminating all processes of the application, outputting an exception log indicating that the application has terminated due to excessive virtual memory usage.
[0044] The exception log records the abnormal situation where the application terminates due to excessive virtual memory usage, making it easy for users to view.
[0045] Secondly, embodiments of this application provide an electronic device, including:
[0046] The monitoring module is used to monitor the allocation results of the graphics buffer during application execution;
[0047] The analysis module is used to analyze the failure type based on the application result if the application for the image buffer fails.
[0048] The acquisition module is used to obtain the application's virtual memory usage if the failure type is memory mapping failure;
[0049] The suicide recovery module is used to activate the suicide recovery function of an application if the virtual memory occupied by the application exceeds a preset threshold.
[0050] Thirdly, embodiments of this application provide an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the method as described in any of the first aspects above.
[0051] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program that, when executed by a processor, implements the method described in any of the first aspects above.
[0052] Fifthly, embodiments of this application provide a chip system including a processor coupled to a memory. The processor executes a computer program stored in the memory to implement the method described in any of the first aspects above. The chip system may be a single chip or a chip module composed of multiple chips.
[0053] In a sixth aspect, embodiments of this application provide a computer program product that, when run on an electronic device, causes the electronic device to perform the method described in any of the first aspects above.
[0054] It is understood that the beneficial effects of the second to sixth aspects mentioned above can be found in the relevant descriptions in the first aspect mentioned above, and will not be repeated here. Attached Figure Description
[0055] Figure 1 This is an exemplary diagram illustrating how a memory leak causes an application to display abnormally, as provided in an embodiment of this application.
[0056] Figure 2 This is a schematic diagram of the hardware structure of a mobile phone provided in an embodiment of this application.
[0057] Figure 3 This is a schematic diagram of a mobile phone software system architecture provided in an embodiment of this application.
[0058] Figure 4 These are schematic diagrams of graphical user interfaces in some application scenarios provided in the embodiments of this application.
[0059] Figure 5 This is a schematic diagram of a graphical user interface during the process of enabling the memory allocation monitoring function provided in the embodiments of this application.
[0060] Figure 6 This is a schematic diagram illustrating the implementation process of an application management method provided in an embodiment of this application.
[0061] Figure 7 This is a schematic diagram illustrating the implementation process of another application management method provided in this application embodiment. Detailed Implementation
[0062] It should be noted that the terminology used in the implementation section of the embodiments of this application is only used to explain the specific embodiments of this application and is not intended to limit this application. In the description of the embodiments of this application, unless otherwise stated, " / " means "or", for example, A / B can mean A or B; "and / or" in this document is merely a description of the relationship between related items, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. In addition, in the description of the embodiments of this application, unless otherwise stated, "multiple" means two or more, "at least one" or "one or more" means one, two or more.
[0063] Hereinafter, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature.
[0064] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.
[0065] To better understand the embodiments of this application, the following describes the terms or concepts that may be involved in the embodiments.
[0066] 1. Graphics buffer
[0067] Graphics buffers are used for displaying and drawing the application's user interface and storing the data. During application runtime, a graphics buffer is needed to allocate this data. This buffer can be allocated from system memory. After allocation, it needs to be mapped into the application's virtual memory address space for proper operation. For multi-process applications, each process requests a graphics buffer upon runtime. Similarly, after successful allocation (meaning sufficient system memory is available for the process), the buffer needs to be mapped into the process's virtual memory address space for normal operation.
[0068] 2. Garbage collection (GC) mechanism
[0069] Garbage collection (GC) is a mechanism that cleans up and reclaims unused objects to free up memory. When an application lags or becomes slow (because memory usage is too high—for example, for a 32-bit application, memory usage exceeding 3GB is considered too high), the virtual machine will trigger GC.
[0070] 3. Low memory killer (LMK) mechanism
[0071] This is an Android system memory cleanup mechanism. The system periodically monitors application memory usage. When available system memory is low, it triggers the LMK (Memory Kill) mechanism to kill low-priority processes in the background to free up memory. Specifically, the process priority is determined by its oom_adj value. The smaller the oom_adj value, the higher the priority, and the less likely the process is to be killed when the LMK mechanism is triggered. It should be noted that the oom_adj value of a foreground process is 0, meaning the foreground process has the highest priority.
[0072] 4. Virtual Memory (VSS)
[0073] The size of all memory addresses that a process can access. Theoretically, for a 32-bit application, the maximum amount of virtual memory that can be used is 2^32. 32 That is, 4G. In actual applications, the system will reserve a small portion of the virtual memory, so for a 32-bit application, the maximum amount of virtual memory that can be used is 3.7G. Exceeding 3.7G will cause a memory overflow.
[0074] 5. Out of memory (OOM)
[0075] The system contains unrecoverable memory or uses too much memory, which eventually causes the application to require more memory than the maximum available memory. Memory overflow manifests as abnormal display of the application interface or application crashes.
[0076] In software systems, improper use of resources such as images, objects, threads, files, and views, leading to a failure to release resources in a timely manner, can cause memory leaks. This can then trigger application memory overflow, causing the application to freeze or even the entire system to crash. Memory leaks are mostly an accumulative process, often without warning before problems occur, making them difficult to detect and locate.
[0077] In practical applications, memory leaks can lead to the following situations:
[0078] 1. When an application lags or responds slowly, it triggers the garbage collection mechanism, causing the application to become unresponsive (ANR) or crash.
[0079] 2. Causes abnormal application display, partial unavailability of application functions, and other abnormalities.
[0080] For example, Figure 1 (a) in the diagram is a schematic of the display interface of application A when there is no memory leak, such as... Figure 1 As shown in (b), the display anomaly that occurs when application A experiences a memory leak can manifest as garbled characters; for example... Figure 1 As shown in (c), the display anomaly that occurs when application A experiences a memory leak can manifest as incomplete display; for example... Figure 1 As shown in (d), when the above application A experiences a memory leak, the display anomaly can manifest as some functions not being displayed, at which point those functions are in an unusable abnormal state.
[0081] 3. System crashes, freezes, and other anomalies.
[0082] For example, when a user watches a video on their phone, the video playback application continuously requests and doesn't release memory during playback. Since the maximum virtual memory a video playback application can use is limited, once the application reaches its virtual memory limit, it cannot map the requested memory into its virtual memory. Simultaneously, the system-allocated memory is marked as used and cannot be allocated to other applications (processes). This memory mapping failure causes the application to continue requesting memory from the system, leading to a memory leak. Because the system's available memory is low, the LMK (Memory Kill) mechanism is triggered. However, since the video playback application is still running in the foreground, its priority is high, and it won't be killed. Therefore, the memory it occupies won't be released, ultimately causing the entire system to crash and freeze. When the system crashes and freezes, the user needs to force-restart the phone to restore normal use, which is cumbersome and negatively impacts the user experience.
[0083] In practical applications, many applications are 32-bit. When requesting system memory, these applications repeatedly call the `graphicbufferallocator` process interface. A 32-bit application can only use a maximum of 4GB of virtual memory. However, because the `graphicbufferallocator` process is 64-bit, even when the application's virtual memory exceeds 4GB, it can still successfully request system memory. Since the application's virtual memory has exceeded 4GB, it cannot map the requested memory into virtual memory, resulting in allocated but unusable and unreleased system memory. Furthermore, after memory mapping fails, the application continues to call the `graphicbufferallocator` interface to request memory, leading to continuous memory leaks and ultimately causing system crashes and freezes.
[0084] As explained above, once a memory leak occurs, it can cause a variety of problems and is difficult to reproduce. This means that memory leaks are difficult to detect and resolve, and they can severely impact user experience. Therefore, if applications that may cause memory leaks can be addressed before they lead to abnormal situations, serious anomalies such as system crashes and freezes can be avoided, mitigating the impact on users.
[0085] To address the aforementioned issues and user needs, this application provides an application management method. By monitoring the application's processes requesting graphics buffers from the system memory, and in cases where memory request fails due to excessive virtual memory usage, a self-destruct recovery function is activated to terminate all processes of the application, thereby releasing the memory occupied by the application and preventing serious consequences such as system crashes and freezes caused by memory leaks, thus mitigating the impact on user experience.
[0086] The application management method provided in the embodiments of this application will be described in detail below with reference to the accompanying drawings. In the following description, specific details such as specific system structures and technologies are presented for illustration rather than limitation, so as to provide a thorough understanding of the embodiments of this application.
[0087] The entity executing the management method of the above application can be an electronic device, such as a mobile phone, wearable device (such as a smartwatch, smart bracelet, smart glasses, smart jewelry, etc.), tablet computer, in-vehicle device, augmented reality (AR) / virtual reality (VR) device, laptop computer, ultra-mobile personal computer (UMPC), netbook, personal digital assistant (PDA), and other electronic devices with network connectivity.
[0088] Exemplary embodiments of the above-described electronic devices include, but are not limited to, those equipped with Devices running Harmony OS or other operating systems. The aforementioned electronic devices can also be other electronic devices, such as laptops with touch-sensitive surfaces (e.g., touch panels), etc. This application does not limit the specific type of electronic device.
[0089] Taking the aforementioned electronic device as a mobile phone as an example, such as Figure 2 The diagram shown is a structural schematic of a mobile phone provided in an embodiment of this application.
[0090] Figure 2A schematic diagram of the structure of mobile phone 100 is shown. Mobile phone 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 11, an antenna 12, a mobile communication module 150, a wireless communication module 160, an audio module 170, a sensor module 180, buttons 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, a barometric pressure sensor 180C, a magnetic sensor 180D, an accelerometer sensor 180E, a distance sensor 180F, a proximity sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0091] It is understood that the structures illustrated in the embodiments of the present invention do not constitute a specific limitation on the mobile phone 100. In other embodiments of this application, the mobile phone 100 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0092] Processor 110 may include one or more processing units, such as: application processor (AP), modem processor, graphics processing unit (GPU), image signal processor (ISP), controller, memory, video codec, digital signal processor (DSP), baseband processor, and / or neural network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0093] The controller can serve as the central nervous system and command center of the mobile phone 100. Based on the instruction operation code and timing signals, the controller generates operation control signals to control the fetching and execution of instructions.
[0094] The processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. This memory can store instructions or data that the processor 110 has just used or that are used repeatedly. If the processor 110 needs to use the instruction or data again, it can retrieve it directly from the memory. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0095] For example, the software system of mobile phone 100 can adopt a layered architecture, event-driven architecture, microkernel architecture, microservice architecture, or cloud architecture. This embodiment of the invention uses the layered architecture Android system as an example to illustrate the software structure of mobile phone 100. Figure 3 This is a software structure block diagram of the mobile phone 100 according to an embodiment of this application.
[0096] A layered architecture divides software into several layers, each with a clear role and function. Layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom: the application layer, the application framework layer, the Android runtime and system libraries, and the kernel layer.
[0097] The application layer can include a series of application packages. For example... Figure 3 As shown, the application package may include applications such as camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, video, and instant messaging.
[0098] The application framework layer provides application programming interfaces (APIs) and a programming framework for applications in the application layer. The application framework layer includes some predefined functions. For example... Figure 3 As shown, the application framework layer may include a window manager, content provider, view system, process manager, notification manager, suicide recovery management module, etc.
[0099] The window manager is used to manage windowed applications. It can retrieve screen size, determine the presence of a status bar, lock the screen, and capture screenshots, among other things.
[0100] Content providers store and retrieve data, making that data accessible to applications. This data may include videos, images, audio, made and received phone calls, browsing history and bookmarks, phone books, etc.
[0101] A view system includes visual controls, such as controls for displaying text and controls for displaying images. View systems can be used to build applications. A display interface can consist of one or more views. For example, a display interface including a text notification icon could include views for displaying text and views for displaying images.
[0102] The file explorer provides applications with various resources, such as localized strings, icons, images, layout files, video files, and more.
[0103] The notification manager allows applications to display notifications in the status bar. These can be used to convey informational messages and can disappear automatically after a short pause, requiring no user interaction. For example, the notification manager can be used to notify users of download completion or message alerts. The notification manager can also display notifications as icons or scrolling text in the top status bar, such as notifications from background applications, or as dialog boxes on the screen. Examples include displaying text messages in the status bar, emitting sounds, vibrating the device, or flashing indicator lights.
[0104] The suicide recovery management module is an application management mechanism that automatically kills an application to release memory when it detects that the running application meets the suicide recovery conditions mentioned in the embodiments of this application.
[0105] In this embodiment, the aforementioned suicide recovery condition may be a memory allocation failure, the failure type being a virtual memory mapping failure, and the virtual memory occupied by the application exceeding a preset threshold.
[0106] In this embodiment, the automatic killing of the application can be achieved by directly terminating all processes of the application. In this case, the display interface of the phone 100 will directly jump to the main screen of the phone 100, meaning the user will perceive the application crashing. Alternatively, the automatic killing of the application can be achieved by automatically restarting the main process of the application after terminating all processes. In this case, the display interface of the phone 100 will directly jump to the main display interface of the application. Since the interval between terminating the application's processes and restarting its main process is very short, the user will not perceive this and will only perceive that the display interface of the phone 100 jumps back to the main display interface of the application.
[0107] In some embodiments of this application, the suicide recovery management module also has a memory request monitoring function, which can automatically enable the memory request monitoring function when the application makes a memory request to the system memory, so as to monitor whether the memory request is successful.
[0108] The Android Runtime consists of core libraries and a virtual machine. The Android runtime is responsible for scheduling and managing the Android system.
[0109] The core library consists of two parts: one part is the functionalities that need to be called by the Java language, and the other part is the Android core library.
[0110] The application layer and application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and application framework layer as binary files. The virtual machine is used to perform functions such as target lifecycle management, stack management, thread management, security and exception management, and garbage collection.
[0111] System libraries can include multiple functional modules. For example: surface manager, media libraries, 3D graphics processing libraries (e.g., OpenGL ES), 2D graphics engines (e.g., SGL), etc.
[0112] The kernel layer is the layer between hardware and software. The kernel layer contains at least the display driver, camera driver, audio driver, and sensor driver.
[0113] The application management method provided in this application embodiment can run at the application framework layer, that is, the above application management method can be implemented through the suicide recovery management module in the application framework layer.
[0114] The application management method provided in this application can be applied to various usage scenarios where memory leaks exist. For example, the application management method provided in this application can be applied to scenarios where users watch videos on electronic devices or view pushed articles using instant messaging software.
[0115] For example, when a user views a push notification article (such as a news article or video) using an instant messaging app, the application's process requests a graphics buffer from system memory for displaying and saving the data. When the application's process requests the graphics buffer, the phone activates a memory allocation monitoring function. If the instant messaging app meets the conditions for self-destruction recovery (where the graphics buffer request fails with a virtual memory mapping failure, and the application's virtual memory usage exceeds a preset threshold), self-destruction recovery is initiated to release memory, preventing the entire phone system from crashing or freezing.
[0116] For example, such as Figure 4 The diagram shown illustrates some graphical user interfaces (GUIs) that may be involved in application scenario one.
[0117] In some embodiments, the interface of the instant messaging software includes a main display area 10 (the interface corresponding to "messages") and other functional areas 20 (e.g., Figure 4 (a) In the text, "Contacts," "Activities," etc.), sub-dialogue 30. The main display area 10 will display multiple sub-dialogues 30, specifically, as follows: Figure 4 The content is displayed in the form shown in (a). When a user wants to view an article pushed by a specific sub-conversation, they can click on the control corresponding to that sub-conversation (e.g., the sub-conversation of Contact 1), causing the instant messaging software's display interface to jump to the display interface corresponding to that sub-conversation (e.g., ...). Figure 4 (as shown in (b)).
[0118] In some embodiments, such as Figure 4 As shown in (c), when an application is running, for example, when a user clicks on a sub-dialogue to view the dialogue, and the process corresponding to that sub-dialogue needs to allocate a graphics buffer, the phone can display a prompt message asking the user whether to enable the phone's memory allocation monitoring function. This prompt message might be something like, "This operation may cause a memory leak. Do you want to enable the memory allocation monitoring function to ensure the system runs normally?". When the phone receives confirmation from the user that the memory allocation monitoring function is enabled (e.g., the user clicks on a sub-dialogue to view the dialogue), the phone can then display a prompt message asking the user whether to enable the memory allocation monitoring function. Figure 4 When the "Confirm" icon is shown in (c) in the diagram, the memory allocation monitoring function can be enabled to monitor the process of the process allocating the graphics buffer.
[0119] In some embodiments, after the mobile phone obtains the application result for the image buffer, if the application is successful, the application continues to run normally; if the application fails, the reason for the failure is further analyzed. If the reason for the failure is the virtual memory mapping failure, the size of the virtual memory already occupied by the application can be further obtained, and the self-destruction recovery function is activated when the size of the virtual memory already occupied by the application exceeds a preset threshold.
[0120] In some embodiments, when the phone activates the self-destruct recovery function, it can directly terminate all processes of the application, at which point the phone's display will jump back to the phone's home screen (e.g., ...). Figure 4 (The interface shown in (d)).
[0121] Alternatively, when the phone activates the self-destruct recovery function, it can automatically restart the main process of the application after terminating all processes of that application, causing the phone's display to show the main interface of that application (e.g., ...). Figure 4 The interface shown in (a) is shown in the image.
[0122] Understandable. Figure 4The interface shown is merely an example; this application embodiment does not limit the specific content displayed on the interface (such as the specific content of the prompts), the display position of the prompts, etc. For example, in order not to affect the user's viewing of information, Figure 4 The displayed prompts can also be set to appear in the status bar, indicating that relevant information is available for the user. When the user needs to view it, they can pull down the status bar and click on the relevant information. Alternatively, the relevant information can be displayed in a small window in the instant messaging interface, such as the lower right or upper right corner, to notify the user while minimizing obstruction of the chat content and reducing the impact on the user experience.
[0123] It should be noted that the phone can enable the memory allocation monitoring function in the following ways: the user actively enables the memory allocation monitoring function, the phone automatically enables the memory allocation monitoring function, and the memory allocation monitoring function is enabled by default.
[0124] Method 1: The user actively enables the memory allocation monitoring function.
[0125] For example, such as Figure 5 The diagram shown illustrates some graphical user interfaces involved in enabling the memory allocation monitoring function according to an embodiment of this application. Here, a mobile phone is used as an example of an electronic device.
[0126] In some embodiments, when an application starts running and its process requests system memory to create a graphics buffer, the phone can prompt the user to enable the memory request monitoring function. The prompt can be made, for example, by displaying a message on the interface (e.g.,...). Figure 4 (as shown in (c)), or by voice; or by displaying prompts on the interface in combination with voice, etc.
[0127] For example, such as Figure 5As shown in (a) above, this is a schematic diagram of the mobile phone's home screen interface. This home screen interface may include an application icon display area 51, used to display various types of application (App) icons, such as clock icons, calendar icons, gallery icons, memo icons, file manager icons, email icons, music icons, calculator icons, voice recorder icons, fitness tracker icons, instant messaging icons, browser icons, settings icons, etc. Below the multiple application icons may be a page indicator display area 52, which includes page indicators used to indicate the positional relationship between the currently displayed page and other pages. Below the page indicator may be a tray application icon display area 53, used to display multiple tray application icons, such as camera application icons, contacts application icons, dialer application icons, messaging application icons, etc. In some other embodiments, the mobile phone home screen interface may include more or fewer application icons or tray application icons than shown in the diagram; this application does not limit this. Above the home screen interface may also be a status bar 54, which may include: one or more signal strength indicators for mobile communication signals (or cellular signals), a battery indicator for the mobile phone, a time indicator, etc.
[0128] In some embodiments, the mobile phone can receive a user's click on the settings icon; in response to the user's click, the mobile phone can display, for example... Figure 5 The settings details interface shown in (b) is shown in the image.
[0129] like Figure 5 As shown in (b) above, the settings details interface may include management bars for multiple services, such as wireless and network management bars, Bluetooth management bars, desktop and wallpaper management bars, display management bars, sound management bars, application management bars, battery management bars, storage management bars, and security and privacy management bars. In practical applications, the settings interface may also include more or fewer types of management bars than shown in the figure, and this application does not limit this.
[0130] In some embodiments, the mobile phone can receive user clicks on the application management bar; in response to the user's click, the mobile phone can display, for example... Figure 5 The application management interface shown in (c) is shown in the image.
[0131] For example, the application interface may include multiple service management tabs, such as: system application settings, application monitoring management, dual application access, and authorization management. Each service name can be followed by a next-page indicator.
[0132] In some embodiments, such as Figure 5As shown in (c), the phone can receive clicks on the next page indicator in the application monitoring management bar. In response to the user's click, the phone can display... Figure 5 The application monitoring and management interface is shown in (d) above.
[0133] For example, such as Figure 5 As shown in (d), the application monitoring and management interface may include a description of the memory allocation monitoring function, a toggle switch, and personalized settings for each application under the memory allocation monitoring function. The description of the memory allocation monitoring function introduces the function to help users understand its purpose. For example, the description might state, "After enabling the memory allocation monitoring function, the system will monitor the memory allocation requests of running applications to detect memory leaks in a timely manner." In some embodiments, the area below the description of the memory allocation monitoring function may display a toggle switch, allowing users to enable or disable the memory allocation monitoring function.
[0134] It should be understood that by allowing users to independently configure the memory allocation monitoring function's on / off switch for different applications, they can selectively and appropriately utilize this function based on the characteristics of their applications. This approach ensures the function is used more rationally, taking into account different business characteristics, and avoids interference or interruption of certain application processes by the memory allocation monitoring function, thereby guaranteeing a better user experience.
[0135] Method 2: Automatically enable memory allocation monitoring function on the phone.
[0136] In one possible implementation, the phone can automatically enable the memory allocation monitoring function when the application starts running, or it can automatically enable the memory allocation monitoring function when the application process initiates a memory allocation request to the system memory (requesting a graphics buffer) to monitor the memory allocation status.
[0137] Optionally, when the phone enables the memory allocation monitoring function, a prompt message can be displayed to inform the user that the phone is about to perform the monitoring function. Alternatively, a query message can be displayed to ask the user whether they confirm the phone is performing the memory allocation monitoring function (e.g., ...). Figure 4 (as shown in (c)). For example, the prompt or query information may be displayed in the status bar of the phone or in the current screen of the phone, and this application does not limit it in this way.
[0138] It should be understood that the process of the phone automatically activating the memory allocation monitoring function in this way is imperceptible to the user. This method of memory allocation monitoring avoids impacting currently running applications, such as preventing video pauses, thus ensuring a better user experience.
[0139] Method 3, memory allocation monitoring function is enabled by default.
[0140] In one possible implementation, the memory allocation monitoring function can be set to be enabled by default before the phone leaves the factory, so that memory allocation can be monitored and managed at any time during subsequent use of the phone.
[0141] Based on the exemplary enabling methods described above, the memory allocation monitoring method provided in this application embodiment can be performed in a form that is perceptible to the user (such as being actively enabled by the user or displaying relevant information to the user), or it can be performed in a form that is imperceptible to the user. This application embodiment does not limit this.
[0142] The application scenarios and corresponding function activation methods of the application management method provided in this application embodiment have been described above with reference to the accompanying drawings. To better understand the signal strength prediction method provided in this application embodiment, its specific implementation process will be exemplarily described below with reference to the accompanying drawings.
[0143] For example, such as Figure 6 The diagram illustrates the system interaction flow of an electronic device during the execution of the application management method provided in this embodiment of the application. Specifically, it may include the following steps:
[0144] S601: During application execution, the application process requests a graphics buffer from the memory manager.
[0145] The aforementioned applications can be either multi-process or single-process. In practical applications, to improve running speed and reduce application redundancy, applications are usually multi-process, and the multiple processes can have a master-slave relationship.
[0146] During application runtime, in order to draw the interface and save the drawn data, the running process requests a graphics buffer from the memory manager. Taking the Android system as an example, the process can request a graphics buffer from the memory manager in the following ways:
[0147] Method 1: Request an inter-process shared graphics buffer via the graphicbuffermapper.
[0148] The Android system provides a utility class called graphicbuffermapper, which provides an interface for higher layers to access the hardware abstraction layer (gralloc module).
[0149] When a user-space application uses a graphics buffer, it first needs to load the gralloc module and obtain a gralloc device and a framebuffer (FB) device. With the gralloc device, the user-space application can request and allocate a graphics buffer and map it into its address space so that it can write the content to be drawn. Finally, the user-space application uses the FB device to render the prepared graphics buffer into the framebuffer, that is, to draw the contents of the graphics buffer onto the display screen, thus realizing the application's user interface display.
[0150] Method 2: Request a graphics buffer for the application to use through the graphicbufferallocator process interface.
[0151] The Android system also provides the graphicbufferallocator process interface, through which an image buffer can be allocated.
[0152] S602, the suicide recovery management module starts the memory allocation monitoring function.
[0153] Here, after activating the memory allocation monitoring function, the suicide recovery management module will send an instruction to the memory manager to obtain the allocation result of the graphics buffer.
[0154] In some embodiments, the suicide recovery management module can start the memory allocation monitoring function when the application starts running, or it can start the memory allocation monitoring function when the application process initiates a graphics buffer request to the system memory. The suicide recovery management module can also obtain the virtual memory usage of the application in real time. When the virtual memory usage of the application exceeds a certain value (this value can be set according to the actual application scenario, and this application does not limit it), the memory allocation monitoring function is enabled. Alternatively, the memory allocation monitoring function can be enabled only when the virtual memory usage of the application exceeds a certain value and the application process initiates a graphics buffer request. Of course, the memory allocation monitoring function can also be enabled in other situations, which will not be elaborated in this application.
[0155] The method for activating the memory allocation monitoring function can be found in the relevant content mentioned above, and will not be repeated here to avoid duplication.
[0156] Here, the application results for the above graphics buffer include successful application and application failure.
[0157] The application result can be represented in binary encoding. For example, the application result may include two fields: one field to indicate whether the application was successful, and the other field to indicate the error type when the application failed. For instance, the field indicating whether the application was successful includes two bits, where 00 indicates success and 01 indicates failure; the field indicating the failure type includes three bits, where 001 indicates insufficient available system memory, 010 indicates memory mapping failure, and 011 indicates other abnormal situations (the second field is 000 when the first field is 00).
[0158] Of course, the above application result can also include only one field, which can indicate whether the application was successful or the failure type when the application failed. For example, this field includes 4 digits, where the first digit indicates whether the application was successful, and the second to fourth digits indicate the failure type when the application failed. For example, 0000 indicates that the application was successful, 1001 indicates that the application failed and the failure type is insufficient available system memory, 1010 indicates that the application failed and the failure type is memory mapping failure, and 1011 indicates that the application failed and the failure type is other abnormal conditions.
[0159] Of course, when the application is successful, it can return no_error; when the application fails, it can return error with an error code to indicate the failure type.
[0160] It is understood that the above is merely an example of the application result, and the application result may also include other content, such as the return time, etc., which is not limited in this application.
[0161] S603, in response to the instruction to obtain the request result of the graphics buffer, the memory manager sends the request result of the graphics buffer to the suicide recovery management module.
[0162] Specifically, when an application process requests an image buffer from system memory, if the system has sufficient available memory to satisfy the request and the requested memory can be mapped to the address of the process's virtual memory, the memory manager will send the successful request result to the suicide recovery management module.
[0163] When there is insufficient available system memory (the requested graphics buffer occupies more memory than the available system memory), the requested memory cannot be mapped to the address of the process's virtual memory, or other abnormal situations, the memory manager will send the failure result to the suicide recovery management module.
[0164] It should be noted that if an application process requests a graphics buffer through method 2 in S601, that is, through the graphicbufferallocator process interface, although the request for the graphics buffer fails for the process, the memory manager has actually allocated the memory required by the requested graphics buffer to the process. After the process fails to request, it will continue to make requests. In this way, the memory allocated by the system (which is not actually used) will accumulate more and more, eventually leading to insufficient system memory and a system crash.
[0165] S604, if the suicide recovery management module detects that the received graphics buffer request was successful, the suicide recovery management module sends a mapping instruction to the application.
[0166] S605, in response to the mapping instruction, the application maps the allocated memory to the address of the application's process's virtual memory.
[0167] Once the suicide recovery management module receives the request result from the memory manager, it can determine whether the graphics buffer allocation was successful by analyzing the corresponding binary code. For example, if the allocation result includes two fields, where the first field indicates whether the allocation was successful, the encoding of this field can be read, and the graphics buffer allocation result can be determined based on this encoding.
[0168] For example, if the suicide recovery management module receives an application result of "00, 000", it reads the content "00" from the first field and, based on the pre-determined meaning of this code, knows that the application result is successful. As another example, if the application result is "01, 010", it reads the content "01" from the first field, and, based on the pre-determined meaning of this code, knows that the application result is unsuccessful.
[0169] For example, when the application result contains only one field, where the first bit of the field is used to indicate whether the application was successful, the encoding of that bit is read, and the application result of the memory application is determined based on the encoding of that bit.
[0170] For example, if the application result is "0000", then the first bit of the code "0" is read, and according to the pre-determined meaning of the code, the application result is successful. As another example, if the application result is "1010", then the first bit of the code "1" is read, and according to the pre-determined meaning of the code, the application result is unsuccessful.
[0171] The memory mapping process, in which the application maps the allocated memory to the address of the process's virtual memory, is a common memory management method. The specific memory mapping process can be found in existing methods, and will not be elaborated here.
[0172] S606, if the suicide recovery management module detects that the received graphics buffer application has failed, it will analyze the failure type based on the application result.
[0173] The process by which the suicide recovery management module determines that a memory request has failed can be found in the description of S604, and will not be repeated here to avoid duplication.
[0174] The failure types when the above application fails can include insufficient available system memory, memory mapping failure, other abnormal situations, etc., which are not limited here.
[0175] In some embodiments, the suicide recovery management module can determine the failure type based on the allocation result returned by the memory manager. For example, the failure type can be determined by analyzing the binary representation of the allocation result.
[0176] For example, when the application result includes two fields, where the first field indicates whether the application was successful and the second field indicates the failure type, the encoding of the second field can be read, and the memory application result can be determined based on the encoding of the second field.
[0177] For example, if the application result is "01, 001", then the content of the second field, "001", is read. Based on the pre-determined meaning of this code, the failure type is insufficient available system memory. As another example, if the application result is "01, 010", then the content of the second field is read as "010". Based on the pre-determined meaning of this code, the failure type is memory mapping failure.
[0178] For example, when the application result contains only one field, where the second to fourth bits of the field are used to indicate the failure type, the encoding of the second to fourth bits is read, and the application result of the memory application is determined based on the encoding of the second to fourth bits.
[0179] For example, if the request result is "1001", then the second to fourth bits of the code "001" are read. Based on the pre-determined meaning of this code, the failure type is insufficient available system memory. As another example, if the request result is "1010", then the second to fourth bits of the code "010" are read. Based on the pre-determined meaning of this code, the failure type is memory mapping failure.
[0180] For example, when the application result is returned as an error with an error code, the failure type can be determined by the error code.
[0181] S607, if the suicide recovery management module determines that the failure type is not memory mapping failure, it sends the first exception log output instruction to the log manager.
[0182] For details on determining the type of failure, please refer to the description in S606, which will not be repeated here.
[0183] S608, the log manager responds to the first exception log output instruction by generating and saving an exception log corresponding to the failure type.
[0184] Here, the aforementioned first exception log output instruction is used to instruct the log manager to generate and save exception logs corresponding to the failure type.
[0185] Since the failure type is not memory mapping failure, it will basically not cause memory leaks. Therefore, no operation is required in the application. It is only necessary to control the log manager to generate and save the exception log corresponding to this failure type so that the user knows the failure type of the graphics buffer application failure, as well as other relevant information (such as the application time, the application subject (i.e., which process of which application submitted the application)).
[0186] In some embodiments, the aforementioned exception log may include the name of the process that initiated the request, the time of the exception, and the content of the exception. The content of the exception includes the failure to request a graphics buffer and the failure type. For example, when the failure type is insufficient system available memory, the aforementioned exception content may be: Process B of application A failed to request a graphics buffer at xx time due to insufficient system memory.
[0187] In some embodiments, when the failure type is insufficient system memory, the electronic device can initiate the LMK mechanism based on the exception log.
[0188] In some embodiments, the aforementioned exception logs can be stored in a log manager, and electronic devices can read the exception logs through the log manager.
[0189] S609, the suicide recovery management module obtains the application's virtual memory usage when the failure type is determined to be memory mapping failure.
[0190] When the failure type is memory mapping failure, it is very likely because the application's virtual memory usage is too high. This situation can easily lead to system memory leaks. In order to determine whether it is due to excessive virtual memory usage, you can obtain the application's virtual memory usage and then analyze whether there is a risk of memory leaks.
[0191] In some embodiments, the suicide recovery management module can use the ` / proc / self / status` function to retrieve the application's virtual memory usage. After determining that a memory allocation failure has occurred and the failure type is memory mapping failure, the ` / proc / self / status` function is automatically called to obtain the application's current virtual memory usage.
[0192] S610, the suicide recovery management module determines whether the virtual memory used by the application exceeds a preset threshold.
[0193] The preset threshold can be set according to the application. For example, for a 32-bit application, the preset threshold can be set to 3.7G. Of course, for a 32-bit application, the preset threshold can be set to a value lower than 3.7G, such as 3.5G or 3.2G.
[0194] S611, the suicide recovery management module sends a second abnormal log output instruction to the log manager when it determines that the virtual memory occupied by the application has not exceeded the preset threshold.
[0195] S612, in response to the second exception log output instruction, the log manager generates and saves an exception log indicating that memory mapping failed and virtual memory did not exceed the threshold.
[0196] Here, the aforementioned first exception log output instruction is used to instruct the log manager to generate and save exception logs for memory mapping failures and virtual memory not exceeding the threshold.
[0197] Here, since the virtual memory occupied by the application does not exceed the preset threshold, that is, this will not cause a memory leak, no action needs to be taken on the application. It is only necessary to generate and save the exception log of memory mapping failure and virtual memory not exceeding the threshold through the log manager.
[0198] S613, when the suicide recovery management module determines that the virtual memory occupied by the application exceeds the preset threshold, it sends a command to the process manager to start the suicide recovery function.
[0199] S614, in response to the instruction to initiate the self-inflicted recovery function, the process manager terminates all processes of the application.
[0200] In some embodiments, when the virtual memory occupied by an application exceeds a preset threshold, the suicide recovery management module can send an instruction to the process manager to activate the suicide recovery function. This instruction is used to instruct the process manager to terminate all processes of the application and release the system memory occupied by the application.
[0201] The Task Manager displays all currently running processes on the system. By ending all processes associated with the application's name using the Task Manager, you can release the system memory occupied by that application.
[0202] In some embodiments, when an electronic device activates the self-destruct recovery function, it can directly terminate all processes of the application. At this time, the display interface of the electronic device will jump back to the main screen interface of the electronic device, that is, the user will feel the application crashing.
[0203] In some embodiments, after the process manager terminates all processes of the application, the log manager can also generate and save an exception log indicating that the application terminated due to excessive virtual memory usage.
[0204] According to the application management method provided in the embodiments of this application, by monitoring the application process's request for a graphics buffer from the memory manager, if the memory request fails due to excessive virtual memory usage, a self-destruct recovery function is activated to terminate all processes of the application, thereby releasing the memory occupied by the application, avoiding serious consequences such as system crashes and freezes caused by memory leaks, and reducing the impact on user experience.
[0205] The above embodiments cause the application to crash immediately, resulting in a poor user experience. To mitigate the impact on user experience, another embodiment of this application provides an application management method, such as... Figure 7 The diagram illustrates another interaction flow within the system of the electronic device during the execution of the application management method provided in this embodiment of the application. Specifically, it may include the following steps:
[0206] The contents of S701 to S712 can be found in the contents of S601 to S612. To avoid repetition, they will not be repeated here.
[0207] S713, the suicide recovery management module determines whether the process that initiated the graphics buffer request is the main process if it finds that the virtual memory occupied by the application exceeds a preset threshold.
[0208] Here, the suicide recovery management module can determine whether the process that initiated the graphics buffer request (the currently running process) is the main process by using the process ID.
[0209] Each process has its own ID, and the ID of the main process is clearly different from that of the child process. Therefore, the process ID can be used to determine whether it is the main process or a child process.
[0210] S714, the suicide recovery management module, upon determining that the process that initiated the graphics buffer request is not the main process, sends an instruction to the process manager to terminate all processes of the application.
[0211] S715, in response to the above instruction to terminate all processes of the application, the process manager terminates all processes of the application.
[0212] Since the process that initiated the graphics buffer request is not the main process, the interface displayed on the electronic device is not the main process of the application. It may be a page that the user has entered after multiple operations. The electronic device cannot reproduce this page. Therefore, the electronic device will only terminate all processes of the application through the process manager to release the system memory occupied by it.
[0213] The process of terminating all processes of an application can be found in the description of S614, and will not be repeated here to avoid repetition.
[0214] S716, when the suicide recovery management module determines that the process that initiated the graphics buffer request is the main process, sends an instruction to the process manager to terminate all processes of the application and then restart the main process of the application.
[0215] S717, the process manager responds to the above instruction to terminate all processes of the application and then restart the main process of the application.
[0216] Since the process that initiated the graphics buffer request is the application's main process, the interface displayed on the electronic device at this time is the application's main display interface. Therefore, after all processes of the application are terminated, the application's main process is automatically restarted, and the electronic device's display interface will directly jump to the application's main display interface.
[0217] Because the interval between ending and restarting the application's main process is very short, the user is unaware of this; they only perceive the electronic device's display returning to the application's main screen. In this way, the user doesn't experience an application crash, thus freeing up system memory occupied by the application while avoiding impacting user experience and improving overall user satisfaction.
[0218] This application also provides a computer-readable storage medium storing instructions that, when executed on a computer or processor, cause the computer or processor to perform one or more steps of any of the above methods.
[0219] This application also provides a computer program product containing instructions. When the computer program product is run on a computer or processor, it causes the computer or processor to perform one or more steps of any of the methods described above.
[0220] This application also provides a chip system containing instructions. When these instructions are executed on a computer or processor, they cause the computer or processor to perform one or more steps of any of the methods described above.
[0221] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially as a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted through the computer-readable storage medium. The computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state disk (SSD)).
[0222] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. This program can be stored in a computer-readable storage medium, and when executed, it can include the processes described in the above method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as ROM or random access memory (RAM), magnetic disks, or optical disks.
[0223] The above description is merely a specific implementation of the embodiments of this application, but the protection scope of the embodiments of this application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the embodiments of this application should be covered within the protection scope of the embodiments of this application. Therefore, the protection scope of the embodiments of this application should be determined by the protection scope of the claims.
Claims
1. A method for managing an application, characterized in that, include: Run the first application in the foreground; At the first point in time, the first application requests a graphics buffer; At a second time point, the process of the first application is terminated based on at least the following conditions: the first application fails to request a graphics buffer, the failure type is memory mapping failure, and the virtual memory occupied by the first application exceeds a preset threshold; at the termination of the process of the first application, the first application fails to request a graphics buffer, the failure type is memory mapping failure, and the virtual memory occupied by the first application exceeds a preset threshold. The second time point is later than the first time point.
2. The application management method as described in claim 1, characterized in that, After the second time point, run the first and second applications; At the third time point, the first application requests a graphics buffer; The process of the second application ends at the fourth time point; When the process of the second application terminates, the first application fails to request a graphics buffer, and the failure type is insufficient system memory.
3. The application management method as described in claim 1, characterized in that, Determine the failure type between the first and second time points; When the failure type is memory mapping failure, obtain the application's virtual memory usage; Determine whether the virtual memory used by the application exceeds a preset threshold.
4. The application management method as described in claim 3, characterized in that, When the virtual memory used by an application exceeds a preset threshold, all processes of the application will be terminated.
5. The application management method as described in claim 3, characterized in that, When the virtual memory occupied by the application exceeds a preset threshold, it is determined whether the process requesting the graphics buffer is the main process of the application. If the process requesting the graphics buffer is the main process of the application, then after terminating all processes of the application, the main process of the application is restarted; otherwise, all processes of the application are terminated.
6. The application management method as described in claim 3, characterized in that, If the failure type is not memory mapping failure, then output the exception log corresponding to the failure type; If the virtual memory used by the application does not exceed the preset threshold, an exception log will be output indicating that memory mapping failed and virtual memory did not exceed the threshold.
7. The application management method according to any one of claims 3 to 6, characterized in that, After terminating all processes of the application, an exception log is output indicating that the application terminated due to excessive virtual memory usage.
8. The application management method as described in claim 3, characterized in that, When the application's process initiates a graphics buffer request, the memory allocation monitoring function is activated to obtain the graphics buffer allocation result.
9. An electronic device, characterized in that, The device includes a processor and a memory coupled together, the memory being used to store a computer program, which, when executed by the processor, causes the electronic device to perform the steps of the method according to any one of claims 1 to 8.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a computer program that, when run on a computer, causes the computer to perform the steps of the method as described in any one of claims 1 to 8.
11. A chip, characterized in that, The device includes a processor coupled to a memory for storing computer program instructions, which, when executed by the processor, cause the chip to perform the steps of the method as described in any one of claims 1 to 8.
Citation Information
Patent Citations
Memory management method and electronic equipment
CN113434288A
