Memory repairing and cleaning method and related equipment

By repairing and cleaning memory leaked applications in a state without the user's perception, the problems of continuous increase in Java memory and garbage collection overload are solved, and the application performance and user experience are improved.

CN119201425APending Publication Date: 2024-12-27HONOR DEVICE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411135243.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-06-02
Publication Date
2024-12-27

AI Technical Summary

Technical Problem

The existing technology is difficult to effectively solve the memory leak problem caused by long-term use of applications, resulting in the continuous rise of Java memory, causing garbage collection overload and performance problems such as lag and application unresponsiveness.

Method used

By performing memory repair and cleaning of applications with memory leaks in a user-free state, including copying the zygote virtual machine when specific conditions are met, determining whether the application is in a user-free state, and destroying the application when thresholds and durations are met, avoiding Affects the use of front-end applications.

Benefits of technology

It effectively avoids lag and performance problems caused by memory leakage, ensures user experience, and avoids unnecessary memory repair and cleaning, saving computing resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119201425A_ABST
    Figure CN119201425A_ABST
Patent Text Reader

Abstract

The invention discloses a memory repairing and cleaning method and related equipment. According to the memory repairing and cleaning method, the electronic equipment can apply for a standby virtual address field when creating a zygote virtual machine, if an application with memory leak exists, the electronic equipment can firstly perform memory expansion on the application based on the standby virtual address field, and when the memory leak condition is relatively serious, the application can be repaired and cleaned. And under the condition that a user does not perceive the application program with the memory leak, performing memory repair and cleaning on the application program with the memory leak. According to the method, the problems of blockage and the like can be effectively avoided on the premise of not influencing the use of the foreground application by the user, and the memory can be repaired and cleaned under the condition of ensuring that the user does not perceive the application after the application is returned to the background, so that the problem of memory leakage is better solved.
Need to check novelty before this filing date? Find Prior Art

Description

[0001] This application is a divisional application. The application number of the original application is 202310652474.3, and the original application date is June 02, 2023. The entire contents of the original application are incorporated into this application by reference. Technical Field

[0002] The present application relates to the field of terminal technology, and in particular to a memory repair and cleaning method and related equipment. Background Art

[0003] Some applications may have memory leaks after long-term use. That is, after applying for Java memory, the corresponding memory cannot be released normally, causing the Java memory occupied by the application to continue to increase. Once the Java memory available to the application is insufficient, the application will trigger garbage collection (GC) for the Block type. In this case, the application GC will become extremely busy and occupy CPU and memory resources, further blocking the execution of Java code, and ultimately causing serious performance issues such as severe freezes and application unresponsiveness (ANR).

[0004] Therefore, how to repair and clean up memory for memory leaks is an urgent problem to be solved. Summary of the invention

[0005] The present application provides a memory repair and cleaning method and related equipment. According to the memory repair and cleaning method, if there is an application with memory leakage, the electronic device can expand the memory of the application and repair and clean the memory of the application without the user being aware of the application. In this way, it will not affect the user's use of the foreground application, and can effectively avoid problems such as freezes, and better solve the problem of memory leakage.

[0006] In the first aspect, the present application provides a memory repair and cleaning method. The method can be applied to electronic devices. The method may include: the electronic device may receive a first instruction to cold-start a first application, and in response to the first instruction, the electronic device may copy a zygote virtual machine to obtain a first application virtual machine; when the first preset condition is met, the electronic device may determine whether the first application is in a user-unaware state based on the current running state of the first application; if the first application is in a user-unaware state, the electronic device may perform memory repair and cleaning on the first application, that is, destroy the first application. Among them, the Java memory space in the first application virtual machine is the first Java memory space. The first preset condition may include: the occupied memory of the first Java memory space is greater than the first threshold, and the duration of the first application residing in the background is greater than the first duration.

[0007] In the solution provided in the present application, if the occupied memory of the Java memory space of the first application virtual machine reaches a certain threshold (for example, the first threshold), and the time the first application resides in the background is greater than a certain time (for example, the first time), the electronic device can obtain the current running state of the first application, and determine whether the first application is in a user-unaware state based on the current running state, that is, determine whether the user can perceive that the first application is running. When the first application is in a user-unaware state, the electronic device can perform memory repair and cleaning on the first application, that is, destroy the first application (also known as killing the first application). This method can perform memory repair and cleaning on the application after the user does not use the application with memory leak problems, which will not affect the user's use of the foreground application, and can avoid problems such as freezes and ANRs.

[0008] In some embodiments of the present application, the first application may be Application_1, the first application virtual machine may be Application_1 virtual machine, and the first Java memory space may be RegionSpace_2.

[0009] In some embodiments of the present application, the first instruction may be the instruction in step S1 (eg Figure 7 ), which may be the instruction in step S103 (such as Figure 8 ), which may be the instruction in S203 (such as Fig.9A ), which may be the instruction in step S303 (such as Fig.10 shown).

[0010] In some embodiments of the present application, the first preset condition may have the same content as the "preset condition_1" mentioned below. For example, when the first Java memory space is RegionSpace_2 and the first threshold is memory threshold_1, the first preset condition and the preset condition_1 both include: the occupied memory of the first Java memory space is greater than the first threshold.

[0011] In some embodiments of the present application, the first threshold may be memory threshold_1.

[0012] In some embodiments of the present application, the first duration may be duration threshold_1.

[0013] In combination with the first aspect, in a possible implementation, the electronic device determines whether the first application is in a user-imperceptible state based on the current running state of the first application, which may specifically include: the electronic device determines whether the first application is in a user-imperceptible state by determining whether the current running state of the first application includes a perceptible state item. The first application is in a user-imperceptible state, which may specifically include: the current motion state of the first application does not include a perceptible state item. Among them, the perceptible state items include any one or more of the following: small window display, downloading, and background playback.

[0014] According to the solution provided in the present application, the electronic device can determine whether the first application is in a user-imperceptible state by whether there is a perceptible status item in the current running state of the first application. If there is a perceptible status item in the current running state of the first application, the first application is not in a user-imperceptible state (hereinafter referred to as an imperceptible state), that is, it is in a user-perceptible state (hereinafter referred to as a perceptible state). If there is no perceptible status item in the current running state of the first application, the first application is in an imperceptible state. This method can determine whether the user is currently using the application based on the current running state of the application, thereby avoiding memory repair and cleaning of the application when the user is using the application, which will not affect the user's use of the application, and can avoid problems such as freezes and ANRs.

[0015] It is understandable that the specific description of the operating status and perceptible status items can be found below and will not be elaborated here.

[0016] In combination with the first aspect, in a possible implementation method, after the electronic device determines whether the first application is in a user-unaware state based on the current running state of the first application, the method may also include: if the first application is not in a user-unaware state, the electronic device re-determines whether the first application is in a user-unaware state based on the current running state of the first application after a second time interval.

[0017] According to the solution provided by the present application, after determining that the first application is not in a user-unaware state, the electronic device can re-acquire the current running state of the first application after a period of time (for example, a second time period), and determine whether the first application is in a user-unaware state based on the re-acquired current running state of the first application. This method can increase the probability of performing memory repair and cleaning on the application to a certain extent, rather than not performing memory repair and cleaning on the application with memory leaks based on only one running state.

[0018] In some embodiments of the present application, the second duration may be T1.

[0019] In combination with the first aspect, in a possible implementation method, after the electronic device re-determines whether the first application is in a user-unaware state based on the current running state of the first application after a second time period, the method may also include: if the electronic device determines for X consecutive times that the first application is not in a user-unaware state, the electronic device stops executing the step of re-determining whether the first application is in a user-unaware state based on the current running state of the first application after a second time period.

[0020] In some embodiments of the present application, X is an integer greater than or equal to 2. In some embodiments of the present application, X=M.

[0021] According to the solution provided by the present application, for applications that are continuously perceptible to the user and have memory leaks, the electronic device will not continue to try to repair and clean up the memory, but will stop trying after several attempts. This method can save computing resources while trying to solve the memory leak problem.

[0022] In combination with the first aspect, in a possible implementation, before the electronic device determines whether the first application is in a user-unaware state based on the current running state of the first application, the method may also include: when the occupied memory of the first Java memory space is greater than a first threshold, the electronic device may send a memory leak message to the SystemServer process in the electronic device through the first application virtual machine; the electronic device may determine whether the first application is in the foreground through the SystemServer process.

[0023] According to the solution provided by the present application, when the first application virtual machine determines that its own Java memory is too much, the first application virtual machine can send a corresponding message (for example, a memory leak message) to the SystemServer process to request memory repair and cleanup. In this way, the subsequent memory repair and cleanup steps are triggered only when the application has the problem of excessive memory usage, rather than judging the memory usage and residing in the background at the same time, which simplifies the program and saves computing resources to a certain extent.

[0024] In combination with the first aspect, in a possible implementation, the electronic device determines whether the first application is in a user-unaware state based on the current running state of the first application, which may specifically include: when the first application is in the foreground, if the first application switches from the foreground to the background, the electronic device may send a first message to the SystemServer process through the SystemServer process, and after the electronic device receives the first message through the SystemServer process, it determines whether the first application is in a user-unaware state based on the current running state of the first application. The first message is a handle message sent with a delay of a third time period. The third time period may be greater than or equal to the first time period.

[0025] According to the solution provided by the present application, the electronic device can send a delayed handle message after the first application is switched from the foreground to the background, instead of immediately executing the subsequent memory repair and cleaning steps. In this way, on the one hand, it can avoid the user from finding that the first application has been destroyed when the user checks the first application again in a short period of time, thereby ensuring the user experience, and on the other hand, it can avoid the judgment error caused by the current running status of the first application not being updated when the switching time is too short.

[0026] In this application, the use of handle messages can realize placing some time-consuming operations in child threads (for example, the child threads involved in the memory repair and cleaning module, application information collection module and application status management module mentioned later) (asynchronous processing), thereby avoiding blocking the main thread, improving the application response speed, and minimizing the coupling between different components, increasing the reusability and extensibility of the code.

[0027] In some embodiments of the present application, the third duration may be T2. In one possible implementation, T2 may be equal to the memory threshold_1. In another possible implementation, T2 may be greater than the memory threshold_1.

[0028] In some embodiments of the present application, the first message may be handle message_1.

[0029] In combination with the first aspect, in a possible implementation method, when the first preset condition is met, the electronic device determines whether the first application is in a user-unaware state based on the current running state of the first application. Specifically, it may include: when the first application is in the background, if the time length of time that the first application resides in the background is greater than the first time length, the electronic device may send a second message to the SystemServer process through the SystemServer process. After receiving the second message through the SystemServer process, the electronic device may determine whether the first application is in a user-unaware state based on the current running state of the first application.

[0030] According to the solution provided by the present application, the electronic device can perform subsequent memory repair and cleaning steps after the first application has been resident in the background for a certain period of time. In this way, on the one hand, it can avoid the user from finding that the first application has been destroyed when the user checks the first application again in a short period of time, thereby ensuring the user experience; on the other hand, it can avoid the judgment error caused by the current running state of the first application not being updated when the first application is obtained due to the short time of resident in the background (for example, the current running state of the first application is still the state when it is in the foreground).

