Memory cleaning method, device, storage medium and electronic device

By obtaining the memory space change trend of electronic devices and determining the memory cleaning strategy, the problem of poor memory cleaning operation in the existing technology is solved, more efficient memory cleaning is achieved, and the operation speed and stability of electronic devices are improved.

CN113177005BActive Publication Date: 2025-06-24GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110468836.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-04-28
Publication Date
2025-06-24
Estimated Expiration
2041-04-28

AI Technical Summary

Technical Problem

The prior art is poor in memory cleaning operations of electronic devices and cannot effectively improve the operating speed of electronic devices.

Method used

By obtaining the first change trend of the available memory space capacity and the second change trend of the foreground process occupying memory space capacity when the available memory space capacity of the electronic device is greater than or equal to the memory cleaning threshold, determining the memory cleaning strategy, and controlling whether to perform memory cleaning operations according to the policy.

Benefits of technology

Effective memory cleaning is carried out in advance, which improves the effectiveness of memory cleaning operations of electronic devices and avoids problems such as running lag and frame drops caused by insufficient available memory space.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113177005B_ABST
    Figure CN113177005B_ABST
Patent Text Reader

Abstract

Embodiments of the present application disclose a memory cleaning method, device, storage medium, and electronic device. Among them, when the available memory space capacity of the electronic device is greater than or equal to the memory cleaning threshold, the first change trend of the available memory space capacity is obtained, and the second change trend of the memory space capacity occupied by the foreground process is obtained. According to the first change trend and the second change trend, a memory cleaning strategy for the electronic device is determined; and according to the determined memory cleaning strategy, the electronic device is controlled to perform or not perform a memory cleaning operation. In this way, compared with the related art where the memory cleaning operation is performed only when the available memory space capacity of the electronic device is less than the memory cleaning threshold, the present application performs memory cleaning in advance before the available memory space capacity of the electronic device is less than the memory cleaning threshold, and can effectively clean the memory of the electronic device.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of memory cleaning, and particularly to a memory cleaning method, apparatus, storage medium, and electronic device. Background Art

[0002] Currently, with the popularization of electronic devices such as smart phones and tablet computers, various applications on these electronic devices emerge in an endless stream. For example, browser applications that provide web browsing functions, game applications that provide playing functions, and so on.

[0003] While enriching the functions of electronic devices, these applications also occupy a large amount of memory space of the electronic devices, resulting in slower and slower running speeds of the electronic devices. To save the memory space of the electronic devices and improve the running speed of the electronic devices, memory cleaning operations need to be performed on the electronic devices, that is, to end some unnecessary running applications.

[0004] When performing memory cleaning operations on electronic devices, related technologies usually set a memory cleaning threshold and trigger memory cleaning operations when the available memory space capacity of the electronic device is less than the memory cleaning threshold. However, the effectiveness of this memory cleaning method is poor. Summary of the Invention

[0005] This application provides a memory cleaning method, apparatus, storage medium, and electronic device, which can improve the effectiveness of memory cleaning operations performed by electronic devices.

[0006] In a first aspect, this application provides a memory cleaning method applied to an electronic device, including:

[0007] When the available memory space capacity of the electronic device is greater than or equal to the memory cleaning threshold, obtain a first change trend of the available memory space capacity;

[0008] Obtain a second change trend of the memory space capacity occupied by the foreground process;

[0009] Determine a memory cleaning strategy for the electronic device according to the first change trend and the second change trend; and

[0010] Control the electronic device to perform or not perform memory cleaning operations according to the memory cleaning strategy.

[0011] In a second aspect, this application provides a memory cleaning apparatus applied to an electronic device, including:

[0012] A first acquisition module, configured to obtain a first change trend of the available memory space capacity when the available memory space capacity of the electronic device is greater than or equal to the memory cleaning threshold;

[0013] A second acquisition module, configured to acquire a second change trend of the memory space capacity occupied by the foreground process;

[0014] A policy determination module, configured to determine a memory cleaning policy for the electronic device according to the first change trend and the second change trend; and

[0015] A memory cleaning module, configured to control the electronic device to perform or not perform a memory cleaning operation according to the memory cleaning policy.

[0016] In a third aspect, the present application provides a storage medium, on which a computer program is stored, and when the computer program is loaded by a processor of an electronic device, it executes any memory cleaning method provided by the present application.

[0017] In a fourth aspect, the present application further provides an electronic device, the electronic device includes a processor and a memory, the memory stores a computer program, and the processor executes any memory cleaning method provided by the present application by loading the computer program.

[0018] Compared with the related art where memory cleaning operations are only performed when the available memory space capacity of the electronic device is less than the memory cleaning threshold, the present application performs memory cleaning in advance before the available memory space capacity of the electronic device is less than the memory cleaning threshold, and can effectively clean the memory of the electronic device. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the following drawings are only some embodiments of the present application, and those skilled in the art can obtain other drawings without creative efforts based on these drawings.

[0020] Figure 1 is a flowchart of a memory cleaning method provided by an embodiment of the present application.

[0021] Figure 2 is a schematic diagram of the memory occupancy of an electronic device in an embodiment of the present application.

[0022] Figure 3 is an example diagram of multiple sampled available memory space capacities obtained by sampling in an embodiment of the present application.

[0023] Figure 4 is an example diagram of a change curve of the available memory space capacity fitted according to multiple sampled available memory space capacities in an embodiment of the present application.

[0024] Figure 5 is an example diagram of multiple sampled occupied memory space capacities obtained by sampling in an embodiment of the present application.