[0031] In some embodiments of the present application, the second message may be handle message_2.

[0032] It is understandable that the second message may be a handle message that is sent immediately. In layman's terms, "immediate sending" means that the sending is not intentionally delayed.

[0033] In combination with the first aspect, in a possible implementation, when the first preset condition is met, the electronic device determines whether the first application is in a user-unaware state based on the current running state of the first application, which may specifically include: when the first application is in the background, if the length of time the first application resides in the background is not greater than the first length of time, the electronic device may send a third message to the SystemServer process through the SystemServer process, and after the electronic device receives the third message through the SystemServer process, it determines whether the first application is in a user-unaware state based on the current running state of the first application. The third message is a handle message sent with a delay of a fourth length of time. The fourth length of time is not less than the difference between the first length of time and the length of time the first application resides in the background.

[0034] According to the solution provided by the present application, the electronic device can send a delayed handle message after the first application resides in the background for a short time (for example, not longer than the first time), instead of immediately executing the subsequent memory repair and cleaning steps. In this way, on the one hand, it can avoid the user from finding that the first application has been destroyed when checking the first application again in a short time, thereby ensuring the user experience, and on the other hand, it can avoid the judgment error caused by the current running status of the first application not being updated when the switching time is too short.

[0035] In some embodiments of the present application, the fourth duration may be T2-T3. In some embodiments of the present application, the fourth duration may be greater than (T2-T3).

[0036] In some embodiments of the present application, the third message may be handle message_3.

[0037] In combination with the first aspect, in a possible implementation, the method may further include: after the electronic device receives the first message, the second message, or the third message through the SystemServer process, the electronic device may obtain the relevant information of the related process of the first application through the SystemServer process. The electronic device destroys the first application, which may specifically include: the electronic device may clear all related processes of the first application based on the relevant information of the related process of the first application.

[0038] According to the solution provided in the present application, the electronic device can destroy the first application by clearing the related processes of the first application.

[0039] In combination with the first aspect, in a possible implementation manner, the first preset condition may further include: the first application is a first preset application.

[0040] According to the solution provided by this application, the electronic device can use the above method to perform memory repair and cleaning for specific applications. This method can control the number of applications that perform memory repair and cleaning, and avoid the application user experience being affected by too many applications that use the above method to perform memory repair and cleaning.

[0041] In some embodiments of the present application, the first preset application may be preset application_1.

[0042] In combination with the first aspect, in a possible implementation, the method may further include: before the electronic device destroys the first application, if the occupied memory of the first Java memory space is less than a second threshold, or the first application has been destroyed, the electronic device no longer destroys the first application.

[0043] According to the solution provided by this application, before performing memory repair and cleaning on an application, if the memory of the application drops to a certain value or the application has been destroyed, the electronic device does not need to destroy the application. This method can reduce the misjudgment of application memory leaks to a certain extent and save computing resources to a certain extent.

[0044] In some embodiments of the present application, the second threshold may be memory threshold_2.

[0045] In combination with the first aspect, in a possible implementation, the Java memory space in the zygote virtual machine is the second Java memory space. The memory size of the second Java memory space is the first memory. The virtual address corresponding to the second Java memory space is the first virtual address segment and the second virtual address segment, and the memory size corresponding to the first virtual address segment is the first memory. The memory corresponding to the second virtual address segment is the backup virtual memory applied for by the zygote virtual machine. The sum of the memory size corresponding to the first virtual address segment and the memory size corresponding to the second virtual address segment is greater than the default memory of the second Java memory space. Before the electronic device determines whether the first application is in a user-unaware state based on the current running state of the first application, the method may also include: when the second preset condition is met, based on the second virtual address segment, the electronic device can expand the memory size of the first Java memory space from the first memory to the second memory. The second memory is the memory size corresponding to the third virtual address segment. The third virtual address segment may include the first virtual address segment, and part or all of the addresses in the second virtual address segment. The second memory is larger than the first memory.

[0046] According to the solution provided by this application, after the occupied Java memory of an application reaches a certain value, the electronic device can first expand the Java memory of the application. If the occupied Java memory of the application continues to rise to a certain value, the electronic device will then perform subsequent memory repair and cleanup steps. This method can expand the Java memory while reducing the probability of destroying the application, thereby avoiding problems such as freezes and ANRs.

[0047] In some embodiments of the present application, the virtual address corresponding to the Java memory space can be understood as: the virtual address segment corresponding to the Java memory space, and the memory size corresponding to the virtual address segment is related to the memory size of the Java memory space. In the present application, the virtual address segment corresponding to the Java memory space can be understood as the virtual address segment that can be used by the Java memory space. In the case where the virtual address segment corresponding to the Java memory space is the virtual address currently used by the Java memory space, the memory size corresponding to the virtual address segment is the current memory size of the Java memory space. In the case where the virtual address segment corresponding to the Java memory space is not all the virtual address currently used by the Java memory space, the memory size corresponding to the virtual address segment currently used by the Java memory space is the current memory size of the Java memory space.

[0048] In some embodiments of the present application, the first memory may be a default memory of RegionSpace_1.

[0049] In some embodiments of the present application, the first memory may be memory_2.

[0050] In some embodiments of the present application, the second memory may be memory_1.

[0051] In some embodiments of the present application, the second memory may be memory_3.

[0052] In some embodiments of the present application, the second preset condition may be preset condition_2.

[0053] In some embodiments of the present application, the second virtual address segment may be a spare virtual address segment.

[0054] In some embodiments of the present application, the first virtual address segment may be virtual address segment_11, and the second virtual address segment may be virtual address segment_12.

[0055] In some embodiments of the present application, the second Java memory space may be RegionSpace_1.

[0056] In conjunction with the first aspect, in a possible implementation, satisfying the second preset condition may specifically include: a first Java memory space in the electronic device satisfies the first memory condition, and a first application in the electronic device is a second preset application. Wherein, satisfying the first memory condition may specifically include: the occupied memory in the first Java memory space reaches a third threshold, and / or the growth rate of the occupied memory in the first Java memory space is greater than a fourth threshold.

[0057] In some embodiments of the present application, the second preset application may be preset application_2.

[0058] In some embodiments of the present application, the third threshold may be memory threshold_3.

[0059] In some embodiments of the present application, the fourth threshold may be r%.

[0060] In some embodiments of the present application, “the first Java memory space satisfies the first memory condition” has the same meaning as “RegionSpace_2 memory satisfies condition_1” in the following text.

[0061] In combination with the first aspect, in a possible implementation, satisfying the second preset condition may specifically include: the first Java memory space in the electronic device satisfies the first memory condition, the first application in the electronic device is the second preset application, and the unoccupied memory of the operating system of the electronic device is greater than a fifth threshold. Among them, the first Java memory space satisfies the first memory condition, which may specifically include: the occupied memory in the first Java memory space reaches the third threshold, and / or the growth rate of the occupied memory in the first Java memory space is greater than a fourth threshold.

[0062] In some embodiments of the present application, the fifth threshold may be memory threshold_4.

[0063] In combination with the first aspect, in a possible implementation manner, the first memory may be a default memory of the second Java memory space.

[0064] In a second aspect, the present application provides an electronic device, comprising: one or more memories, and one or more processors; the one or more memories are coupled to the one or more processors, the memory is used to store computer program code, the computer program code includes computer instructions, and the one or more processors call the computer instructions to enable the electronic device to perform the method described in the first aspect or any one of the implementations of the first aspect.

[0065] In a third aspect, the present application provides a computer storage medium, which includes computer instructions, and when the computer instructions are executed on an electronic device, the electronic device executes the method described in the first aspect or any one of the implementations of the first aspect.

[0066] In a fourth aspect, an embodiment of the present application provides a chip. The chip can be applied to an electronic device, and the chip includes one or more processors, and the processor is used to call computer instructions to enable the electronic device to execute the method described in the first aspect or any implementation of the first aspect.

[0067] In a fifth aspect, an embodiment of the present application provides a computer program product comprising instructions. When the computer program product is run on an electronic device, the electronic device executes the method described in the first aspect or any one of the implementations of the first aspect.

[0068] It is understandable that the electronic device provided in the second aspect, the computer storage medium provided in the third aspect, the chip provided in the fourth aspect, and the computer program product provided in the fifth aspect are all used to execute the method described in the first aspect or any one of the implementations of the first aspect. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects of any possible implementation of the first aspect, which will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0069] Figure 1 A schematic diagram of the software structure of an electronic device provided in an embodiment of the present application;

[0070] Figure 2 A schematic diagram of the incubation principle of a zygote process provided in an embodiment of the present application;

[0071] Figure 3A and Figure 3B A schematic diagram of a virtual machine provided in an embodiment of the present application;

[0072] Figure 4 A schematic diagram of a runtime data area provided in an embodiment of the present application;

[0073] Figure 5 A schematic diagram of a zygote virtual machine provided in an embodiment of the present application;

[0074] Figure 6 A schematic diagram of the principle of a zygote virtual machine incubating other application process virtual machines provided in an embodiment of the present application;

[0075] Figure 7 A flowchart of a memory repair and cleaning method provided in an embodiment of the present application;

[0076] Figure 8 A flowchart of another memory repair and cleaning method provided in an embodiment of the present application;

[0077] Fig.9A and Fig. 9B A flowchart of another set of memory repair and cleaning methods provided in an embodiment of the present application;

[0078] Fig.10 A flowchart of another memory repair and cleaning method provided in an embodiment of the present application;

[0079] Fig.11 A flowchart of a zygote virtual machine creation method provided in an embodiment of the present application;

[0080] Fig.12 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0081] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. In the description of the embodiments of the present application, unless otherwise specified, " / " means or, for example, A / B can mean A or B; "and / or" in the text is only a description of the association relationship of the associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, "multiple" means two or more than two.

[0082] It should be understood that the terms "first", "second", etc. in the specification, claims and drawings of the present application are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units that are not listed, or may optionally include other steps or units that are inherent to these processes, methods, products or devices.

[0083] Reference to "embodiments" in this application means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described in this application may be combined with other embodiments.

[0084] During the use of electronic devices such as mobile phones and tablets, the Java memory available to applications in these electronic devices is limited. For example, for electronic devices using the Android system, the maximum Java memory available to applications in the electronic device is limited (for example, the default value of the maximum Java memory can be 512MB). It is understandable that Java memory refers to the memory provided to Java objects. The reason why the Java memory available to applications is limited is that excessive use of memory by applications may cause the system to crash or become unstable. The system needs to limit the memory usage of applications to ensure the stability of the system, and the system can limit the memory available to each application to avoid the situation where some applications occupy a large amount of memory and cause other applications to fail to operate normally, and the hardware resources of electronic devices are relatively limited. The system needs to limit the memory of applications to ensure that all applications can operate normally on the device.

[0085] Some applications may have memory leaks after long-term use. That is, after applying for Java memory, the corresponding memory cannot be released normally, causing the Java memory occupied by the application to continue to increase. Once the Java memory occupied by the application approaches or exceeds the Java memory upper limit specified by the system (for example, 512MB), the application will trigger GC for the Block type. In this case, the application GC will become extremely busy and occupy CPU and memory resources, further blocking the execution of Java code, and ultimately causing serious performance problems such as lag and ANR.

[0086] The embodiments of the present application provide a memory repair and cleaning method and related equipment. According to the memory repair and cleaning method, when there is an application with a memory leak, the electronic device can perform memory repair and cleaning on the application with a memory leak without the user being aware of the application with a memory leak. In some embodiments of the present application, the electronic device can first expand the memory of the application when a memory leak occurs, and then perform memory repair and cleaning on the application according to the above method when the memory leak is more serious. This method can effectively avoid problems such as freezes without affecting the user's use of the foreground application, and can also perform memory repair and cleaning after the application retreats to the background, ensuring that the user is unaware of the application, thereby better solving the problem of memory leaks.

[0087] The following first introduces the software structure of the electronic device involved in this application.

[0088] See also Figure 1 , Figure 1 A schematic diagram of the software structure of an electronic device provided in an embodiment of the present application.

[0089] like Figure 1 As shown, the software framework of the electronic device involved in the present application may include an application layer, an application framework layer (framework, FWK), a system library, a runtime, a hardware abstraction layer (HAL) and a kernel layer (kernel).

[0090] The application layer may include a series of application packages. For example, application_1, calendar, gallery, call, Bluetooth, video, music, short message, WLAN and other applications (also referred to as applications). Application_1 may be a system application or a third-party application, which is not limited in this application. For example, application_1 may be a short video application, a live broadcast application, or a news application.

[0091] The application framework layer provides an application programming interface (API) and a programming framework for applications in the application layer. The application framework layer includes some predefined functions. The application framework layer can include a series of system services. System services are modular components that focus on specific functions. The functions provided by the application framework API can communicate with system services to access the underlying hardware. The application framework layer can include a SystemServer (system service) process. The SystemServer process is generated by the zygote process incubation (fork). The SystemServer process is the first process of the zygote process fork. The SystemServer process is responsible for starting and managing the entire application framework layer, including services such as the Activity Manager, Window Manager, Package Manager, and Power Manager. The SystemServer process can include an application information collection module, an application status management module, and a memory repair and cleanup module. The application information collection module is used to collect the process information of the application. For example, the main process and related subprocesses corresponding to the application. The application status management module is used to obtain the status information (i.e., the running status) of the application. In some embodiments of the present application, the running state of the application may include one or more status items of the application (for example, foreground and background states, screen recording, backup, download, small window display, audio and / or video playback, etc.). The memory repair and cleaning module can be used to determine whether the application is in a user-unaware state (hereinafter referred to as the unaware state), and to repair and clean the memory of the application. The unaware state means that the user cannot perceive that the application is running. For example, the application is in the background running state, and it has no corresponding display on the display screen, and there is no background playback. It can be understood that the "repair and cleaning" of the application involved in this application can be understood as destroying the application, or it can be understood as killing the application.

[0092] The application framework layer may also include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, etc. The specific meanings thereof may be referred to in the relevant technical documents and will not be described in detail here.

[0093] The application framework layer may also include a task stack recovery module. The task stack recovery module may be used to restore the interface displayed by the application before it was killed. It is understandable that the task stack recovery module may restore the interface displayed by the application before it was killed to the background. In other words, the process of the application restoring the corresponding interface may not be perceived by the user. In some embodiments of the present application, the task stack recovery module may determine whether to re-pull up and restore the corresponding interface of the killed application based on the priority decision. It is understandable that the priority refers to the priority of the killed application. In some embodiments of the present application, when the priority of the killed application is higher, the task stack recovery module may re-pull up and restore the corresponding interface of the application. It is understandable that the relevant setting rules of the priority can refer to the relevant technical documents, which will not be explained in detail here.

[0094] Runtime is responsible for the scheduling and management of the system. Runtime includes a core library and a virtual machine. Among them, the core library contains two parts: one part is the function that the programming language (for example, the Java language) needs to call, and the other part is the core library of the system. The application layer and the application framework layer run in the virtual machine. The virtual machine executes the programming files (for example, Java files) of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection. It can be understood that the virtual machine can include virtual machine instances corresponding to several processes. For example, the virtual machine instance corresponding to the zygote process (referred to as the zygote virtual machine in this application), the virtual machine instance corresponding to the application_1 process (referred to as the application_1 virtual machine in this application), etc.

[0095] Zygote (incubator) is a very important daemon service in Android. The zygote process corresponds to the zygote virtual machine. All other processes are incubated (forked) by the zygote process. The initial spatial layout of the virtual machines of other processes inherits the spatial layout of the zygote virtual machine. Android applications are written in Java and run in their own independent virtual machines. If each application needs to run and initialize a virtual machine separately when it starts, the system performance will be greatly reduced. Therefore, Android first creates a zygote virtual machine, and then incubates other virtual machine processes through it, and then shares the virtual machine memory and framework layer resources, which greatly improves the startup and running speed of the application.

[0096] Specifically, see Figure 2, the zygote process corresponds to the zygote virtual machine. The zygote virtual machine is the virtual machine instance corresponding to the zygote process. The zygote process can fork the application process (for example, the application_1 process) and the SystemServer process. The application process corresponds to an application virtual machine (for example, the application_1 virtual machine), and the application virtual machine is the virtual machine instance corresponding to the application process. It can be understood that the application process is the process corresponding to the application, and the application runs on the application process. It is worth noting that the application virtual machine inherits the spatial layout of the zygote virtual machine. In simple terms, it can also be understood as the zygote virtual machine forking the application virtual machine.

[0097] It can be understood that each application runs in its own process. Each application process corresponds to its own virtual machine instance. In simple terms, it can be understood that the application runs in a virtual machine (for example, Dalvik / ART virtual machine). For example, application_1 runs in the application_1 process, and the virtual machine instance corresponding to the application_1 process is the application_1 virtual machine. It can also be simply understood that the virtual machine instance corresponding to application_1 is the application_1 virtual machine.

[0098] It is understandable that the specific description of the application_1 virtual machine and the zygote virtual machine can be found below and will not be elaborated here.

[0099] It can be understood that the Dalvik virtual machine is the Android virtual machine used before Android 5.0, and the ART virtual machine is the Android virtual machine used throughout Android 5.0.

[0100] The runtime may also include a process control module. The process control module may be used to control the process. For example, a virtual machine instance corresponding to the zygote process (i.e., the zygote virtual machine) and a virtual machine instance corresponding to the application (e.g., the application_1 virtual machine) may be created.

[0101] The system library may include multiple functional modules, such as the surface manager, media libraries, 3D graphics processing library (e.g., OpenGL ES), and 2D graphics engine (e.g., SGL). The specific meanings and functions of these functional modules can be found in the relevant technical documents and will not be described in detail here.

[0102] The Hardware Abstraction Layer (HAL) is an interface layer between the operating system kernel and the upper-level software, and its purpose is to abstract the hardware. The hardware abstraction layer is an abstract interface driven by the device kernel, which is used to implement the application programming interface that provides access to the underlying device to the higher-level Java API framework. HAL can provide a standard interface to display the device hardware functions to the higher-level Java API framework. HAL contains multiple library modules, such as camera HAL, audio HAL, etc. Each library module implements an interface for a specific type of hardware component. When the system framework layer API requires access to the hardware of a portable device, the operating system will load the library module for the hardware component.

[0103] The kernel layer is the foundation of the Android operating system. The kernel layer is responsible for hardware drivers, networking, power, system security, and memory management. The kernel layer is an intermediate layer between hardware and software, and its role is to pass application requests to the hardware. The kernel layer can include camera drivers, display drivers, camera drivers, audio drivers, and sensor drivers.

[0104] It should be noted that the application provides Figure 1 The software structure diagram of the electronic device shown is only an example and does not limit the specific module division in different layers of the Android operating system. For details, please refer to the introduction of the Android operating system software structure in conventional technology. In addition, the method provided in this application can also be implemented based on other operating systems, and this application will not give examples one by one.

[0105] The following is a detailed introduction to virtual machines and their corresponding memory spaces.

[0106] See also Figure 3A , Figure 3A A schematic diagram of a virtual machine provided in an embodiment of the present application.

[0107] like Figure 3A As shown, a virtual machine may include a Runtime module and a Runtime data area. The Runtime module may be used to manage the memory space in the virtual machine (e.g., the Runtime data area). The Runtime data area may be used to store class file metadata, objects and arrays, as well as method parameter local variables, etc. The Runtime data area may include several Spaces, and the functions of the several Spaces may be different. For example, Figure 3A As shown, the runtime data area may include a Java memory space. The Java memory space refers to the memory space provided for Java objects. The memory corresponding to the Java memory space is the Java memory. It can be understood that Figure 3BAs shown, for the Android operating system, the Java memory space can be RegionSpace (regional space). Of course, for other operating systems, the Java memory space can also be other modules, and this application does not limit this. RegionSpace manages memory slices by evenly allocating 256 kilobyte (KB) regions (regions, which can also be understood as memory blocks). In other words, RegionSpace divides memory resources into fixed-size regions and then allocates them from the regions. In addition, the size of a region is 256KB.

[0108] In some embodiments of the present application, the Runtime module can control several Spaces in the runtime data area to apply for virtual addresses, and establish a mapping relationship between the virtual addresses and the physical addresses. Specifically, in a possible implementation, several Spaces in the runtime data area can call the address management module to apply for virtual addresses. It can be understood that the address management module can be used to implement the mapping relationship between the virtual address and the physical address corresponding to the memory of the Java memory space (for example, RegionSpace). It should be noted that the virtual address involved in this application can be understood as a virtual memory address, and the physical address can be understood as a physical memory address (i.e., RAM memory address). Virtual memory refers to a piece of logical memory virtualized using disk space. Physical memory refers to the address space range that can be expressed by real physical memory (i.e., RAM memory).

[0109] It is understandable that the full name of RAM is Random Access Memory. RAM is also called main memory, which is the internal memory that directly exchanges data with the central processing unit (CPU). It can be read and written at any time (except when refreshed), and the speed is very fast. It is usually used as a temporary data storage medium for operating systems or other running programs. When RAM is working, information can be written (stored) or read (retrieved) from any specified address at any time.

[0110] It should be noted that the runtime data area may include not only the Java memory space (eg, RegionSpace) but also other Spaces. Figure 4As shown, the runtime data area may include RegionSpace, LargeObjectSpace (large object space), ZygoteSpace (incubator space), ImageSpace (image file space) and jit code cache (just-in-time compiled code cache area), etc. The specific meanings and functions of these memory spaces can be referred to in relevant technical documents, which will not be elaborated here.