[0025] Figure 6 It is an example diagram of the occupied memory space capacity change curve fitted according to multiple occupied memory space sampling capacities in the embodiments of the present application.

[0026] Figure 7 It is a comparison schematic diagram of the available memory space capacity change curve and the occupied memory space capacity change curve in the embodiments of the present application.

[0027] Figure 8 It is another comparison schematic diagram of the available memory space capacity change curve and the occupied memory space capacity change curve in the embodiments of the present application.

[0028] Figure 9 It is yet another comparison schematic diagram of the available memory space capacity change curve and the occupied memory space capacity change curve in the embodiments of the present application.

[0029] Figure 10 It is another process schematic diagram of the memory cleaning method provided by the embodiments of the present application.

[0030] Figure 11 It is a structural schematic diagram of the memory cleaning device provided by the embodiments of the present application.

[0031] Figure 12 It is a structural schematic diagram of the electronic device provided by the embodiments of the present application. Detailed implementation manners

[0032] It should be noted that the terms "first", "second", "third", etc. in the present application are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device that includes a series of steps or modules is not limited to the listed steps or modules, but some embodiments also include steps or modules not listed, or some embodiments also include other steps or modules inherent to these processes, methods, products or devices.

[0033] Referring to "embodiments" herein means that specific features, structures or characteristics described in connection with the embodiments can be included in at least one embodiment of the present application. The phrase appears in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art will explicitly and implicitly understand that the embodiments described herein can be combined with other embodiments.

[0034] Embodiments of the present application provide a memory cleaning method, a memory cleaning device, a storage medium, and an electronic device. The execution subject of the memory cleaning method may be the memory cleaning device provided by the embodiments of the present application, or an electronic device integrated with the memory cleaning device, and the memory cleaning device may be implemented in a hardware or software manner. Among them, the electronic device may be a device with data processing capabilities configured with a processor, such as a smart phone, a tablet computer, a handheld computer, a notebook computer, etc.

[0035] Please refer to Figure 1 , Figure 1 which is a schematic flow chart of the memory cleaning method provided by the embodiments of the present application. As Figure 1 shown, the flow of the memory cleaning method provided by the embodiments of the present application may be as follows:

[0036] In 110, when the available memory space capacity of the electronic device is greater than or equal to the memory cleaning threshold, obtain the first change trend of the available memory space capacity.

[0037] The current memory cleaning rule will set a memory cleaning threshold according to the size of the memory space capacity of the electronic device. For example, for an electronic device with a memory space capacity of 8GB, the memory cleaning threshold may be set to 1GB. In this way, when the available memory space capacity of the electronic device is less than 1GB, the memory cleaning operation is triggered to end unnecessary running applications in the background, so as to ensure that the available memory space capacity is greater than or equal to 1GB.

[0038] Although the above memory cleaning rule can ensure sufficient available memory space capacity when the application is started, for some large applications, the occupied space capacity when entering the application and the peak occupied memory space capacity during operation vary greatly. Taking a certain game application as an example, when starting the game and in the game hall scene, the memory space capacity occupied by this game application is about 300-400MB, while in the battle scene, the peak occupied memory space capacity can reach more than 900MB. During the operation of the game application, background applications may also continuously apply for memory, resulting in a rapid decrease in the available memory space capacity. In order not to affect the smooth operation of the foreground process, the electronic device will not execute the memory cleaning rule during the operation of the foreground process. The increase in memory occupied by the foreground process and the increase in memory occupied by background applications will cause the foreground process to experience problems such as running stuttering and frame drops. For example, taking an electronic device using the Android system as an example, when the available memory space capacity drops rapidly and triggers the Low Memory Killer (LMK), the Low Memory Killer will preempt the processor resources and end applications in batches, resulting in problems such as running stuttering and frame drops in the foreground process.

[0039] Therefore, in order to perform memory cleaning operations more effectively, based on the above memory cleaning rules, the present application provides new dynamic memory cleaning rules. The dynamic memory cleaning rules dynamically determine whether a memory cleaning operation is required according to the changes in the available memory space capacity and the memory space capacity occupied by foreground processes.

[0040] In the following embodiments, the memory cleaning method provided by the present application is described with an electronic device as the execution subject.

[0041] Different from the related art, in the embodiments of the present application, regardless of whether there is a foreground process running, the electronic device continuously detects its available memory space capacity. If it detects that the available memory space capacity is less than the memory cleaning threshold, a corresponding memory cleaning operation is performed; if it detects that the available memory space capacity is greater than or equal to the memory cleaning threshold, it is further determined whether to perform a memory cleaning operation according to the dynamic memory cleaning rules provided by the present application. There is no limit to the value of the memory cleaning threshold here, and specifically, those skilled in the art can take empirical values according to actual needs. For example, the memory cleaning threshold can be configured as 20% of the memory space capacity of the electronic device.

[0042] In the embodiments of the present application, when it is detected that the available memory space capacity is greater than or equal to the memory cleaning threshold, the change trend of the available memory space capacity is obtained, denoted as the first change trend. Among them, the first change trend is used to describe the change direction (such as increase or decrease) and the change amount of the available memory space capacity of the electronic device.

[0043] In 120, the second change trend of the memory space capacity occupied by the foreground process is obtained.

[0044] In addition, in addition to obtaining the first change trend of the available memory space capacity, the electronic device also obtains the change trend of the memory space capacity occupied by the foreground process, denoted as the second change trend. Among them, the second change trend is used to describe the change direction (such as increase or decrease) and the change amount of the memory space capacity occupied by the foreground process. Among them, the foreground process can be the process of any application running in the foreground of the electronic device, including but not limited to game applications, video applications, tool applications, browser applications, news applications, and so on.

[0045] It should be noted that the execution order of the above 110 and 120 is not affected by the order of the numbers. It can be that 110 is executed before 120, or 120 is executed before 110, or 110 and 120 are executed simultaneously.

[0046] In 130, according to the first change trend and the second change trend, a memory cleaning strategy for the electronic device is determined.

[0047] It can be understood that whether the application is running in the foreground or in the background, as long as it is running, it will occupy the memory space capacity of the electronic device. For example, please refer to Figure 2 , although the memory space capacity of the electronic device is fixed, the available memory space capacity and the occupied memory space capacity are dynamically changing. The occupied memory space capacity of the foreground process belongs to a part of the occupied memory space capacity, and the other part is the occupied memory space capacity of the background application.

[0048] It should be noted that there is a certain correlation between the first change trend of the available memory space capacity and the second change trend of the occupied memory space capacity of the foreground process. For example, assuming that the memory occupation of other applications except the foreground process remains unchanged, when the occupied memory space capacity of the foreground process increases, the available memory space capacity of the electronic device decreases accordingly, and when the occupied memory space capacity of the foreground process decreases, the available memory space capacity of the electronic device increases accordingly. Therefore, in the embodiments of the present application, the electronic device can predict the subsequent memory occupation situation according to the first change trend of the available memory space capacity and the second change trend of the occupied memory space capacity of the foreground process, and accordingly determine the memory cleaning strategy.

[0049] For example, when it is predicted that the subsequent memory occupation situation is that the available memory space capacity will be less than the memory cleaning threshold, the memory cleaning strategy is determined to be to perform a memory cleaning operation, and when it is predicted that the subsequent memory occupation situation is that the available memory space capacity will be greater than or equal to the memory cleaning threshold, the memory cleaning strategy is determined to be not to perform a memory cleaning operation.

[0050] In 140, according to the memory cleaning strategy, control the electronic device to perform or not perform a memory cleaning operation.

[0051] After the electronic device determines the memory cleaning strategy, it will perform or not perform a memory cleaning operation according to the determined memory cleaning strategy.

[0052] For example, when the determined memory cleaning strategy is to perform a memory cleaning operation, the electronic device will accordingly perform a memory cleaning operation, and when the determined memory cleaning strategy is not to perform a memory cleaning operation, the electronic device will accordingly not perform a memory cleaning operation.

[0053] It should be noted that in the embodiments of the present application, there is no specific limitation on the memory cleaning operation performed by the electronic device, and those skilled in the art can configure it according to actual needs.

[0054] As above, by periodically executing 110-140, the memory cleaning operation of the electronic device can be dynamically performed, and the effectiveness of the memory cleaning operation of the electronic device can be improved.

[0055] As can be seen from the above, in the present application, when the available memory space capacity of the electronic device is greater than or equal to the memory cleaning threshold, the first change trend of the available memory space capacity is obtained, and the second change trend of the memory space capacity occupied by the foreground process is obtained. Then, according to the first change trend and the second change trend, a memory cleaning strategy for the electronic device is determined; and according to the determined memory cleaning strategy, the electronic device is controlled to perform or not perform a memory cleaning operation. In this way, compared with the related art where the memory cleaning operation is only performed when the available memory space capacity of the electronic device is less than the memory cleaning threshold, the present application performs memory cleaning in advance before the available memory space capacity of the electronic device is less than the memory cleaning threshold, and can effectively clean the memory of the electronic device.

[0056] Optionally, in one embodiment, before obtaining the first change trend of the available memory space capacity, it further includes:

[0057] When the available memory space capacity of the electronic device is greater than or equal to the memory cleaning threshold, it is judged whether the foreground process is a preset application;

[0058] When the foreground process is a preset application, the first change trend of the available memory space capacity is obtained.

[0059] In the embodiment of the present application, the electronic device only performs a memory cleaning operation in advance when the foreground process is a specific application to ensure the stable operation of these specific applications.

[0060] Among them, when the electronic device detects that the available memory space capacity is greater than or equal to the memory cleaning threshold, it does not immediately obtain the first change trend of the available memory space capacity, but first judges whether the running foreground process is a preset application. If the running foreground process is a preset application, then the first change trend of the available memory space capacity is obtained.

[0061] It should be noted that in the embodiment of the present application, there is no specific limitation on the type and quantity configuration of the preset application. It can be configured by default by the electronic device. For example, game applications with strict memory requirements can be configured as preset applications, and it can also be configured by the electronic device according to user input. For example, a video application can be configured as a preset application according to user input.

[0062] Optionally, in one embodiment, obtaining the first change trend of the available memory space capacity includes:

[0063] (1) Sampling the available memory space capacity of the electronic device within a preset sampling period according to a preset sampling frequency to obtain a plurality of available memory space sampling capacities;

[0064] (2) Fitting a change curve of the available memory space capacity of the electronic device according to the plurality of available memory space sampling capacities;

[0065] (3) Use the curve of the change in the available memory space capacity as the first change trend.

[0066] The embodiment of the present application further provides an optional method for obtaining the first change trend of the available memory space capacity.

[0067] Among them, the embodiment of the present application is pre-configured with a sampling frequency for sampling the available memory space capacity, denoted as the preset sampling frequency. In addition, a preset sampling period for sampling the available memory space capacity is also pre-configured.