[0111] It can be understood that the runtime data area can also control other modules such as the stack and method area. The stack is a memory instruction area used to store basic data types, instruction codes, and constants. The method area is similar to the runtime data area. It is a memory area shared by each thread and can be used to store type information, constants, static variables, and code cache compiled by the just-in-time compiler that have been loaded by the virtual machine.

[0112] It is understandable that the memory allocated in the runtime data area is managed by the GC mechanism of the virtual machine. It is understandable that the relevant description of GC can refer to the above and related technical documents, and will not be repeated here.

[0113] It is understandable that the Runtime module may also include an execution engine, a native library interface, a native method library, and a Java thread, etc. This application does not limit the specific structure of the Runtime module.

[0114] It is understandable that the virtual machine mentioned in this application may be a Java Virtual Machine (JVM).

[0115] The following introduces the zygote virtual machine and its incubation process.

[0116] Understandable, such as Figure 5 As shown, this application records the Runtime module in the zygote virtual machine as Runtime module_1, the runtime data area in the zygote virtual machine as Runtime data area_1, and the Java memory space in the zygote virtual machine as RegionSpace_1.

[0117] It is understandable that the zygote process can create an application process and a SystemServer process through fork. The application process and the SystemServer process can obtain a copy of a virtual machine instance from the zygote process. That is, the application process and the System Server process can obtain a virtual machine instance copied from the virtual machine instance corresponding to the zygote process (i.e., the zygote virtual machine). In other words, the electronic device can obtain the virtual machine instance corresponding to other processes by copying the zygote virtual machine.

[0118] For example, Figure 6 As shown, the electronic device can fork the process corresponding to application_1 (i.e., application_1 process) through the zygote process. The virtual machine instance corresponding to the application_1 process (i.e., application_1 virtual machine) can be copied (or copied) by the virtual machine instance corresponding to the zygote process (i.e., zygote virtual machine). In other words, the application_1 virtual machine in the initial state (i.e., the application_1 virtual machine that has just been created) is the same as the zygote virtual machine. For ease of description, this application records the Runtime module in the application_1 virtual machine as Runtime module_2, the runtime data area in the application_1 virtual machine as runtime data area_2, and the Java memory space in the application_1 virtual machine as RegionSpace_2. It can be understood that for the application_1 virtual machine in the initial state, the Runtime module_2 is the same as the Runtime module_1, the runtime data area_2 is the same as the runtime data area_1, and the RegionSpace_2 is the same as the RegionSpace_1. In some embodiments of the present application, after the application_1 virtual machine is created, the application_1 can set the application_1 virtual machine according to actual needs (for example, change the memory space layout in the application_1 virtual machine), and this application does not limit this. It is understandable that the zygote process can also fork other application processes (for example, the process corresponding to the SMS application). Figure 6 As shown, the virtual machine instance corresponding to the SMS application (i.e., the SMS virtual machine) can be copied from the zygote virtual machine. Similarly, in the initial state, the Runtime module_3 and the Runtime module_1 in the SMS virtual machine are the same, the runtime data area_3 and the runtime data area_1 are the same, and the RegionSpace_3 and the RegionSpace_1 are the same.

[0119] It is understandable that the zygote process can also fork other processes (for example, other application processes such as music and video), and this application will not give examples one by one.

[0120] It is understandable that in the Android operating system, the Java memory space in the zygote virtual machine may be RegionSpace, however, in other operating systems, the Java memory space in the zygote virtual machine may not be RegionSpace, but other modules, and this application does not impose any restrictions on this.

[0121] The following describes a memory repair and cleaning method provided by an embodiment of the present application.

[0122] See also Figure 7 , Figure 7 This is a flowchart of a memory repair and cleaning method provided in an embodiment of the present application. The method may include but is not limited to the following steps:

[0123] S1: The electronic device receives an instruction to cold-start Application_1. In response to the instruction, the electronic device incubates an Application_1 virtual machine based on the zygote virtual machine and monitors the memory usage of the Java memory space in the Application_1 virtual machine. The Application_1 virtual machine is a virtual machine instance corresponding to the Application_1 process.

[0124] The user can cold start Application_1 by touch, sound, etc. Correspondingly, the electronic device can receive an instruction to cold start Application_1, and in response to the instruction, the electronic device can hatch the Application_1 virtual machine based on the zygote virtual machine. After the Application_1 virtual machine is hatched by the zygote virtual machine, the electronic device can further monitor the memory occupancy of the Java memory space in the Application_1 virtual machine. It can be understood that the Application_1 virtual machine refers to the virtual machine instance corresponding to the Application_1 process. The initial memory space layout of the Application_1 virtual machine is consistent with the memory space layout in the created zygote virtual machine.

[0125] In some embodiments of the present application, the electronic device may check the occupied memory of the Java memory space in the application_1 virtual machine every certain period of time (for example, 1 minute).

[0126] In some embodiments of the present application, the electronic device may check the occupied memory of the Java memory space in the application_1 virtual machine after each GC.

[0127] It is understandable that the electronic device can also monitor the memory usage of the Java memory space in the application_1 virtual machine in other ways, and this application does not limit this.

[0128] It is understandable that when an application is started, there is no process of the application in the background of the electronic device. At this time, the system will recreate a new process and assign it to the application. This startup method is called a cold start (the application process does not exist in the background).

[0129] It is understandable that before executing step S1, the electronic device can create and start the zygote virtual machine. Specifically, the user can trigger the start of the electronic device by long pressing the power button, etc., and accordingly, the electronic device can receive an instruction to start the electronic device, and in response to the instruction, the electronic device can create and start the zygote virtual machine. The specific implementation method of creating and starting the zygote virtual machine can be referred to below, which will not be described in detail here.

[0130] S2: When the occupied memory of the Java memory space in the virtual machine of Application_1 is greater than the memory threshold_1, and the duration of Application_1 residing in the background is greater than the duration threshold_1, the electronic device determines whether Application_1 is in an unaware state.

[0131] It is understandable that the electronic device can monitor the memory usage of the Java memory space in the application_1 virtual machine. When the occupied memory of the Java memory space in the application_1 virtual machine is greater than the memory threshold_1, and the time that the application_1 resides in the background is greater than the time threshold_1, the electronic device can determine whether the application_1 is in an unaware state. It is understandable that the unaware state means that the user has no perception of the application_1. The specific description of the unaware state can be found below and will not be elaborated here.

[0132] In some embodiments of the present application, if the electronic device detects that the occupied memory of the Java memory space in the virtual machine of Application_1 is greater than the memory threshold_1, the electronic device can determine whether Application_1 is in the foreground or in the background. If Application_1 is in the foreground, the electronic device waits for Application_1 to switch from the foreground to the background, and the duration of Application_1 residing in the background is greater than the duration threshold_1, and then determines whether Application_1 is in an unaware state. If Application_1 is in the background, the electronic device determines whether the duration of Application_1 residing in the background is greater than the duration threshold_1. If the duration of Application_1 residing in the background is greater than the duration threshold_1, the electronic device determines whether Application_1 is in an unaware state. If the duration of Application_1 residing in the background is not greater than the duration threshold_1, the electronic device waits for the duration of Application_1 residing in the background to be greater than the duration threshold_1, and then determines whether Application_1 is in an unaware state.

[0133] It is understandable that the memory threshold_1 and the duration threshold_1 can be set according to actual needs, and the present application does not limit this. In some embodiments of the present application, the memory threshold_1 is 600 megabytes (MB). In some embodiments of the present application, the duration threshold_1 is 30 seconds (s).

[0134] In some embodiments of the present application, the electronic device performs memory cleanup for a specific application. In a possible implementation, the electronic device performs step S2 only when application_1 is a preset application_1. That is, when application_1 is a preset application_1, and the occupied memory of the Java memory space in the application_1 virtual machine is greater than the memory threshold_1, and the duration of application_1 residing in the background is greater than the duration threshold_1, the electronic device determines whether application_1 is in an unaware state.

[0135] In a possible implementation manner, application_1 is a preset application_1, which may specifically include: application_1 is an application in the preset application list_1.

[0136] In another possible implementation manner, application_1 is a preset application_1, which may specifically include: application_1 is an application of preset category_1.

[0137] It is understandable that the preset application list / preset category can be set according to actual needs, and the present application does not limit this. In some embodiments of the present application, the preset application list / preset category can be set based on the historical memory usage of each application. For example, the preset application list_1 may include: for the memory usage after a cold start, the applications whose memory usage rate exceeds b% and reaches c%*a the number of times. It is understandable that a, b and c can be set according to actual needs, and the present application does not limit this. For example, a can be 5, b can be 90, and c can be 80.

[0138] S3: The electronic device performs memory repair and cleaning on application_1.

[0139] If the electronic device determines that application_1 is in an unaware state, the electronic device performs memory repair and cleanup on application_1, that is, destroys application_1. Specifically, the electronic device may clear all processes and threads related to application_1.

[0140] S4: The electronic device determines whether it is determined for M consecutive times that the application_1 is not in the unaware state, where M is a positive integer.

[0141] If the electronic device determines that application_1 is not in an unaware state, that is, application_1 is in a perceptible state (that is, the user can perceive that application_1 is running), the electronic device determines whether the electronic device has determined that application_1 is not in an unaware state for M consecutive times. If the electronic device determines that the electronic device has determined that application_1 is not in an unaware state for M consecutive times, the electronic device executes step S6 (that is, canceling the memory repair and cleaning of application_1). If the electronic device determines that the electronic device has not determined that application_1 is not in an unaware state for M consecutive times, the electronic device executes step S5 and then executes step S2. It can be understood that M can be a positive integer. For example, M=3.

[0142] S5: The electronic device waits for T1.

[0143] If the electronic device determines that the electronic device has not determined for M consecutive times that application_1 is not in the unaware state, the electronic device waits for T1 before executing step S2.

[0144] It is understandable that T1 can be set according to actual needs, and this application does not limit this. For example, T1 can be 10s.

[0145] S6: The electronic device cancels the memory repair and cleaning of application_1.

[0146] If the electronic device determines that the electronic device has determined for M consecutive times that application_1 is not in an unaware state, the electronic device cancels the memory repair and cleaning of application_1.

[0147] It should be noted that in some embodiments of the present application, after the electronic device executes step S2, if the electronic device determines that application_1 is in an unaware state, the electronic device may execute step S6. In this case, the electronic device does not need to execute steps S4 and S5, nor does it need to execute steps S2 and S3.

[0148] It should also be noted that, in some embodiments of the present application, before the electronic device performs memory repair and cleanup on application_1, if the occupied memory of the Java memory space in the application_1 virtual machine is less than the memory threshold_2, the electronic device cancels the memory repair and cleanup on application_1. In some other embodiments of the present application, before the electronic device performs memory repair and cleanup on application_1, if application_1 is destroyed, the electronic device cancels the memory repair and cleanup on application_1.