[0068] In the embodiment of the present application, when obtaining the first change trend of the available memory space capacity, the electronic device first samples the available memory space capacity of the electronic device within the preset sampling period according to the preset sampling frequency, and correspondingly obtains a plurality of sampled available memory space capacities; then, according to these sampled available memory space capacities, a curve is fitted according to their respective sampling times, denoted as the available memory space capacity change curve of the electronic device. This available memory space capacity change curve reflects the change trend of the available memory space capacity of the electronic device. Therefore, the electronic device directly uses the fitted available memory space capacity change curve as the first change trend of the available memory space capacity.

[0069] Based on the above description, those skilled in the art can understand that the larger the value of the preset sampling frequency, the more sampled available memory space capacities are obtained, and the more accurate the fitted available memory space capacity change curve is. Therefore, in the embodiment of the present application, the value of the preset sampling frequency is not specifically limited, and those skilled in the art can take empirical values according to actual needs. In addition, the value of the preset sampling period in the embodiment of the present application is also not specifically limited, and those skilled in the art can also take empirical values according to actual needs.

[0070] Exemplarily, assume that the preset sampling frequency is configured to be 1 time / second and the preset sampling period is 5 seconds. Then the electronic device will sample the available memory space capacity 5 times within 5 seconds. Please refer to Figure 3 , assuming that the sampled available memory space capacity obtained at the 1st second is 1.4 GB, the sampled available memory space capacity obtained at the 2nd second is 1.64 GB, the sampled available memory space capacity obtained at the 3rd second is 1.8 GB, the sampled available memory space capacity obtained at the 4th second is 1.84 GB, and the sampled available memory space capacity obtained at the 5th second is 1.87 GB, then the available memory space capacity change curve shown in Figure 4 can be fitted.

[0071] Optionally, in an embodiment, obtaining the second change trend of the memory space capacity occupied by the foreground process includes:

[0072] (1) Sample the memory space capacity occupied by the foreground process within a preset sampling period at a preset sampling frequency to obtain multiple sampled memory space capacities.

[0073] (2) Fit a curve of the change in the memory space capacity occupied by the foreground process based on the multiple sampled memory space capacities.

[0074] (3) Use the curve of the change in the memory space capacity as the second change trend.

[0075] The embodiment of the present application further provides an optional method for obtaining the second change trend of the memory space capacity occupied by the foreground process.

[0076] Among them, the embodiment of the present application uses the same method as that for obtaining the first change trend of the available memory space capacity in the above embodiment to obtain the second change trend of the memory space capacity occupied by the foreground process.

[0077] In the embodiment of the present application, when obtaining the second change trend of the memory space capacity occupied by the foreground process, the electronic device first samples the memory space capacity occupied by the foreground process within a preset sampling period at a preset sampling frequency, and correspondingly obtains multiple sampled memory space capacities; then, based on these multiple sampled memory space capacities obtained by sampling, a curve is fitted according to their respective sampling times, denoted as the curve of the change in the memory space capacity occupied by the foreground process, and this curve of the change in the memory space capacity reflects the change trend of the memory space capacity occupied by the foreground process. Therefore, the electronic device directly uses the fitted curve of the change in the memory space capacity as the second change trend of the memory space capacity occupied by the foreground process.

[0078] Exemplarily, assume that the preset sampling frequency is configured as 1 time / second and the preset sampling period is 5 seconds, then the electronic device will sample the available memory space capacity 5 times within 5 seconds. Please refer to Figure 5 , assume that the sampled memory space capacity obtained at the 1st second is 0.95 GB, the sampled memory space capacity obtained at the 2nd second is 0.9 GB, the sampled memory space capacity obtained at the 3rd second is 0.81 GB, the sampled memory space capacity obtained at the 4th second is 0.7 GB, and the sampled memory space capacity obtained at the 5th second is 0.4 GB, then the curve of the change in the memory space capacity as shown in Figure 6 can be fitted.

[0079] Optionally, in one embodiment, determine a memory cleaning policy for the electronic device according to the first change trend and the second change trend, including:

[0080] When the average slope of the available memory space capacity change curve is negative, the average slope of the occupied memory space capacity change curve is positive, and the absolute value of the average slope of the available memory space capacity change curve is less than the absolute value of the average slope of the occupied memory space capacity change curve, it is determined that the memory cleaning policy is not to perform a memory cleaning operation.

[0081] An embodiment of the present application provides an optional method for determining a memory cleaning policy according to a first change trend and a second change trend.

[0082] Among them, the available memory space capacity change curve is used as the first change trend of the available memory space capacity, and the occupied memory space capacity change curve is used as the second change trend of the memory space capacity occupied by the foreground process.

[0083] When determining the memory cleaning policy for the electronic device according to the first change trend and the second change trend, please refer to Figure 7 , if the average slope of the available memory space capacity change curve is negative, it indicates that the available memory space capacity is continuously decreasing at this time. If the average slope of the occupied memory space capacity change curve is positive, it indicates that the memory space capacity occupied by the foreground process is continuously increasing at this time. At this time, the electronic device further compares the absolute value of the average slope of the available memory space capacity change curve with the absolute value of the average slope of the occupied memory space capacity change curve. Among them, if the absolute value of the average slope of the available memory space capacity change curve is less than the absolute value of the average slope of the occupied memory space capacity change curve, the electronic device determines that there are other applications other than the foreground process actively releasing memory at this time, predicts that the available memory space capacity will be greater than or equal to the memory cleaning threshold, and at this time, cleaning should not be triggered, and the corresponding memory cleaning policy is determined not to perform a memory cleaning operation.

[0084] Optionally, in an embodiment, determining the memory cleaning policy for the electronic device according to the first change trend and the second change trend includes:

[0085] When the average slope of the available memory space capacity change curve is negative, the average slope of the occupied memory space capacity change curve is positive, and the absolute value of the average slope of the available memory space capacity change curve is greater than or equal to the absolute value of the average slope of the occupied memory space capacity change curve, it is determined that the memory cleaning policy is to perform a memory cleaning operation.

[0086] Another embodiment of the present application provides an optional method for determining a memory cleaning policy according to a first change trend and a second change trend.

[0087] Among them, the available memory space capacity change curve is used as the first change trend of the available memory space capacity, and the occupied memory space capacity change curve is used as the second change trend of the memory space capacity occupied by the foreground process.

[0088] When determining the memory cleaning policy for an electronic device according to the first change trend and the second change trend, please refer to Figure 8 , if the average slope of the available memory space capacity change curve is negative, it indicates that the available memory space capacity is continuously decreasing at this time. If the average slope of the occupied memory space capacity change curve is positive, it indicates that the occupied memory space capacity of the foreground process is continuously increasing at this time. At this time, the electronic device further compares the absolute value of the average slope of the available memory space capacity change curve with the absolute value of the average slope of the occupied memory space capacity change curve. Among them, when the absolute value of the average slope of the available memory space capacity change curve is greater than or equal to the absolute value of the average slope of the occupied memory space capacity change curve, the electronic device determines that there are other applications other than the foreground process increasing memory occupancy at this time, predicts that the available memory space capacity will be less than the memory cleaning threshold, and at this time, cleaning should be triggered, and the corresponding memory cleaning policy is determined to perform a memory cleaning operation.

[0089] Optionally, in an embodiment, determining the memory cleaning policy for the electronic device according to the first change trend and the second change trend includes:

[0090] When the average slope of the available memory space capacity change curve is negative and the average slope of the occupied memory space capacity change curve is negative, the memory cleaning policy is determined not to perform a memory cleaning operation.

[0091] Another optional method for determining the memory cleaning policy according to the first change trend and the second change trend is provided in the embodiments of the present application.

[0092] Among them, the available memory space capacity change curve is used as the first change trend of the available memory space capacity, and the occupied memory space capacity change curve is used as the second change trend of the occupied memory space capacity of the foreground process.

[0093] When determining the memory cleaning policy for an electronic device according to the first change trend and the second change trend, please refer to Figure 9 , if the average slope of the available memory space capacity change curve is negative, it indicates that the available memory space capacity is continuously decreasing at this time. If the average slope of the occupied memory space capacity change curve is also negative, it indicates that the foreground process may have exited the high memory occupancy scenario at this time (for example, a game application has exited a battle), predicts that the available memory space capacity will be greater than or equal to the memory cleaning threshold, and at this time, cleaning should not be triggered, and the corresponding memory cleaning policy is determined not to perform a memory cleaning operation.

[0094] Optionally, in an embodiment, determining the memory cleaning policy for the electronic device according to the first change trend and the second change trend includes:

[0095] When the average slope of the available memory space capacity change curve is positive and the average slope of the occupied memory space capacity change curve is positive or negative, it is determined that the memory cleaning policy is not to perform a memory cleaning operation.

[0096] Optionally, in an embodiment, controlling the electronic device to perform a memory cleaning operation includes:

[0097] (1) Determine the target background process to be terminated according to the pre-allocated priorities of each background process;

[0098] (2) Terminate the target background process and release the memory space capacity occupied by the target background process.

[0099] The embodiment of the present application further provides an optional memory cleaning operation.

[0100] It should be noted that in the embodiment of the present application, according to the configured priority allocation policy, corresponding priorities are pre-allocated to each process, denoted as pre-allocated priorities. Here, the configuration of the priority allocation policy is not specifically limited, and can be configured by those skilled in the art according to actual needs. The priority allocation policy can be configured to be dynamic (for example, different priorities are correspondingly configured according to different running states of the process), or the priority allocation policy can be configured to be static.

[0101] In the embodiment of the present application, when performing a memory cleaning operation, the electronic device first determines the target background process to be terminated according to the pre-allocated priorities of each background process, terminates the determined target background process, and correspondingly releases the memory space capacity occupied by the target background process.

[0102] Exemplarily, the electronic device sorts each background process according to the level of the pre-allocated priority, determines the preset number (which can be an empirical value taken by those skilled in the art according to actual needs) of background processes with the lowest pre-allocated priority ranking, and determines these preset number of background processes as the target background processes for cleaning.

[0103] Please refer to Figure 10 , the process of the memory cleaning method provided by the present application can also be as follows:

[0104] In 210, when the available memory space capacity of the electronic device is greater than or equal to the memory cleaning threshold, at a preset sampling frequency, the available memory space capacity within a preset sampling period is sampled to obtain a plurality of available memory space sampling capacities, and the occupied memory space capacity of the foreground process is sampled to obtain a plurality of occupied memory space sampling capacities.

[0105] The current memory cleaning rule sets a memory cleaning threshold according to the size of the memory space capacity of the electronic device. For example, for an electronic device with a memory space capacity of 8 GB, the memory cleaning threshold can be set to 1 GB. Thus, when the available memory space capacity of the electronic device is less than 1 GB, the memory cleaning operation is triggered to end unnecessary running applications in the background, thereby ensuring that the available memory space capacity is greater than or equal to 1 GB.