[0149] It is understandable that the memory threshold_2 can be set according to actual needs, and this application does not limit this. For example, the memory threshold_2 can be 450MB.

[0150] Combine the following Figure 8 A memory repair and cleaning method provided in an embodiment of the present application is further described.

[0151] See also Figure 8 , Figure 8 A flowchart of another memory repair and cleaning method provided in an embodiment of the present application. The method may include but is not limited to the following steps:

[0152] S101: The electronic device receives an instruction to start the electronic device.

[0153] It is understandable that the user can trigger the start-up of the electronic device by long pressing the power button, etc. Accordingly, the electronic device can receive an instruction to start the electronic device. The instruction is used to trigger the electronic device to create a zygote virtual machine.

[0154] S102: In response to the instruction to start the electronic device received by the electronic device, the electronic device creates and starts a zygote virtual machine.

[0155] In response to the instruction to start the electronic device, the electronic device can create a zygote virtual machine, layout the memory space in the zygote virtual machine, and start the zygote virtual machine after the creation is completed. For details, please refer to the following and will not be described in detail here.

[0156] In some embodiments of the present application, the electronic device may apply for a spare virtual address segment during the process of creating a zygote virtual machine so as to achieve subsequent memory expansion. For details, please refer to the following text and will not be described in detail here.

[0157] S103: The electronic device receives an instruction to cold-start application_1.

[0158] The user can cold start the application_1 by touch, sound, etc. Accordingly, the electronic device can receive an instruction to cold start the application_1. The instruction is used to trigger the start of the application_1.

[0159] S104: In response to the instruction of cold-starting Application_1 received by the electronic device, the electronic device incubates the Application_1 virtual machine based on the zygote virtual machine.

[0160] In response to the instruction to cold-start application_1, the electronic device may start to start application_1. Specifically, the electronic device may incubate application_1 virtual machine based on zygote virtual machine. Application_1 virtual machine is a virtual machine instance corresponding to application_1 process.

[0161] It can be understood that, since the Application_1 virtual machine is hatched by the Zygote virtual machine, the initial memory of the Java memory space in the Application_1 virtual machine is the same as the memory of the Java memory space in the Zygote virtual machine.

[0162] In some embodiments of the present application, the electronic device may apply for a spare virtual address segment during the process of creating a zygote virtual machine. In this case, since the application_1 virtual machine is incubated based on the zygote virtual machine, the application_1 virtual machine can subsequently implement memory expansion based on the spare virtual address segment.

[0163] S105: The Application_1 virtual machine monitors the memory usage of the Java memory space in the Application_1 virtual machine.

[0164] It can be understood that after the incubation of the application_1 virtual machine is completed, the memory usage of the Java memory space therein can be monitored.

[0165] In some embodiments of the present application, the Application_1 virtual machine in the electronic device may check the occupied memory of the Java memory space in the Application_1 virtual machine every certain period of time (for example, 1 minute).

[0166] In some embodiments of the present application, the Application_1 virtual machine in the electronic device can check the occupied memory of the Java memory space in the Application_1 virtual machine once after each GC.

[0167] It is understandable that the Application_1 virtual machine can also monitor the memory usage of the Java memory space in the Application_1 virtual machine in other ways, and this application does not limit this.

[0168] S106: When preset condition 1 is met, the application 1 virtual machine sends a memory leak message to the SystemServer process.

[0169] When the preset condition _1 is met, the application_1 virtual machine can send a memory leak message to the SystemServer process. Correspondingly, the SystemServer process can receive the memory leak message sent by the application_1 virtual machine. The memory leak message is used to indicate that the remaining Java memory in the application_1 virtual machine is insufficient. The memory leak message can carry the package name and process pid of application_1.

[0170] It can be understood that pid refers to the process identification in the operating system. Each process has a unique pid. As soon as the application is run, the system will automatically assign a pid to the process corresponding to the program. The pid is assigned by the system when the process is running and does not represent a specific process. When the process is running, its pid will not change, but after the process terminates, its pid will be recycled by the system. The system may reallocate the recycled pid to other newly running programs.

[0171] In some embodiments of the present application, satisfying the preset condition_1 may specifically include: the occupied memory of the Java memory space in the application_1 virtual machine is greater than the memory threshold_1.

[0172] In some embodiments of the present application, satisfying preset condition_1 may specifically include: the occupied memory of the Java memory space in the application_1 virtual machine is greater than the memory threshold_1, and the application_1 is the preset application_1.

[0173] In some embodiments of the present application, before executing step S106, the application_1 virtual machine can implement memory expansion based on the spare virtual address segment to avoid problems such as freezing.

[0174] S107: When the duration of application_1 residing in the background is greater than duration threshold_1, the SystemServer process determines whether application_1 is in an unaware state.

[0175] After the SystemServer process receives the memory leak message sent by the Application_1 virtual machine, it can determine whether Application_1 is in the foreground or in the background. If Application_1 is in the foreground, the SystemServer process waits for Application_1 to switch from the foreground to the background, and after the length of time that Application_1 resides in the background is greater than the duration threshold_1, the SystemServer process determines whether Application_1 is in an unaware state. If Application_1 is in the background, the SystemServer process determines whether the length of time that Application_1 resides in the background is greater than the duration threshold_1. If the length of time that Application_1 resides in the background is greater than the duration threshold_1, the electronic device determines whether Application_1 is in an unaware state. If the length of time that Application_1 resides in the background is not greater than the duration threshold_1, the electronic device waits for the length of time that Application_1 resides in the background to be greater than the duration threshold_1 before determining whether Application_1 is in an unaware state.

[0176] It is understandable that the specific description of the unaware state can be found below and will not be elaborated here.

[0177] S108: When application_1 is in an unaware state, the SystemServer process performs memory repair and cleanup on application_1.

[0178] If the SystemServer process determines that Application_1 is in an unaware state, the SystemServer process performs memory repair and cleanup on Application_1.

[0179] In some embodiments of the present application, if the SystemServer process determines that Application_1 is not in an unaware state, that is, Application_1 is in a perceptible state, the SystemServer process cancels the memory repair and cleanup of Application_1.

[0180] In some embodiments of the present application, if the SystemServer process determines that Application_1 is not in an unaware state, that is, Application_1 is in a perceptible state, the SystemServer process determines again whether Application_1 is in an unaware state after an interval of T1. If the SystemServer process determines that Application_1 is in an unaware state, the SystemServer process performs memory repair and cleanup on Application_1. However, if the SystemServer process determines that Application_1 is not in an unaware state, the SystemServer process may determine again whether Application_1 is in an unaware state after an interval of T1. It should be noted that the SystemServer process determines whether Application_1 is in an unaware state for a maximum of M times. If the SystemServer process determines that Application_1 is not in an unaware state for M consecutive times, the SystemServer process cancels the memory repair and cleanup of Application_1.

[0181] It should be noted that, in some embodiments of the present application, after the Application_1 virtual machine executes step S106, it can continue to monitor the memory occupancy of the Java memory space in the Application_1 virtual machine. Once the occupied memory of the Java memory space in the Application_1 virtual machine is less than the memory threshold_2, the Application_1 virtual machine can send a corresponding message to the SystemServer process to inform the SystemServer process that the Java memory occupancy of Application_1 has been restored. If the SystemServer process has not started to perform memory repair and cleanup on Application_1 when receiving the corresponding message, the SystemServer process can cancel the memory repair and cleanup on Application_1.

[0182] It should also be noted that, in some embodiments of the present application, before the SystemServer process performs memory repair and cleanup on Application_1, if Application_1 is destroyed, the SystemServer process cancels the memory repair and cleanup on Application_1.

[0183] Combine the following Fig.9A and Fig. 9B A specific implementation of the above embodiment is described.