[0106] In order to perform the memory cleaning operation more effectively, based on the above memory cleaning rule, the present application provides a new dynamic memory cleaning rule. This dynamic memory cleaning rule dynamically determines whether a memory cleaning operation is required according to the changes in the available memory space capacity and the memory space capacity occupied by the foreground process.

[0107] Different from the related art, in the embodiment of the present application, regardless of whether there is a foreground process running, the electronic device always detects its available memory space capacity in real time. If it detects that the available memory space capacity is less than the memory cleaning threshold, the corresponding memory cleaning operation is performed; if it detects that the available memory space capacity is greater than or equal to the memory cleaning threshold, it is further determined whether to perform the memory cleaning operation according to the dynamic memory cleaning rule provided by the present application. There is no limit to the value of the memory cleaning threshold here, and those skilled in the art can specifically take empirical values according to actual needs. For example, the memory cleaning threshold can be configured as 20% of the memory space capacity of the electronic device.

[0108] Among them, in the embodiment of the present application, a sampling frequency for sampling the available memory space capacity is pre-configured, denoted as the preset sampling frequency. In addition, a preset sampling period for sampling the available memory space capacity is also pre-configured.

[0109] When it is detected that the available memory space capacity is greater than or equal to the memory cleaning threshold, according to the preset sampling frequency, the available memory space capacity within the preset sampling period is sampled to obtain multiple sampled available memory space capacities, and the memory space capacity occupied by the foreground process is sampled to obtain multiple sampled occupied memory space capacities.

[0110] In the embodiment of the present application, there is no specific limitation on the value of the preset sampling frequency, and those skilled in the art can take empirical values according to actual needs. In addition, there is no specific limitation on the value of the preset sampling period in the embodiment of the present application, and those skilled in the art can also take empirical values according to actual needs.

[0111] In 220, the electronic device fits an available memory space capacity change curve based on multiple sampled available memory space capacities, and fits a foreground process occupied memory space capacity change curve based on multiple sampled occupied memory space capacities.

[0112] Among them, the electronic device fits a curve according to these multiple sampled available memory space sampling capacities at their respective sampling times, which is recorded as the available memory space capacity change curve of the electronic device. This available memory space capacity change curve reflects the change trend of the available memory space capacity of the electronic device. In addition, the electronic device also fits a curve according to these multiple sampled occupied memory space sampling capacities at their respective sampling times, which is recorded as the occupied memory space capacity change curve of the foreground process. This occupied memory space capacity change curve reflects the change trend of the occupied memory space capacity of the foreground process.

[0113] Exemplarily, assume that the preset sampling frequency is configured as once per second and the preset sampling period is 5 seconds. Then the electronic device will sample the available memory space capacity 5 times within 5 seconds. Please refer to Figure 3 , assume that the sampled available memory space sampling capacity at the 1st second is 1.4 GB, the sampled available memory space sampling capacity at the 2nd second is 1.64 GB, the sampled available memory space sampling capacity at the 3rd second is 1.8 GB, the sampled available memory space sampling capacity at the 4th second is 1.84 GB, and the sampled available memory space sampling capacity at the 5th second is 1.87 GB. Then the available memory space capacity change curve as shown in Figure 4 can be fitted.

[0114] Please refer to Figure 5 , assume that the sampled occupied memory space sampling capacity at the 1st second is 0.95 GB, the sampled occupied memory space sampling capacity at the 2nd second is 0.9 GB, the sampled occupied memory space sampling capacity at the 3rd second is 0.81 GB, the sampled occupied memory space sampling capacity at the 4th second is 0.7 GB, and the sampled occupied memory space sampling capacity at the 5th second is 0.4 GB. Then the occupied memory space capacity change curve as shown in Figure 6 can be fitted.

[0115] In 230, the electronic device determines a memory cleaning policy according to the available memory space capacity change curve and the occupied memory space capacity change curve.

[0116] It can be understood that whether the application runs in the foreground or in the background, as long as it runs, it will occupy the memory space capacity of the electronic device. For example, please refer to Figure 2 , although the memory space capacity of the electronic device is fixed, the available memory space capacity and the occupied memory space capacity are dynamically changing. And the occupied memory space capacity of the foreground process belongs to a part of the occupied memory space capacity, and the other part is the memory space capacity occupied by the background application.

[0117] It should be noted that there is a certain correlation between the changing trend of the available memory space capacity and the changing trend of the memory space capacity occupied by the foreground process. For example, assuming that the memory occupation of other applications except the foreground process remains unchanged, when the memory space capacity occupied by the foreground process increases, the available memory space capacity of the electronic device decreases accordingly, and when the memory space capacity occupied by the foreground process decreases, the available memory space capacity of the electronic device increases accordingly. Therefore, in the embodiments of the present application, the electronic device can predict the subsequent memory occupation situation according to the changing trend of the available memory space capacity and the changing trend of the memory space capacity occupied by the foreground process, and accordingly determine the memory cleaning policy.

[0118] As described above, the available memory space capacity change curve reflects the changing trend of the available memory space capacity of the electronic device, and the occupied memory space capacity change curve reflects the changing trend of the memory space capacity occupied by the foreground process. Therefore, the electronic device determines the memory cleaning policy according to the available memory space capacity change curve and the occupied memory space capacity change curve.

[0119] Exemplarily, when the average slope of the available memory space capacity change curve is negative, the average slope of the occupied memory space capacity change curve is positive, and the absolute value of the average slope of the available memory space capacity change curve is less than the absolute value of the average slope of the occupied memory space capacity change curve, it is determined that the memory cleaning policy is not to perform a memory cleaning operation; or