[0184] 1. Application_1 virtual machine detects a memory leak and reports it to the SystemServer process (such as Fig.9A (shown)

[0185] S201: The process control module receives an instruction to start the electronic device.

[0186] It is understandable that the electronic device can detect the user operation of starting the electronic device (for example, long pressing the power button on the electronic device). Specifically, the user can long press the power button on the electronic device, and the process control module in the electronic device can receive the instruction to start the electronic device.

[0187] S202: The process control module creates and starts the zygote virtual machine. The zygote virtual machine is a virtual machine instance corresponding to the zygote process. The zygote virtual machine includes a Runtime module_1 and a runtime data area_1. The runtime data area_1 includes RegionSpace_1.

[0188] After the electronic device receives the instruction to start the electronic device, in response to the instruction to start the electronic device, the process control module in the electronic device can create and start the zygote virtual machine. Specifically, after the process control module receives the instruction to start the electronic device, it can create and start the zygote virtual machine. It can be understood that the zygote virtual machine is a virtual machine instance corresponding to the zygote process. The zygote virtual machine includes a Runtime module_1 and a runtime data area_1. The runtime data area_1 includes RegionSpace_1. The relevant description of the zygote virtual machine can be found above and will not be elaborated here.

[0189] S203: The process control module receives an instruction to cold start application_1.

[0190] The user can trigger a cold start of application_1. For example, the user can trigger a cold start of application_1 by clicking the application icon of application_1. Accordingly, the process control module can receive an instruction to cold start application_1. It is understandable that the relevant meaning of cold start can be referred to above and related technical documents, and will not be explained here.

[0191] S204: The process control module incubates the application_1 virtual machine based on the zygote virtual machine. The application_1 virtual machine is a virtual machine instance corresponding to the application_1 process. The application_1 virtual machine inherits the spatial layout of the zygote virtual machine. The application_1 virtual machine includes the Runtime module_2 and the runtime data area_2. The runtime data area_2 includes RegionSpace_2.

[0192] It is understandable that the process control module can fork the application_1 process through the zygote process. Specifically, the process control module can copy (i.e., replicate) the virtual machine instance corresponding to the zygote process (i.e., the zygote virtual machine) as the virtual machine instance corresponding to the application_1 process (i.e., the application_1 virtual machine). Correspondingly, the Runtime module_2 and the runtime data area_2 in the application_1 virtual machine are created. Among them, the runtime data area_2 includes RegionSpace_2.

[0193] It can be understood that the application_1 virtual machine inherits the spatial layout of the zygote virtual machine, which specifically means that the spatial layout of the application_1 virtual machine incubated based on the zygote virtual machine is the same as the spatial layout of the zygote virtual machine. In other words, the application_1 virtual machine in the initial state is the same as the zygote virtual machine. The relevant description can be referred to in the context and will not be elaborated here.

[0194] S205: Runtime module_2 monitors the memory of RegionSpace_2.

[0195] After the fork of the virtual machine of Application_1 is completed, the Runtime module_2 in Application_1 can monitor the memory of RegionSpace_2. Specifically, the Runtime module_2 can monitor the occupied memory of RegionSpace_2.

[0196] In some embodiments of the present application, Runtime module_2 may check the occupied memory of RegionSpace_2 every certain period of time (for example, 1 minute).

[0197] In some embodiments of the present application, Runtime module_2 may check the occupied memory in RegionSpace_2 after each GC.

[0198] S206: When the preset condition 1 is met, the Runtime module 2 sends a memory leak message to the System Server. The memory leak message carries the package name of the application 1.

[0199] When the preset condition 1 is met, the Runtime module 2 in the electronic device can send a memory leak message to the SystemServer process. Correspondingly, the SystemServer process can receive the memory leak message sent by the Runtime module 2.

[0200] In some embodiments of the present application, the memory leak message may also carry the process pid.

[0201] It is understandable that the relevant description of preset condition_1 and memory leak message can be referred to above and will not be elaborated here.

[0202] 2. The SystemServer process performs memory repair and cleanup on application_1 (such as Fig. 9B (shown)

[0203] S207: The memory repair and cleaning module receives the memory leak message.

[0204] After the Runtime module_2 sends the memory leak message to the SystemServer process, the memory leak message can be received by the memory repair and cleaning module in the SystemServer process.

[0205] S208: The memory repair and cleaning module determines whether Application_1 is in the foreground.

[0206] After receiving the memory leak message sent by Runtime module_2, the memory repair and cleaning module in the SystemServer process can determine whether application_1 is in the foreground. If application_1 is in the foreground, the memory repair and cleaning module can execute steps S209-S211. If application_1 is in the background, the memory repair and cleaning module can execute steps S212-S214.

[0207] In some embodiments of the present application, the memory repair and cleaning module can call the corresponding interface to determine whether application_1 is running in the foreground or in the background.

[0208] S209: When Application_1 is in the foreground, the memory repair and cleaning module instructs the application information collection module to monitor the foreground-background switching event of Application_1.

[0209] If the memory repair and cleaning module determines that application_1 is in the foreground, the memory repair and cleaning module can instruct the application information collection module in the SystemServer process to monitor the foreground and background switching event of application_1. It can be understood that the foreground and background switching event of application_1 refers to the switching of application_1 from the foreground running state to the background running state.

[0210] In some embodiments of the present application, after the electronic device is started, the zygote process is created and started, the zygote process can incubate and generate a SystemServer process. After the SystemServer process is generated, the threads in the SystemServer process can initialize parameters. For example, the memory repair cleaning module in the SystemServer process can initialize parameters. It is understandable that after the memory repair cleaning module initializes the parameters, the memory repair cleaning module can register the application foreground and background switching event with the application information collection module. It is understandable that after the memory repair cleaning module registers the application foreground and background switching event with the application information collection module, the memory repair cleaning module has the ability to monitor the switching events of the foreground running state and the background running state of the application through the application information collection module (hereinafter referred to as the foreground and background switching events). It should be noted that the application information collection module can monitor the foreground and background switching events of multiple applications including application_1 in the electronic device. Specifically, when the memory repair cleaning module determines that application_1 is in the foreground, the memory repair cleaning module can use the ability to monitor the foreground and background switching events of the application through the application information collection module to determine whether there is a foreground and background switching event for application_1.

[0211] S210: The memory repair and cleaning module monitors the foreground and background switching event of application_1 through the application information collection module.

[0212] In some embodiments of the present application, if application_1 switches from the foreground to the background, the memory repair and cleaning module can monitor the presence of a foreground-background switching event of application_1 through the application information collection module. That is, the presence of a foreground-background switching event for application_1 can indicate that application_1 switches from the foreground to the background.

[0213] S211: The memory repair and cleaning module sends a handle message_1 to the memory repair and cleaning module. The handle message_1 is a handle message sent with a delay of T2.

[0214] After receiving the application_1 foreground and background switching message sent by the application information collection module, the memory repair and cleaning module can send a handle message_1 to itself. The handle message_1 is a handle message sent with a delay of T2. In other words, the memory repair and cleaning module can delay sending the handle message by T2.

[0215] It is understandable that T2 can be set according to actual needs, and the present application does not limit this. For example, T2 can be 30s. It is understandable that T2 can be the "duration threshold_1" mentioned above. In some embodiments of the present application, T2 can be greater than the duration threshold_1.

[0216] It can be understood that the handle mechanism is a message passing mechanism in the Android system. The handler mechanism can be used for communication between threads of the same process. For the convenience of description, the messages sent based on the handle mechanism are recorded as handle messages in this application (for example, handle message_1, handle message_2 and handle message_3).

[0217] S212: When application_1 is in the background, the memory repair and cleaning module determines whether the time duration for which application_1 resides in the background exceeds T2.

[0218] If the memory repair and cleaning module determines that application_1 is in the background, the memory repair and cleaning module can obtain the length of time that application_1 resides in the background, and determine whether the length of time that application_1 resides in the background exceeds T2.

[0219] In some embodiments of the present application, the memory repair and cleaning module can call the corresponding interface to obtain the length of time that application_1 resides in the background.

[0220] S213: If the duration of application_1 residing in the background exceeds T2, the memory repair and cleaning module sends a handle message_2 to the memory repair and cleaning module. The handle message_2 is an immediate handle message.

[0221] If the duration of application_1 residing in the background exceeds T2, the memory repair and cleaning module can send a handle message_2 to itself. The handle message_2 is an immediate handle message. That is, when the memory repair and cleaning module determines that the duration of application_1 residing in the background exceeds T2, the handle message can be sent to itself immediately without delay.

[0222] S214: If the duration of application_1 residing in the background does not exceed T2, handle message_3 is sent. Handle message_2 is a handle message sent with a delay of (T2-T3). T3 is the duration of application_1 residing in the background.

[0223] If the duration of application_1 residing in the background does not exceed T2, the memory repair and cleaning module can send a handle message_3 to itself. The handle message_2 is a handle message sent with a delay of (T2-T3). In other words, if the memory repair and cleaning module determines that the duration of application_1 residing in the background does not exceed T2, it can delay sending a handle message to itself by (T2-T3). Among them, T3 is the duration of application_1 residing in the background.

[0224] S215: The memory repair and cleaning module obtains relevant information of the related processes of Application_1 from the application information collection module.

[0225] After the memory repair and cleaning module receives the handle message (for example, handle message_1, or handle message_2, or handle message_3), it can obtain relevant information of the related processes of application_1 from the application information collection module.

[0226] In some embodiments of the present application, after the electronic device is started, the memory repair and cleaning module in the SystemServer process can initialize parameters. For details, please refer to the above, which will not be described in detail here. It is understandable that after the memory repair and cleaning module initializes the parameters, the memory repair and cleaning module can register the application process information collection event with the application information collection module. It is understandable that after the memory repair and cleaning module registers the application process information collection event with the application information collection module, the application information collection module has the ability to collect relevant information of the relevant processes of the application (for example, process name, relevant file name, etc.). It should be noted that the application information collection module can collect relevant information of the relevant processes of multiple applications including application_1 in the electronic device. Specifically, after the memory repair and cleaning module receives the handle message, the memory repair and cleaning module can use the ability of the application information collection module to collect relevant information of the relevant processes of the application. That is, the application information collection module can collect relevant information of the relevant processes of application_1.

[0227] In some embodiments of the present application, the memory repair and cleaning module can obtain relevant information of all related processes of application_1 (for example, the main process of application_1, child processes, etc.) from the application information collection module.

[0228] S216: The memory repair and cleaning module obtains the current running status of Application_1 from the application status management module.

[0229] After the memory repair and cleaning module receives the handle message (for example, handle message_1, or handle message_2, or handle message_3), it can obtain the current running state of application_1 from the application state management module.

[0230] In some embodiments of the present application, the running state may include any one or more of the following state items: foreground and background state, screen recording, backup, download, small window display, playing audio and / or video, etc. It is understandable that the running state may include more state items, and the present application will not cite them one by one.

[0231] S217: The memory repair and cleaning module determines whether there is a perceptible status item in the current running state of application_1.

[0232] The memory repair and cleaning module can determine whether there is a perceptible status item in the current running state of the acquired application_1. It can be understood that the perceptible status item refers to the status of the application that can be perceived by the user. The perceptible status item may include any one or more of the following: small window display, downloading, and background playback. Of course, the perceptible status item may also include other status items, which are not limited in this application.

[0233] S218: If there is no perceptible status item in the current running state of Application_1, the memory repair and cleaning module performs memory repair and cleaning on Application_1 based on the relevant information of the related processes of Application_1.

[0234] If there is no perceptible status item in the current running state of application_1, the memory repair and cleaning module can repair and clean application_1 based on the relevant information of the related processes of application_1 (for example, process name, related file name, etc.). It can be understood that the memory repair and cleaning module repairs and cleans application_1 based on the relevant information of the related processes of application_1, which can specifically include: the memory repair and cleaning module clears all related processes of application_1 based on the relevant information of the related processes of application_1. That is, destroying application_1.

[0235] S219: If there is a perceptible status item in the current running state of Application_1, the memory repair and cleaning module re-acquires the current running state of Application_1 from the application state management module after an interval T1.

[0236] If there is a perceptible status item in the current running state of application_1, the memory repair and cleaning module can re-acquire the current running state of application_1 from the application state management module after an interval of T1. It can be understood that after the memory repair and cleaning module re-acquires the current running state of application_1, it can execute step S217 again, that is, determine whether there is a perceptible status item in the current running state of application_1. It should be noted that when the memory repair and cleaning module executes step S217 again, it is aimed at the re-acquired current running state of application_1.

[0237] S220: If there are perceptible status items in the current running status of Application_1 obtained for M consecutive times, the memory repair and cleaning module does not perform memory repair and cleaning on Application_1.

[0238] If the current running status of application_1 obtained by the memory repair and cleaning module for M consecutive times contains perceptible status items, the memory repair and cleaning module does not perform memory repair and cleaning on application_1, that is, cancels the memory repair and cleaning of application_1 this time.

[0239] It should be noted that, in some embodiments of the present application, after the application_1 virtual machine executes step S206, the memory occupancy of the Java memory space in the application_1 virtual machine can continue to be monitored. Once the occupied memory of the Java memory space in the application_1 virtual machine is less than the memory threshold_2, the application_1 virtual machine can send a corresponding message to the memory repair and cleaning module in the SystemServer process to inform that the Java memory occupancy of the application_1 has been restored. If the memory repair and cleaning module has not started to perform memory repair and cleaning on the application_1 when receiving the corresponding message, the memory repair and cleaning module can cancel the memory repair and cleaning of the application_1.

[0240] It should also be noted that, in some embodiments of the present application, before the memory repair and cleaning module performs memory repair and cleaning on application_1, if application_1 is destroyed, the memory repair and cleaning module cancels the memory repair and cleaning of application_1. In this case, after the memory repair and cleaning module initializes the parameters, the memory repair and cleaning module can register the application destruction event so that the memory repair and cleaning module can subsequently obtain the application_1 destruction event.

[0241] In some embodiments of the present application, the Application_1 virtual machine may perform memory expansion before reporting the memory leak to the SystemServer process.

[0242] Combine the following Fig.10 and Fig. 9B Another specific implementation of the above embodiment is introduced.

[0243] First of all, it should be noted that electronic equipment performs Fig.10 After following the steps shown, you can continue with Fig. 9B As mentioned above, Fig. 9B The contents shown are described in detail and will not be described here. Fig. 9B The content shown.

[0244] S301: The process control module receives an instruction to start the electronic device.

[0245] It is understandable that the specific implementation of step S301 can refer to the relevant description of step S201, which will not be repeated here.

[0246] S302: The process control module creates and starts the zygote virtual machine. The zygote virtual machine is a virtual machine instance corresponding to the zygote process. The zygote virtual machine includes the Runtime module_1 and the runtime data area_1. The runtime data area_1 includes RegionSpace_1. The memory size corresponding to the virtual address segment used by RegionSpace_1 is the default memory of RegionSpace_1, and RegionSpace_1 corresponds to a spare virtual address segment.

[0247] After the electronic device receives the instruction to start the electronic device, in response to the instruction to start the electronic device, the process control module in the electronic device can create and start the zygote virtual machine. Specifically, after the process control module receives the instruction to start the electronic device, it can create and start the zygote virtual machine.

[0248] It should be noted that, in the process of creating a zygote virtual machine, RegionSpace_1 in the zygote virtual machine can apply for a backup virtual address segment. Please refer to the following for the specific implementation method, which will not be described in detail here.

[0249] S303: The process control module receives an instruction to cold start application_1.

[0250] It is understandable that the specific implementation of step S303 can refer to the relevant description of step S203, which will not be repeated here.

[0251] S304: The process control module incubates the application_1 virtual machine based on the zygote virtual machine. The application_1 virtual machine is a virtual machine instance corresponding to the application_1 process. The application_1 virtual machine inherits the spatial layout of the zygote virtual machine. The application_1 virtual machine includes the Runtime module_2 and the runtime data area_2. The runtime data area_2 includes RegionSpace_2. The memory size corresponding to the virtual address segment used by RegionSpace_2 is the default memory of RegionSpace_1, and RegionSpace_2 corresponds to a spare virtual address segment.

[0252] It can be understood that since the application_1 virtual machine inherits the spatial layout of the zygote virtual machine, in the initial state (i.e., the application_1 virtual machine is just created), the memory size corresponding to the virtual address segment used by RegionSpace_2 is the default memory of RegionSpace_1, and RegionSpace_2 has a corresponding spare virtual address segment.

[0253] It is understandable that the specific implementation of step S304 can refer to the relevant description of step S204, which will not be repeated here.

[0254] S305: Runtime module_2 monitors the memory of RegionSpace_2.

[0255] It is understandable that the specific implementation of step S305 can refer to the relevant description of step S205, which will not be repeated here.

[0256] S306: When preset condition_2 is met, Runtime module_2 controls RegionSpace_2 to expand the memory of RegionSpace_2 based on the spare virtual address segment.

[0257] When preset condition _2 is met, Runtime module _2 may control RegionSpace_2 to expand the memory of RegionSpace_2 based on the spare virtual address segment.

[0258] In some embodiments of the present application, satisfying preset condition_2 may specifically include any one or more of the following: RegionSpace_2 memory satisfies condition_1, application_1 satisfies condition_2, and the unoccupied memory of the operating system of the electronic device satisfies condition_3.

[0259] In some embodiments of the present application, the memory of RegionSpace_2 satisfies condition_1, which may specifically include any one or more of the following: the occupied memory in RegionSpace_2 exceeds the memory threshold_3, the occupied memory of RegionSpace_2 over a period of time exceeds the memory threshold_3, the occupied memory in RegionSpace_2 after n consecutive GCs exceeds the memory threshold_3, and the growth rate of the occupied memory in RegionSpace_2 exceeds r%.

[0260] It is understandable that the memory threshold _3, r and n can be set according to actual needs, and the present application does not limit this. For example, the memory threshold _3 can be 480MB. In some embodiments of the present application, the memory threshold _3 can be less than or equal to the preset memory threshold. In some embodiments of the present application, the memory threshold _3 can be f% of the preset memory threshold. It is understandable that f can be set according to actual needs, and the present application does not limit this. For example, f can be 80. In some embodiments of the present application, r can be 30. n can be a positive integer. For example, n can be 5.

[0261] In some embodiments of the present application, application_1 satisfies condition_2, which may specifically include: application_1 is preset application_2. In one possible implementation, application_1 is preset application_2, which may specifically include: application_1 is an application in preset application list_2. In another possible implementation, application_1 is preset application_2, which may specifically include: application_1 is an application of preset category_2.

[0262] It is understandable that the setting method of the preset application list / preset category can refer to the above and will not be repeated here.

[0263] It should be noted that the preset application list_2 and the preset application list_1 can be completely the same or partially the same. Similarly, the preset category_2 and the preset category_1 can also be completely the same or partially the same. In some embodiments of the present application, application_1 can correspond to multiple categories. In this case, preset category_1 and preset category_2 can be completely different. It is understandable that the relevant descriptions of the preset application list and the preset category can be referred to above and will not be repeated here.

[0264] In some embodiments of the present application, the unoccupied memory of the operating system of the electronic device satisfies condition_3, which may specifically include any one or more of the following: the unoccupied memory of the operating system of the electronic device is greater than memory threshold_4, and the ratio of the unoccupied memory of the operating system of the electronic device to the total memory of the operating system is greater than ratio_1. It is understood that memory threshold_4 and ratio_1 can be set according to actual needs, and the present application does not limit this. For example, ratio_1 can be 0.2.

[0265] It is understandable that the above-mentioned conditions 1, 2 and 3 may also include other contents, and this application does not limit this.

[0266] S307: When the preset condition 1 is met, the Runtime module 2 sends a memory leak message to the System Server.

[0267] It is understandable that the specific implementation of step S307 can refer to the relevant description of step S206, which will not be repeated here.

[0268] In some embodiments of the present application, the electronic device executes Fig.10 The step S302 shown in FIG. 1 may be specifically performed as follows: Fig.11 The specific steps are as follows:

[0269] S401: The process control module creates a zygote virtual machine.

[0270] After the electronic device receives the instruction to start the electronic device, in response to the instruction to start the electronic device, the process control module in the electronic device can create a zygote virtual machine. It is understandable that the process control module can layout the memory space in the zygote virtual machine during the process of creating the zygote virtual machine.

[0271] According to the above, the zygote virtual machine includes the Runtime module_1 and the runtime data area_1. The runtime data area_1 includes RegionSpace_1.

[0272] S402: The process control module starts the zygote virtual machine.

[0273] After the electronic device creates the zygote virtual machine, the process control module in the electronic device can start the zygote virtual machine.

[0274] When the electronic device executes step S401, it may specifically execute the following steps:

[0275] S4011: The process control module creates the Runtime module_1.

[0276] After the process control module receives the instruction to start the electronic device, it can start to create the zygote virtual machine in response to the instruction to start the electronic device. Specifically, the process control module can first create the Runtime module_1. The relevant description of the Runtime module_1 can be referred to above, and will not be elaborated here.

[0277] S4012: Runtime module_1 creates runtime data area_1.

[0278] After the process control module creates the Runtime module_1, the Runtime module_1 can create the runtime data area_1. The description of the runtime data area_1 can be found above and will not be elaborated here.

[0279] It is understandable that after the Runtime module_1 creates the runtime data area_1, the runtime data area_1 can perform a layout of the memory space. That is, the electronic device can perform a layout of the runtime data area_1. The specific implementation of the layout of the runtime data area_1 can include steps S4013-S4016.

[0280] S4013: The runtime data area_1 determines that the memory size corresponding to the RegionSpace_1 in the runtime data area_1 is memory_1. Memory_1 is larger than the default memory corresponding to the RegionSpace_1.

[0281] After the Runtime module_1 creates the runtime data area_1, the runtime data area_1 can determine the memory size corresponding to each Space in the runtime data area_1. Specifically, the runtime data area_1 can determine that the memory size corresponding to RegionSpace_1 is memory_1. It can also be understood that the runtime data area_1 can determine that the initial memory size corresponding to RegionSpace_1 is memory_1. Memory_1 is larger than the default memory corresponding to RegionSpace_1. It can be understood that RegionSpace_1 is a memory space in the runtime data area_1, and its detailed description can be referred to above.

[0282] Of course, the runtime data area_1 can also determine the memory size corresponding to other Spaces (for example, ImageSpace, etc.) in the runtime data area_1. For its specific implementation, please refer to relevant technical documents and will not be described in detail here.

[0283] In some embodiments of the present application, the runtime data area_1 can determine the memory size corresponding to each Space in the runtime data area_1 by reading a related configuration file. It is understandable that the configuration file records the memory corresponding to each Space in the runtime data area_1. In this way, the runtime data area_1 can be laid out according to the memory corresponding to each Space recorded in the configuration file.

[0284] It can be understood that the configuration file may record that the initial memory size corresponding to RegionSpace_1 is memory_1, and the default memory corresponding to RegionSpace_1.

[0285] Exemplarily, Memory_1 may be 768 MB, and the default memory corresponding to RegionSpace_1 may be 512 MB.

[0286] Of course, memory_1 can also be set to other values ​​greater than the default memory corresponding to RegionSpace_1, and this application does not limit this. In some embodiments of this application, memory_1 is not greater than the preset memory threshold. It is understandable that the preset memory threshold can be set according to actual needs, and this application does not limit this. For example, the preset memory threshold can be 768MB.

[0287] S4014: At runtime, data region_1 creates RegionSpace_1 based on memory_1.

[0288] After the runtime data area_1 determines that the memory size corresponding to RegionSpace_1 is memory_1, it can allocate a piece of memory space in the runtime data area_1 as RegionSpace_1. In this case, RegionSpace_1 has not yet been created. In the subsequent process, RegionSpace_1 can apply for the virtual address segment corresponding to memory_1, establish a mapping between the virtual address segment and the real physical address, and divide the region, thereby realizing the creation of RegionSpace_1.

[0289] S4015: RegionSpace_1 applies for virtual address segment_1, and divides the regions in RegionSpace_1 based on the relevant information of virtual address segment_1. The memory size corresponding to virtual address segment_1 is memory_1. Virtual address segment_1 consists of virtual address segment_11 and virtual address segment_12. The memory size corresponding to virtual address segment_11 is the default memory of RegionSpace_1.

[0290] After data area_1 is divided into RegionSpace_1 at runtime, RegionSpace_1 can apply for virtual address segment_1 and divide the regions in RegionSpace_1 based on the relevant information of virtual address segment_1.

[0291] In some embodiments of the present application, RegionSpace_1 can apply for an anonymous page corresponding to Memory_1. The anonymous page corresponding to Memory_1 can be used to represent virtual address segment_1. It can be understood that an anonymous page is used to represent a segment of a virtual address in a process virtual address space that has a mapping relationship with a physical address. The heap, stack, and data segments in the process virtual address space are generally referred to as anonymous pages. An anonymous page refers to a page without a file background. It does not exist in the form of a file, so it cannot be exchanged with a disk file.

[0292] In some embodiments of the present application, the relevant information of the virtual address segment_1 may include any one or more of the following: the first address of the virtual address segment_1, the last address of the virtual address segment_1.

[0293] In a possible implementation, the relevant information of virtual address segment_1 includes the first address of virtual address segment_1. In this case, RegionSpace_1 can determine the last address of virtual address segment_1 based on the first address of virtual address segment_1 and memory_1, and divide virtual address segment_1 into address segments of 256KB in size based on the first address and the last address of virtual address segment_1. It can be understood that each address segment of 256KB in size is a region.

[0294] It should be noted that the memory size corresponding to the virtual address segment_1 applied for by RegionSpace_1 is memory_1, and memory_1 is larger than the default memory of RegionSpace_1. In other words, the memory size corresponding to the virtual address segment_1 applied for by RegionSpace_1 is larger than the default memory of RegionSpace_1. For ease of description and understanding, this application records virtual address segment_1 as consisting of virtual address segment_11 and virtual address segment_12. Among them, the memory size corresponding to virtual address segment_11 is the default memory of RegionSpace_1.

[0295] S4016: During runtime, data area_1 obtains and records relevant information of the regions in RegionSpace_1 from RegionSpace_1.

[0296] After RegionSpace_1 divides the regions, Data Area_1 can obtain and record the relevant information of the regions divided by RegionSpace_1 from RegionSpace_1 during runtime. It can be understood that the relevant information of the regions can include the address segments corresponding to the regions, and can also include the status and type of the regions. Of course, the relevant information of the regions can also include other contents (for example, the types of storage objects in the regions), which is not limited in this application.

[0297] S4017: After the layout of runtime data area_1 is completed, Runtime module_1 releases part of the memory of RegionSpace_1. After releasing part of the memory, the memory of RegionSpace_1 is the default memory of RegionSpace_1. After releasing part of the memory, the virtual address segment corresponding to RegionSpace_1 is virtual address segment_11.

[0298] After Runtime module_1 determines that the layout of runtime data area_1 is complete, Runtime module_1 can release part of the memory_1 applied for by RegionSpace_1 and retain the rest of the memory. After releasing the memory, the memory size of RegionSpace_1 can be the default memory corresponding to RegionSpace_1. In other words, the virtual address corresponding to the released part of the memory is virtual address segment_12, and the virtual address corresponding to the retained memory is virtual address segment_11.

[0299] It is understandable that virtual address segment_12 can be understood as the backup virtual address segment corresponding to RegionSpace_1. Virtual address segment_12 is recorded in RegionSpace_1, and the memory corresponding to virtual address segment_12 can be used again in the subsequent process. It is understandable that RegionSpace in other virtual machines (for example, application_1 virtual machine) obtained by forking the zygote virtual machine also records virtual address segment_12, and memory expansion can also be achieved based on virtual address segment_12 in the subsequent process.

[0300] It can be understood that the release of memory involved in this application specifically refers to releasing the mapping relationship between the virtual address segment corresponding to the memory and the physical address.

[0301] It should be noted that, in some embodiments of the present application, when the electronic device executes step S4017, the electronic device may release the memory in memory_1 except memory_2. It is understandable that memory_2 is smaller than memory_1. In a possible implementation, Fig.11 As shown, memory_2 can be the default memory corresponding to RegionSpace_1. In another possible implementation, memory_2 can be larger than the default memory corresponding to RegionSpace_1. In this way, the Java memory space of all application processes forked by the zygote process can be expanded. In another possible implementation, memory_2 can be smaller than the default memory corresponding to RegionSpace_1. In this way, the Java memory space of the application process forked by the zygote process will be reduced, which can facilitate the subsequent expansion of the Java memory space for a specific application.

[0302] It is understood that if the electronic device releases the memory in memory_1 except memory_2 when executing step S4017, the electronic device can adjust the memory size of RegionSpace_2 from memory_2 to memory_3 when executing step S306. It is understood that memory_3 is larger than memory_2, and memory_3 is smaller than or equal to memory_1.

[0303] It should be noted that based on Fig.11As shown in the content, the "virtual address segment used by RegionSpace_1" mentioned in step S302 can be virtual address segment_11, and the "standby virtual address segment corresponding to RegionSpace_1" mentioned in step S302 can be virtual address segment_12. When the electronic device executes step S306, a mapping relationship between some or all address segments in virtual address segment_12 and the physical address can be established, so that the memory size corresponding to RegionSpace_1 can be expanded on the basis of the original default memory (i.e., the default memory of RegionSpace_1), and the memory size of RegionSpace_1 can be expanded to Memory_1 at most.

[0304] It is understandable that the above method is not only applicable to electronic devices using the Android operating system, but also to electronic devices using other operating systems. In this case, the Java memory space in the electronic device may not be the above RegionSpace.

[0305] The hardware structure of the electronic device involved in this application is introduced below.

[0306] See also Fig.12 , Fig.12 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application.

[0307] The electronic device may include a processor 110 , an external memory interface 120 , an internal memory 121 , an audio module 130 , a speaker 130A, a receiver 130B, a microphone 130C, an earphone interface 130D, a display screen 140 , a camera 150 , and a touch sensor 160 .

[0308] It is to be understood that the structure illustrated in the embodiments of the present application does not constitute a specific limitation on the electronic device. It is to be understood that the illustrated components can be implemented in hardware, software, or a combination of software and hardware. In some embodiments of the present application, the electronic device may include more components than illustrated. Exemplarily, the electronic device may include other types of sensors such as an acceleration sensor, a gyroscope sensor, and a temperature sensor. In some other embodiments of the present application, the electronic device may include fewer components than illustrated, or combine certain components, or split certain components, or arrange the components differently. The interface connection relationship between the modules illustrated in the embodiments of the present application is only a schematic illustration and does not constitute a structural limitation on the electronic device.

[0309] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. A memory may also be provided in the processor 110 for storing instructions and data.

[0310] The electronic device implements the display function through the GPU, the display screen 140, and the application processor.

[0311] The GPU is a microprocessor for image processing, connected to the display screen 140 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs, which execute program instructions to generate or change display information. The display screen 140 is used to display images, videos, etc. In some embodiments, the electronic device may include one or more display screens 140.

[0312] The camera 150 is used to capture static images or videos. The ISP is used to process the data fed back by the camera 150. Light is transmitted to the camera photosensitive element through the lens, and the light signal is converted into an electrical signal. The camera photosensitive element transmits the electrical signal to the ISP for processing and converts it into an image visible to the naked eye. The electronic device may include one or more cameras 150.

[0313] The internal memory 121 may include one or more RAMs and one or more non-volatile memories (NVMs). The random access memory can be directly read and written by the processor 110, and can be used to store executable programs (e.g., machine instructions) of an operating system or other running programs, and can also be used to store user and application data, etc. The non-volatile memory can also store executable programs and store user and application data, etc., and can be loaded into the random access memory in advance for direct reading and writing by the processor 110.

[0314] In the embodiment of the present application, the code for implementing the memory repair and cleaning method described in the embodiment of the present application can be stored in a non-volatile memory. When running the camera application, the electronic device can load the executable code stored in the non-volatile memory into the random access memory.

[0315] The external memory interface 120 may be used to connect to an external non-volatile memory to expand the storage capacity of the electronic device.

[0316] The electronic device can implement audio functions through the audio module 130, the speaker 130A, the receiver 130B, the microphone 130C, the headphone interface 130D, and the application processor.

[0317] The audio module 130 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signals. The speaker 130A, also called "speaker", is used to convert audio electrical signals into sound signals. The receiver 130B, also called "earpiece", is used to convert audio electrical signals into sound signals. The microphone 130C, also called "microphone", "microphone", is used to convert sound signals into electrical signals. The headphone interface 130D is used to connect wired headphones.

[0318] In the embodiment of the present application, when the speech-to-text function is turned on, the electronic device can enable the microphone 130C to collect sound signals and convert the sound signals into corresponding text.

[0319] The touch sensor 160 is also called a "touch control device". The touch sensor 160 can be arranged on the display screen 140. The touch sensor 160 and the display screen 140 form a touch screen, also called a "touch control screen". The touch sensor 160 is used to detect touch operations acting on or near it. The touch sensor can pass the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through the display screen 140. In other embodiments, the touch sensor 160 can also be arranged on the surface of the electronic device, which is different from the position of the display screen 140.

[0320] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A memory processing method, characterized in that: Applied to an electronic device, the electronic device includes a first application, and the method includes: Cold starting the first application; In response to cold starting the first application, a first application virtual machine corresponding to the first application is obtained, wherein a Java memory space in the first application virtual machine is a first Java memory space, and a memory size of the first Java memory space is a first memory; When a first preset condition is met, the memory size of the first Java memory space is expanded from the first memory to a second memory, wherein the second memory is larger than the first memory.

2. The method according to claim 1, characterized in that The satisfying of the second preset condition includes: The first Java memory space meets a first memory condition, and the first application is a first preset application.

3. The method according to claim 1, characterized in that The electronic device further includes an operating system, and the satisfying the second preset condition includes: The first Java memory space meets a first memory condition, the first application is a first preset application, and the unoccupied memory of the operating system is greater than a first threshold.

4. The method according to claim 2 or 3, characterized in that The first Java memory space satisfies the first memory condition, including: The occupied memory in the first Java memory space reaches a second threshold, and / or a growth rate of the occupied memory in the first Java memory space is greater than a third threshold.

5. The method according to claim 1, characterized in that After the memory size of the first Java memory space is expanded from the first memory to the second memory, the method further includes: determining whether the first application is in a preset state when a second preset condition is met; If the first application is not in the preset state, destroy the first application.

6. The method according to claim 5, characterized in that The preset states include: small window display, downloading and background playing states.

7. The method according to claim 5 or 6, characterized in that The second preset condition includes: the occupied memory of the first Java memory space is greater than a fourth threshold, and the duration for which the first application resides in the background is greater than the first duration.

8. The method according to claim 5 or 6, characterized in that The second preset condition includes: the first application is a second preset application.

9. The method according to claim 5, characterized in that The electronic device further includes a SystemServer process. Before determining whether the first application is in the preset state, the method further includes: When the occupied memory of the first Java memory space is greater than the fourth threshold, a memory leak message is sent to the SystemServer process through the first application virtual machine.

10. The method according to claim 5, characterized in that Before destroying the first application, the method further includes: If the occupied memory of the first Java memory space is less than a fifth threshold, or the first application has been destroyed, the first application is no longer destroyed.

11. An electronic device comprising one or more memories and one or more processors, characterized in that: The memory is used to store a computer program; the processor is used to call the computer program so that the electronic device executes the method according to any one of claims 1 to 10.

12. A computer storage medium, characterized in that: include: Computer instructions; when the computer instructions are executed on an electronic device, the electronic device executes the method according to any one of claims 1 to 10.