[0120] When the average slope of the available memory space capacity change curve is negative, the average slope of the occupied memory space capacity change curve is positive, and the absolute value of the average slope of the available memory space capacity change curve is greater than or equal to the absolute value of the average slope of the occupied memory space capacity change curve, it is determined that the memory cleaning policy is to perform a memory cleaning operation; or

[0121] When the average slope of the available memory space capacity change curve is negative and the average slope of the occupied memory space capacity change curve is negative, it is determined that the memory cleaning policy is not to perform a memory cleaning operation; or

[0122] When the average slope of the available memory space capacity change curve is positive, and the average slope of the occupied memory space capacity change curve is positive or negative, it is determined that the memory cleaning policy is not to perform a memory cleaning operation.

[0123] In 240, the electronic device performs or does not perform a memory cleaning operation according to the memory cleaning policy.

[0124] After the electronic device determines the memory cleaning policy, it performs or does not perform a memory cleaning operation according to the determined memory cleaning policy.

[0125] For example, when the determined memory cleaning policy is to perform a memory cleaning operation, the electronic device correspondingly performs a memory cleaning operation; when the determined memory cleaning policy is not to perform a memory cleaning operation, the electronic device correspondingly does not perform a memory cleaning operation.

[0126] It should be noted that in the embodiments of the present application, there is no specific limitation on the memory cleaning operation performed by the electronic device, and it can be configured by those skilled in the art according to actual needs.

[0127] As described above, by periodically executing 210-240, the memory of the electronic device can be dynamically cleaned, improving the effectiveness of the memory cleaning operation of the electronic device.

[0128] Please refer to Figure 11 , Figure 11 FIG. 300 is a schematic structural diagram of a memory cleaning device 300 provided in an embodiment of the present application. The memory cleaning device 300 is applied to the electronic device provided in the present application. As Figure 11 shown, the memory cleaning device 300 may include:

[0129] A first acquisition module 310, configured to acquire a first change trend of the available memory space capacity when the available memory space capacity of the electronic device is greater than or equal to a memory cleaning threshold;

[0130] A second acquisition module 320, configured to acquire a second change trend of the memory space capacity occupied by the foreground process;

[0131] A policy determination module 330, configured to determine a memory cleaning policy for the electronic device according to the first change trend and the second change trend; and

[0132] A memory cleaning module 340, configured to control the electronic device to perform or not perform a memory cleaning operation according to the memory cleaning policy.

[0133] Optionally, in an embodiment, when acquiring the first change trend of the available memory space capacity, the first acquisition module 310 is configured to:

[0134] Sample the available memory space capacity of the electronic device within a preset sampling period at a preset sampling frequency to obtain a plurality of available memory space sampling capacities;

[0135] Fit a change curve of the available memory space capacity of the electronic device according to the plurality of available memory space sampling capacities;

[0136] Use the change curve of the available memory space capacity as the first change trend.

[0137] Optionally, in an embodiment, when acquiring the second change trend of the memory space capacity occupied by the foreground process, the second acquisition module 320 is configured to:

[0138] Sample the occupied memory space capacity of the foreground process within a preset sampling period according to the preset sampling frequency to obtain multiple sampled occupied memory space capacities;

[0139] Fit a change curve of the occupied memory space capacity of the foreground process based on the multiple sampled occupied memory space capacities;

[0140] Use the change curve of the occupied memory space capacity as the second change trend.

[0141] Optionally, in one embodiment, when determining the memory cleaning policy for the electronic device according to the first change trend and the second change trend, the policy determination module 330 is configured to:

[0142] When the average slope of the available memory space capacity change curve is negative, the average slope of the occupied memory space capacity change curve is positive, and the absolute value of the average slope of the available memory space capacity change curve is less than the absolute value of the average slope of the occupied memory space capacity change curve, determine that the memory cleaning policy is not to perform a memory cleaning operation.

[0143] Optionally, in one embodiment, when determining the memory cleaning policy for the electronic device according to the first change trend and the second change trend, the policy determination module 330 is configured to:

[0144] When the average slope of the available memory space capacity change curve is negative, the average slope of the occupied memory space capacity change curve is positive, and the absolute value of the average slope of the available memory space capacity change curve is greater than or equal to the absolute value of the average slope of the occupied memory space capacity change curve, determine that the memory cleaning policy is to perform a memory cleaning operation.

[0145] Optionally, in one embodiment, when determining the memory cleaning policy for the electronic device according to the first change trend and the second change trend, the policy determination module 330 is configured to:

[0146] When the average slope of the available memory space capacity change curve is negative and the average slope of the occupied memory space capacity change curve is negative, determine that the memory cleaning policy is not to perform a memory cleaning operation.

[0147] Optionally, in one embodiment, when controlling the electronic device to perform a memory cleaning operation, the memory cleaning module 340 is configured to:

[0148] Determine the target background process to be terminated according to the pre-allocated priorities of the background processes;

[0149] Terminate the target background process and release the occupied memory space capacity of the target background process.

[0150] It should be noted that the memory cleaning device provided in the embodiments of the present application belongs to the same concept as the memory cleaning method in the above embodiments. For the specific implementation process, please refer to the above related embodiments and will not be elaborated here.

[0151] The embodiments of the present application provide a storage medium, on which a computer program is stored. When the computer program stored thereon is executed by the processor of the electronic device provided in the embodiments of the present application, the processor of the electronic device executes the steps in any of the above memory cleaning methods. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM), etc.

[0152] The present application also provides an electronic device. Please refer to Figure 12 , the electronic device 400 includes a processor 410 and a memory 420.

[0153] The processor 410 in the embodiments of the present application can be a general-purpose processor, such as a processor with an ARM architecture.

[0154] A computer program is stored in the memory 420, which can be a high-speed random access memory, and can also be a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices, etc. Correspondingly, the memory 420 can also include a memory controller to provide the processor 401 with access to the memory 420. The processor 410 is used to execute the computer program in the memory 420 to execute any of the above memory cleaning methods suitable for the electronic device, such as:

[0155] When the available memory space capacity of the electronic device is greater than or equal to the memory cleaning threshold, obtain the first change trend of the available memory space capacity;

[0156] Obtain the second change trend of the memory space capacity occupied by the foreground process;

[0157] According to the first change trend and the second change trend, determine the memory cleaning strategy for the electronic device; and

[0158] According to the memory cleaning strategy, control the electronic device to perform or not perform a memory cleaning operation.

[0159] The above has introduced in detail a memory cleaning method, device, storage medium, and electronic device provided by this application. Specific examples are used in this article to elaborate on the principle and implementation manner of this application. The description of the above embodiments is only used to help understand the method and its core idea of this application; at the same time, for those skilled in the art, according to the idea of this application, there will be changes in the specific implementation manner and application scope. In summary, the content of this specification should not be construed as a limitation to this application.

Claims

1. A memory cleaning method, applied to an electronic device, characterized in that, Including: When the available memory space capacity of the electronic device is greater than or equal to the memory cleaning threshold, obtaining a first change trend of the available memory space capacity; Obtaining a second change trend of the memory space capacity occupied by the foreground process; According to the first change trend and the second change trend, determining a memory cleaning strategy for the electronic device, including: when the average slope of the available memory space capacity change curve is negative, the average slope of the occupied memory space capacity change curve is positive, and the absolute value of the average slope of the available memory space capacity change curve is less than the absolute value of the average slope of the occupied memory space capacity change curve, determining that the memory cleaning strategy is not to perform a memory cleaning operation; when the average slope of the available memory space capacity change curve is negative, the average slope of the occupied memory space capacity change curve is positive, and the absolute value of the average slope of the available memory space capacity change curve is greater than or equal to the absolute value of the average slope of the occupied memory space capacity change curve, determining that the memory cleaning strategy is to perform a memory cleaning operation; when the average slope of the available memory space capacity change curve is negative and the average slope of the occupied memory space capacity change curve is negative, determining that the memory cleaning strategy is not to perform a memory cleaning operation; and Controlling the electronic device to perform or not perform a memory cleaning operation according to the memory cleaning strategy.

2. The memory cleaning method according to claim 1, wherein, The obtaining of the first change trend of the available memory space capacity includes: Sampling the available memory space capacity of the electronic device within a preset sampling period according to a preset sampling frequency to obtain a plurality of available memory space sampling capacities; Fitting a change curve of the available memory space capacity of the electronic device based on the plurality of available memory space sampling capacities; Taking the change curve of the available memory space capacity as the first change trend.

3. The memory cleaning method according to claim 2, characterized in that, The obtaining of the second change trend of the memory space capacity occupied by the foreground process includes: Sampling the memory space capacity occupied by the foreground process within the preset sampling period according to the preset sampling frequency to obtain a plurality of occupied memory space sampling capacities; Fitting a change curve of the memory space capacity occupied by the foreground process based on the plurality of occupied memory space sampling capacities; Taking the change curve of the occupied memory space capacity as the second change trend.

4. The memory cleaning method according to any one of claims 1-3, characterized in that The controlling the electronic device to perform a memory cleaning operation includes: Determining a target background process to be terminated according to the pre-allocated priorities of each background process; Terminating the target background process and releasing the memory space capacity occupied by the target background process.

5. A memory cleaning device, applied to an electronic device, characterized in that Including: A first obtaining module, configured to obtain a first change trend of the available memory space capacity when the available memory space capacity of the electronic device is greater than or equal to the memory cleaning threshold; A second obtaining module, configured to obtain a second change trend of the memory space capacity occupied by the foreground process; A policy determination module, configured to determine a memory cleaning policy for the electronic device according to the first change trend and the second change trend, including: when the average slope of the available memory space capacity change curve is negative, the average slope of the occupied memory space capacity change curve is positive, and the absolute value of the average slope of the available memory space capacity change curve is less than the absolute value of the average slope of the occupied memory space capacity change curve, determining that the memory cleaning policy is not to perform a memory cleaning operation; when the average slope of the available memory space capacity change curve is negative, the average slope of the occupied memory space capacity change curve is positive, and the absolute value of the average slope of the available memory space capacity change curve is greater than or equal to the absolute value of the average slope of the occupied memory space capacity change curve, determining that the memory cleaning policy is to perform a memory cleaning operation; when the average slope of the available memory space capacity change curve is negative and the average slope of the occupied memory space capacity change curve is negative, determining that the memory cleaning policy is not to perform a memory cleaning operation; and A memory cleaning module, configured to control the electronic device to perform or not perform a memory cleaning operation according to the memory cleaning policy.

6. A storage medium having a computer program stored thereon, characterized in that, When the computer program is loaded by a processor of an electronic device, the memory cleaning method according to any one of claims 1-4 is executed.

7. An electronic device, the electronic device comprising a processor and a memory, the memory storing a computer program, characterized in that, The processor executes the memory cleaning method according to any one of claims 1-4 by loading the computer program.

Citation Information

Patent Citations

  • Method and device for clearing memory of mobile terminal and mobile terminal

    CN104298612A

  • Process processing method and device and electronic device

    CN106959892A