GC method and electronic equipment

By dynamically adjusting the memory waterline of GC and controlling the GC frequency based on the scene information, the problems of high power consumption and poor performance caused by the fixed memory waterline in the prior art are solved, and lower power consumption and higher equipment performance are achieved.

CN119025253APending Publication Date: 2024-11-26HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310605219.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-05-25
Publication Date
2024-11-26

AI Technical Summary

Technical Problem

In memory management of existing electronic devices, the fixed setting of memory waterlines leads to a large power consumption and overhead, affecting device performance.

Method used

By dynamically adjusting the memory waterline of GC, dynamically determine the memory waterline based on scene information (such as the resident memory size and memory growth rate of heap memory), and then controlling the frequency and strength of GC.

Benefits of technology

It reduces the power consumption and overhead of the device, improves the performance of the device, and reduces user-sensed lag and memory waste.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119025253A_ABST
    Figure CN119025253A_ABST
Patent Text Reader

Abstract

The invention discloses a GC method and electronic equipment, and relates to the technical field of terminals. The method is applied to the electronic equipment and comprises the steps that scene information used for representing a current scene is obtained, then a memory waterline corresponding to the scene information is determined, the memory waterline can be determined according to at least one of the resident memory size and the memory acceleration size of a heap memory corresponding to the current scene, and then GC is triggered in the current scene according to the memory waterline. The corresponding scene can be determined according to the scene information, the resident memory size and the memory acceleration size of the heap memory corresponding to different scenes may be different, and then the determined memory waterlines may be different. Therefore, different waterlines are adopted to trigger the GC in different scenes, the effect of dynamically controlling the GC frequency can be achieved, the power consumption overhead of equipment is reduced, and the performance of the equipment is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of terminal technology, and in particular to GC methods and electronic equipment. Background Art

[0002] Currently, electronic device systems can manage memory through garbage collection (GC) mechanisms. For example: Android The system can use the Android Runtime (ART) virtual machine to provide a GC function, and manage the Java heap memory through the GC function, such as performing GC on Java objects, native objects, etc.

[0003] Among them, the ART virtual machine triggers GC according to the set memory watermark. That is to say, when the size of the heap memory requested by the application reaches the set memory watermark, the ART virtual machine starts to perform GC on the heap memory to release some of the occupied memory. The size of the memory watermark will affect the frequency and intensity of GC, and thus affect the power consumption of the device. Summary of the invention

[0004] The present application provides a GC method and an electronic device, which can dynamically adjust the memory waterline that triggers GC, reduce the power consumption overhead of the device, and improve the performance of the device.

[0005] In order to achieve the above objectives, this application adopts the following technical solutions:

[0006] In a first aspect, a GC method is provided, which is applied to an electronic device, and the method includes: obtaining scene information, where the scene information is used to characterize a current scene; determining a memory waterline corresponding to the scene information, where the memory waterline is determined based on a first parameter, where the first parameter includes at least one of a resident memory size and a memory growth rate size of a heap memory corresponding to the current scene; triggering GC in the current scene according to the memory waterline, for example: in the current scene, when the amount of heap memory occupied exceeds (i.e., is greater than) the memory waterline, triggering GC.

[0007] In some embodiments, different service types in the same application correspond to different scenarios. In some examples, the scenario can be divided at a coarse granularity, such as in this example, the scenario can include but is not limited to video scenarios, search scenarios, waterfall scenarios, etc. For example, the scenario corresponding to the video service is the video scenario, and the scenario corresponding to the search service is the search scenario, that is, the video service and the search service correspond to different scenarios. In other examples, the scenario can also be divided at a finer granularity, such as in this example, the scenario can include but is not limited to video on demand scenarios, live broadcast scenarios, search scenarios, waterfall scenarios, etc.

[0008] Optionally, in this embodiment, the scene information may include but is not limited to one or more of an application identifier, an activity identifier, a control type, etc. Exemplarily, the control type may include but is not limited to one or more of a video control (such as a surface view), a search control (such as a search box), a waterfall flow control (such as a list view), etc. Optionally, the corresponding business type may be determined through the scene information, and then the corresponding scene may be determined.

[0009] In some application scenarios, the same business type may correspond to the same activity.

[0010] In other application scenarios, the same service type may correspond to different activities, and different activities may correspond to the same scene. For example, if the service corresponding to activity1 is a video service and the service corresponding to activity2 is also a video service, then activity1 and activity2 correspond to the same scene, such as both are video scenes.

[0011] Of course, in a specific implementation, different activities can also be divided into different scenes. For example, activity1, activity2, and activity3 correspond to different scenes. Exemplarily, in this implementation, the scene information may include but is not limited to an application identifier and an activity identifier.

[0012] In some other embodiments, different applications correspond to different scenarios. For example, video application a, video application b, social application a, phone application a, phone application c, etc. correspond to different scenarios. Exemplarily, in this embodiment, the scenario information may include but is not limited to the application identifier.

[0013] Based on the above technical solution, the corresponding scene can be determined according to the scene information. The memory watermark determined according to at least one of the resident memory size and memory growth rate size of the corresponding heap memory in different scenes may be different. Therefore, different memory watermarks can be used to trigger GC in different scenes, which can achieve the effect of dynamically controlling the GC frequency. While reducing the power consumption of the device, the performance of the device can be improved.

[0014] In one possible design, before determining the memory waterline corresponding to the scene information, the method further includes: determining a second parameter based on the first parameter, the second parameter including at least one of a target heap maximum free memory and a target heap utilization; and determining the memory waterline based on the second parameter. Based on this design, the maximum free memory of the heap and the heap utilization are determined by the resident memory size and the memory growth rate of the heap memory, that is, the maximum free memory of the heap and the heap utilization are adjusted, and the size of the maximum free memory of the heap and the heap utilization will affect the frequency of GC, and then the memory waterline that triggers GC is determined based on the adjusted maximum free memory of the heap and the heap utilization, so as to achieve the purpose of dynamically controlling the GC frequency.

[0015] In a possible design, determining the second parameter according to the first parameter includes: obtaining preset parameters, the preset parameters include a preset GC interval, a preset maximum free memory of the heap, a preset heap expansion factor, and a preset heap utilization, wherein the preset GC interval is the interval between two GCs, and the preset heap expansion factor is greater than 1, such as the preset heap expansion factor can be 3; determining the second parameter according to the preset parameters and the first parameter. Based on this design, since the size of the maximum free memory of the heap and the heap utilization will affect the frequency of GC, by combining the system's preset maximum free memory of the heap, the heap utilization, etc. to determine the final maximum free memory of the heap and the heap utilization, a more appropriate maximum free memory of the heap and the heap utilization can be obtained, thereby making the frequency of GC better, reducing the power consumption of the device and improving the performance of the device.

[0016] In a possible design, the first parameter includes the memory growth rate, and the second parameter includes the maximum free memory of the target heap; the maximum free memory of the target heap satisfies the following formula:

[0017]

[0018] Among them, maxFree1 is the maximum free memory of the target heap, max Free2 is the maximum free memory of the preset heap, and S is the memory growth rate.

[0019] Based on this design, since the larger the maximum free memory of the heap is, the lower the frequency of GC is. Therefore, the maximum free memory of the heap that is finally used is the maximum value of the maximum free memory of the heap preset by the system and the maximum free memory calculated according to the memory growth rate, which can reduce the GC frequency and thus achieve the purpose of reducing the power consumption of the device.

[0020] In a possible design, the first parameter includes the resident memory size and the memory growth rate, and the second parameter includes the target heap utilization rate; the target heap utilization rate satisfies the following formula:

[0021]

[0022] Among them, S is the memory speed increase size, and M3 is the resident memory size.

[0023] Based on this design, the lower the heap utilization, the lower the GC frequency. Therefore, the final heap utilization is the minimum value between the system preset heap utilization and the heap utilization calculated based on the resident memory size and memory growth rate size, which can reduce the GC frequency and thus achieve the purpose of reducing the power consumption of the device.

[0024] In one possible design, when there is an interactive event in the current scene, the preset GC interval time is set to a first value; when there is no interactive event in the current scene, the preset GC interval time is set to a second value, and the first value is greater than the second value. An interactive event refers to an event in which a user interacts with an electronic device. Based on this design, when there is a user interactive event, a larger preset GC interval time is used, so that a larger memory waterline can be determined. This can make the GC frequency lower, reduce the probability of user interactive events being blocked by GC, and thus reduce the probability of users feeling that the electronic device is stuck.

[0025] In a possible design, when the preset GC interval is a first value, the memory watermark is valid within the preset time. Based on this design, the memory watermark determined according to the preset GC interval of the first value may be larger, so setting a certain effective time for the larger memory watermark can reduce the probability of not performing GC for a long time, thereby allowing the temporary memory of the application to be released in time, improving the performance of the device.

[0026] In a possible design, before obtaining the scene information, the method further includes: obtaining a third parameter corresponding to the scene information, the third parameter including: the time when the previous GC ended, the heap memory size when the previous GC ended, the time when the next GC ended, the heap memory size before the next GC ended, and the previous GC and the next GC are two adjacent GCs; determining the memory growth rate according to the third parameter. Based on this design, the memory growth rate corresponding to different scene information can be determined based on the time when the previous GC ended, the heap memory size when the previous GC ended, the time when the next GC ended, and the heap memory size before the next GC ended in two adjacent GCs, and then the memory waterline corresponding to different scene information can be determined.

[0027] In a possible design, before obtaining the scene information, the method also includes: when the type of the next GC is non-lightweight GC, determining the resident memory size according to the heap memory size at the end of the next GC. Based on this design, since the lightweight GC can only clean up the temporary memory applied after the last GC, it cannot clean up the temporary memory applied before the last GC. Non-lightweight GC can clean up both the temporary memory applied after the last GC and the temporary memory applied before the last GC. Therefore, when the type of the next GC is non-lightweight GC, determining the resident memory size according to the heap memory size at the end of the next GC can improve the accuracy of the determined resident memory size, thereby improving the accuracy of the obtained memory waterline.

[0028] In one possible design, before determining the second parameter according to the first parameter, the method further includes: determining Based on this design, since the system preset minimum heap free memory is smaller than the system preset maximum heap free memory, if If it is less than the preset minimum free memory of the heap, it must be less than the preset maximum free memory of the heap. To reduce the power consumption of the device, it is necessary to reduce the frequency of GC. Therefore, to achieve this goal, it is necessary to increase the preset maximum free memory of the heap. However, if If the maximum free memory of the heap is smaller than the system preset, there is no need to adjust the system preset maximum free memory of the heap. Otherwise, the power consumption of the device will increase.

[0029] In one possible design, before determining the memory waterline corresponding to the scene information, the method also includes: obtaining the current memory utilization of the electronic device; determining that the memory utilization is less than or equal to a first threshold. Based on this design, when setting the memory waterline, the memory utilization is also taken into consideration, and when the memory utilization is low, the memory waterline is determined based on the scene information. In other words, when the memory utilization is high, the memory waterline is no longer determined based on the scene information. The memory waterline determined based on the scene information is higher, and the memory waterline not determined based on the scene information is lower. In other words, when the memory utilization is high, the frequency of GC is increased so that the occupied memory can be released in time, which can improve the performance of the device. When the memory utilization is low, the frequency of GC is reduced, and the power consumption of the device can be reduced without affecting the normal use of the memory.

[0030] In one possible design, before determining the memory waterline corresponding to the scene information, the method also includes: obtaining the current remaining memory size of the electronic device; determining that the remaining memory size is greater than or equal to a second threshold. Based on this design, when setting the memory waterline, the remaining memory of the system is also taken into account. When there is a lot of remaining memory, the memory waterline is determined based on the scene information. In other words, when there is little remaining memory, the memory waterline is no longer determined based on the scene information. The memory waterline determined based on the scene information is higher, and the memory waterline not determined based on the scene information is lower. In other words, when there is little remaining memory, the frequency of GC is increased so that the occupied memory can be released in time, which can improve the performance of the device. When there is a lot of remaining memory, the frequency of GC is reduced. Without affecting the normal use of memory, the power consumption of the device can be reduced.

[0031] In a possible design, the second parameter is determined based on the preset parameter and the first parameter, including: obtaining the current CPU utilization of the electronic device; determining a preset coefficient corresponding to the CPU utilization, the preset coefficient being greater than or equal to 1; and determining the second parameter based on the preset parameter, the first parameter, and the preset coefficient. Based on this design, when setting the memory waterline, the CPU utilization is also taken into account, and the frequency of GC will affect the CPU utilization, and then the second parameter is determined based on the CPU utilization, and then the memory waterline is determined, which can reduce the probability of system freezes.

[0032] In a possible design, the CPU utilization is positively correlated with a preset coefficient.

[0033] In a possible design, the maximum free memory of the target heap satisfies the following formula:

[0034]

[0035] Among them, maxFree3 is the maximum free memory of the target heap, max Free2 is the maximum free memory of the preset heap, and S is the memory growth rate.

[0036] Based on this design, the maximum free memory of the heap is calculated by the preset coefficient, memory speed-up size, etc., and the preset coefficient corresponds to the CPU utilization. In this way, when the CPU utilization is high, the preset coefficient can be used to increase the size of the maximum free memory of the heap, thereby increasing the memory waterline and achieving the purpose of reducing the frequency of GC. In turn, the CPU utilization can be reduced, reducing the probability of system freezes.

[0037] In a possible design, the target heap utilization satisfies the following formula:

[0038]

[0039] Among them, S is the memory speed increase size, and M3 is the resident memory size.

[0040] Based on this design, the heap utilization is calculated by the preset coefficient, the resident memory size, the memory speed-up size, etc., and the preset coefficient corresponds to the CPU utilization. In this way, when the CPU utilization is high, the calculated heap utilization can be reduced by the preset coefficient, thereby increasing the memory waterline, and achieving the purpose of reducing the GC frequency. In turn, the CPU utilization can be reduced, and the probability of system freezes can be reduced.

[0041] In one possible design, the scene information includes at least one of an application identifier and an activity identifier.

[0042] In a second aspect, an electronic device is provided, which has the function of implementing the method described in the first aspect and any of the designs thereof. The function can be implemented by hardware, or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above functions. In a possible example, the electronic device includes an acquisition unit (or acquisition module) and a processing unit (or processing module); the acquisition unit is used to acquire scene information, and the scene information is used to characterize the current scene; the processing unit is used to: determine the memory waterline corresponding to the scene information, the memory waterline is determined according to a first parameter, and the first parameter includes at least one of the resident memory size and memory growth rate size of the heap memory corresponding to the current scene; trigger GC in the current scene according to the memory waterline.

[0043] In one possible design, the processing unit is further used to: determine a second parameter based on the first parameter, the second parameter including at least one of a target heap maximum free memory and a target heap utilization rate; and determine a memory waterline based on the second parameter.

[0044] In one possible design, the acquisition unit is also used to obtain preset parameters, which include a preset GC interval, a preset heap maximum free memory, a preset heap expansion coefficient, and a plurality of preset heap utilization rates. The preset GC interval is the interval between two GCs, and the preset heap expansion coefficient is greater than 1; the processing unit is also used to determine the second parameter based on the preset parameters and the first parameter.

[0045] In a possible design, the first parameter includes the memory growth rate, and the second parameter includes the maximum free memory of the target heap; the maximum free memory of the target heap satisfies the following formula:

[0046]

[0047] Among them, maxFree1 is the maximum free memory of the target heap, max Free2 is the maximum free memory of the preset heap, and S is the memory growth rate.

[0048] In a possible design, the first parameter includes the resident memory size and the memory growth rate, and the second parameter includes the target heap utilization rate; the target heap utilization rate satisfies the following formula:

[0049]

[0050] Among them, S is the memory speed increase size, and M3 is the resident memory size.

[0051] In one possible design, when there is an interaction event in the current scene, the preset GC interval time is taken as a first value; when there is no interaction event in the current scene, the preset GC interval time is taken as a second value, the first value is greater than the second value, and the interaction event refers to an event in which a user interacts with an electronic device.

[0052] In a possible design, when the preset GC interval time is a first value, the memory waterline is valid within the preset time.

[0053] In one possible design, the acquisition unit is also used to obtain a third parameter corresponding to the scene information, where the third parameter includes: the time when the previous GC ended, the heap memory size when the previous GC ended, the time when the next GC ended, the heap memory size before the next GC ended, and the previous GC and the next GC are two adjacent GCs; the processing unit is also used to determine the memory growth rate based on the third parameter.

[0054] In a possible design, the processing unit is further used to determine the resident memory size according to the heap memory size at the end of the next GC when the type of the next GC is non-lightweight GC.

[0055] In one possible design, the processing unit is also used to determine Greater than the preset minimum free memory of the heap.

[0056] In one possible design, the acquisition unit is also used to obtain the current memory utilization of the electronic device; the processing unit is also used to determine whether the memory utilization is less than or equal to a first threshold.

[0057] In one possible design, the acquisition unit is also used to obtain the current remaining memory size of the electronic device; the processing unit is also used to determine whether the remaining memory size is greater than or equal to a second threshold.

[0058] In one possible design, the acquisition unit is also used to obtain the current central processing unit CPU utilization of the electronic device; the processing unit is also used to: determine a preset coefficient corresponding to the CPU utilization, the preset coefficient is greater than or equal to 1; determine the second parameter based on the preset parameter, the first parameter, and the preset coefficient.

[0059] In a possible design, the maximum free memory of the target heap satisfies the following formula:

[0060]

[0061] Among them, maxFree3 is the maximum free memory of the target heap, max Free2 is the maximum free memory of the preset heap, and S is the memory growth rate.

[0062] In a possible design, the target heap utilization satisfies the following formula:

[0063] Target heap utilization = min(preset heap utilization,

[0064] Among them, S is the memory speed increase size, and M3 is the resident memory size.

[0065] In one possible design, the scene information includes at least one of an application identifier and an activity identifier.

[0066] In a third aspect, an electronic device is provided, comprising a processor and a memory, wherein the memory is coupled to the processor, the memory is used to store computer program code, the computer program code comprises computer instructions, and the processor reads the computer instructions from the memory so that the electronic device executes the method described in the first aspect and any one of the designs thereof.

[0067] In one possible design, the electronic device further includes a communication interface, which can be used for the electronic device to communicate with other devices. Exemplarily, the communication interface can be a transceiver, an input / output interface, an interface circuit, an output circuit, an input circuit, a pin or a related circuit, etc.

[0068] In a fourth aspect, a computer-readable storage medium is provided, the computer-readable storage medium comprising a computer program or instructions, which, when executed on an electronic device, enables the electronic device to execute the method described in the first aspect and any one of the designs thereof.

[0069] In a fifth aspect, a computer program product is provided. When the computer program product is run on a computer, the computer can execute the method described in the first aspect and any one of the designs thereof.

[0070] According to a sixth aspect, a circuit system is provided, the circuit system comprising a processing circuit, wherein the processing circuit is configured to execute the method described in any one of the designs of the first aspect.

[0071] In the seventh aspect, a chip system is provided, comprising at least one processor and at least one interface circuit, wherein the at least one interface circuit is used to perform transceiver functions and send instructions to at least one processor, and when the at least one processor executes the instructions, the at least one processor executes the method described in the first aspect and any one of the designs thereof.

[0072] It should be noted that the technical effects brought about by any design in the above-mentioned second to seventh aspects can refer to the technical effects brought about by the corresponding design in the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0074] Figure 2 A schematic diagram of the structure of another electronic device provided in an embodiment of the present application;

[0075] Figure 3 A schematic diagram of the structure of another electronic device provided in an embodiment of the present application;

[0076] Figure 4 A schematic diagram of a GC method provided in an embodiment of the present application;

[0077] Figure 5 A schematic diagram of a scenario provided for an embodiment of the present application;

[0078] Figure 6 A schematic diagram of another GC method provided in an embodiment of the present application;

[0079] Figure 7 A schematic diagram of another GC method provided in an embodiment of the present application;

[0080] Figure 8 A schematic diagram of the result of triggering GC provided in an embodiment of the present application;

[0081] Fig. 9 A schematic diagram of another GC method provided in an embodiment of the present application;

[0082] Fig.10 A schematic diagram of another GC method provided in an embodiment of the present application;

[0083] Fig.11 A schematic diagram of the structure of another electronic device provided in an embodiment of the present application;

[0084] Fig.12 A schematic diagram of the structure of a chip system provided in an embodiment of the present application. DETAILED DESCRIPTION

[0085] The technical solution provided in the embodiments of the present application is described in detail below with reference to the accompanying drawings.

[0086] The terms "including" and "having" and any variations thereof mentioned in the description of this application are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device comprising a series of steps or units is not limited to the listed steps or units, but may optionally include other 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.

[0087] It should be noted that, in the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.

[0088] In the description of this application, unless otherwise specified, the meaning of "plurality" refers to two or more. "And / or" in this article is only a description of the association relationship of 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.

[0089] Android system is The Android system is built for the kernel. In order to reduce the difficulty of application development and adapt applications to devices with different hardware configurations, the Android system builds a virtual machine on top of the Linux kernel. The use of the virtual machine separates Android applications from the Linux kernel, making the Android system more stable and reliable.

[0090] Android applications are developed using the Java language. The Java language divides memory into two types: stack memory and heap memory. Both the stack and the heap are used to store data in memory. Among them, the Android system uses the ART virtual machine to manage the heap memory since version 5.0, such as memory allocation and GC for Java objects and Native objects referenced by Java. It can be understood that Native objects can refer to objects in Native methods, and Native methods can be used to call some codes that are not written in the Java language.

[0091] Generally speaking, for each Android application process, an ART virtual machine can be created to assist in running. When the ART virtual machine performs GC on the heap memory of the Android application, it is triggered according to the set memory watermark. When the size of the heap memory requested by the Android application exceeds the set memory watermark, the ART virtual machine starts to perform GC on the heap memory to release some of the occupied memory. Among them, there are two types of GC: lightweight (sticky) GC and non-lightweight GC. Lightweight GC can clean up temporary memory requested after the last GC, but does not clean up temporary memory requested before the last GC. Non-lightweight GC can clean up both temporary memory requested after the last GC and temporary memory requested before the last GC.

[0092] At present, after each execution of GC, the above memory watermark is updated according to the allocated memory (or occupied memory, or used memory, etc.) of the Android application and the system parameters predefined by the Android system, so as to trigger GC according to the updated memory watermark next time. Exemplarily, the system parameters include the maximum free memory of the heap, the minimum free memory of the heap, the heap memory utilization, the heap expansion factor, etc. The memory watermark can be determined according to Formula 1.

[0093] Memory waterline = target_foorpr int - allocated memory of the last GC process Formula 1

[0094] In formula 1, the memory allocated in the last GC process is the memory occupied by the last GC process. It can be understood that GC may take some time to complete, and the GC process also needs to occupy memory. And the memory occupied by this GC process cannot be released in this GC. target_foorpr int is a variable, and the memory waterline can be updated as target_foorpr int is updated.

[0095] In some examples, when the previous GC is a non-lightweight GC, target_foorpr int may be determined according to Formula 2 and Formula 3.

[0096]

[0097] It can be understood that in the embodiment of the present application, minFree represents the minimum free memory of the heap, maxFree represents the maximum free memory of the heap, and allocated memory represents the allocated memory of the application.

[0098] target_foorpr int = grow_bytes * heap expansion factor + allocated memory Formula 3

[0099] In some other examples, when the previous GC is a lightweight GC, target_foorpr int may be determined according to Formula 4.

[0100]

[0101] The size of the memory watermark affects the frequency and intensity of GC. If the memory watermark is set too small, and the application process creates objects (such as Java objects) very quickly, the number of GCs will be too high, which will increase the power consumption of the device and cause users to feel that the operation is slow in some scenarios. If the memory watermark is set too large, it will lead to memory waste and even insufficient memory for the entire device, causing performance problems for the device.

[0102] In order to reduce the frequency of GC, a solution is proposed in the relevant technology. Android application processes are divided into three levels, namely, perceptible processes, imperceptible processes and foreground processes. If GC is performed on perceptible processes and imperceptible processes, the above formula is directly used to determine the memory waterline. If GC is performed on the foreground process, the maximum free memory of the heap is directly doubled and then the memory waterline is determined according to the above formula, but this method may make the determined memory waterline too large. For some applications with large temporary memory and low memory growth rate, this method will not perform GC for a long time, and then the temporary memory of the application cannot be released, resulting in memory waste, and even insufficient memory of the entire device, causing performance problems of the device, and the applicable scenarios are limited.

[0103] Based on this, the present application provides a GC method that can dynamically adjust the memory waterline that triggers GC, thereby controlling the frequency of GC, thereby improving the performance of the device while reducing the power consumption overhead of the device.

[0104] The technical solution provided in the embodiments of the present application can be applied to electronic devices, or to a system including electronic devices.

[0105] For example, the electronic device may be a mobile phone, a tablet computer, a handheld computer, a netbook, a personal digital assistant (PDA), an augmented reality (AR) device, a virtual reality (VR) device, an artificial intelligence (AI) device, a wearable device, and the wearable device includes but is not limited to a smart watch, a smart bracelet, a smart anklet, etc. The operating system installed on the electronic device includes but is not limited to Or other operating systems with similar GC mechanisms. This application does not limit the specific type of electronic equipment or the installed operating system.

[0106] For example, taking the electronic device as a mobile phone, Figure 1 A schematic structural diagram of a mobile phone provided in an embodiment of the present application is shown.

[0107] like Figure 1 As shown, the mobile phone may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc.

[0108] 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. Different processing units may be independent devices or integrated into one or more processors.

[0109] The controller can generate operation control signals according to the instruction operation code and timing signal to complete the control of instruction fetching and execution.

[0110] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.

[0111] In some embodiments, processor 110 may include one or more interfaces.

[0112] The charging management module 140 is used to receive charging input from a charger, where the charger can be a wireless charger or a wired charger.

[0113] The power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140 to power the processor 110, the internal memory 121, the display screen 194, the camera 193, and the wireless communication module 160.

[0114] The wireless communication function of the mobile phone can be realized through antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modem processor and baseband processor.

[0115] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in the mobile phone can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve the utilization of the antennas. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In some other embodiments, the antenna can be used in combination with a tuning switch.

[0116] The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc., applied to mobile phones. The mobile communication module 150 can include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc.

[0117] The wireless communication module 160 can provide wireless communication solutions for use on mobile phones, including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication technology (NFC), infrared technology (IR), etc.

[0118] In some embodiments, the antenna 1 of the mobile phone is coupled to the mobile communication module 150, and the antenna 2 is coupled to the wireless communication module 160, so that the mobile phone can communicate with the network and other devices through wireless communication technology.

[0119] The mobile phone realizes display functions through a GPU, a display screen 194, and an application processor.

[0120] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel.

[0121] The camera 193 is used to capture static images or videos. In some embodiments, the mobile phone may include 1 or N cameras 193, where N is a positive integer greater than 1.

[0122] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the mobile phone. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function.

[0123] The internal memory 121 may be used to store computer executable program codes, which include instructions. The internal memory 121 may include a program storage area and a data storage area.

[0124] The audio module 170 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 mobile phone can use the audio module 170, such as music playback, recording, etc. The audio module 170 may include a speaker, a receiver, a microphone, an earphone interface, and an application processor to implement audio functions.

[0125] Optionally, the sensor module 180 may include one or more of a pressure sensor, a gyroscope sensor, an air pressure sensor, a magnetic sensor, an acceleration sensor, a distance sensor, a fingerprint sensor, a temperature sensor, an ambient light sensor, a bone conduction sensor, and the like.

[0126] The buttons 190 include a power button, a volume button, etc. The buttons 190 may be mechanical buttons or touch buttons.

[0127] Motor 191 can generate vibration prompts.

[0128] Indicator 192 may be an indicator light, which may be used to indicate charging status, power changes, messages, missed calls, notifications, etc.

[0129] The SIM card interface 195 is used to connect a SIM card.

[0130] For example, the above only uses a mobile phone as an example to illustrate the structure of the electronic device in the embodiment of the present application, but does not constitute a limitation on the structure and form of the electronic device. The embodiment of the present application does not limit the structure and form of the electronic device. For example, Figure 2 Another exemplary structure of an electronic device is shown. Figure 2As shown, the electronic device includes: a processor 201, a memory 202, and a transceiver 203. The implementation of the processor 201 and the memory 202 can be found in Figure 1 The implementation of the processor and memory shown. The transceiver 203 can be used for the electronic device to interact with other devices (such as electronic devices). The transceiver 203 can be based on devices such as Wi-Fi, Bluetooth or other communication protocols.

[0131] It is understandable that the structure shown in the embodiment of the present application does not constitute a specific limitation on the electronic device. Figure 1 , Figure 2 More or fewer components are shown, or some components are combined, or some components are separated, or different component arrangements are arranged. The components shown in the figure can be implemented in hardware, software, or a combination of software and hardware.

[0132] In some embodiments, the software system of the electronic device may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. The embodiment of the present invention takes the Android system of the layered architecture as an example to exemplify the software structure of the electronic device.

[0133] Figure 3 A software structure block diagram of an electronic device provided in an embodiment of the present application is shown.

[0134] The layered architecture divides the software into several layers, each with a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system may include four layers, from top to bottom, namely, the application layer, the system framework layer, the Android runtime and system library, and the kernel layer.

[0135] The application layer includes a virtual machine stack module 301 , an information reporting module 302 , a parameter setting module 303 and the like.

[0136] The virtual machine heap module 301 may be used to perform GC on the heap memory requested by the application according to the memory waterline.

[0137] The information reporting module 302 can be used to collect heap related information and report the heap related information to the data collection and processing module 311 of the system framework layer. Please refer to the following for an introduction to the heap related information.

[0138] The parameter setting module 303 can be used to set the heap-related parameters in the virtual machine heap module 301. The heap-related parameters can be used to calculate the memory watermark that triggers GC. For an introduction to the heap-related parameters, please refer to the following description.

[0139] The system framework layer includes a data collection and processing module 311 , an activity management service (AMS) module 312 , a data management module 313 , and a parameter decision module 314 .

[0140] The data collection and processing module 311 can be used to receive the heap-related information reported by the application layer information reporting module 302, and determine the memory growth rate (hereinafter referred to as memory growth rate), resident memory size, etc. of the heap memory in different scenarios according to the heap-related information. It can be understood that resident memory refers to memory that cannot be released when GC is performed.

[0141] The AMS module 312 may be used to manage the life cycle of the application during runtime. In some embodiments of the present application, the AMS module 302 may be used to monitor scene information and report the monitored scene information to the data management module 313 .

[0142] The data management module 313 may be used to receive the scene information reported by the AMS module, determine whether the current scene has changed according to the scene information, and determine the memory growth rate, resident memory size, etc. corresponding to the current scene. In some embodiments, the data management module 313 may send the memory growth rate, resident memory size, preset GC interval time, etc. corresponding to the current scene to the parameter decision module 314. For an introduction to the preset GC interval time, please refer to the following description.

[0143] In some other embodiments, the data management module 313 may also be used to obtain the system load and send the system load to the parameter decision module 314. Please refer to the following for an introduction to the system load.

[0144] The parameter decision module 314 can be used to calculate the heap-related parameters according to various parameters such as the memory growth rate, resident memory size, preset GC interval time, system load, etc. corresponding to the current scenario. The parameter decision module 314 can also send the calculated heap-related parameters to the parameter setting module 303 of the application layer.

[0145] In some embodiments, the system framework layer may further include an input management service (IMS) module 315. The IMS module 315 may be used to manage input events, input devices, etc. In some embodiments of the present application, the IMS module 315 may be used to monitor interaction events between a user and an electronic device (hereinafter referred to as user interaction events). The IMS module 315 may also send the user interaction event to the data management module 313.

[0146] In some embodiments, after receiving the user interaction event reported by the IMS module 315, the data management module 313 can determine a new preset GC interval according to the user interaction event, and send the new preset GC interval to the parameter decision module 314. For an introduction to the new preset GC interval, please refer to the following description.

[0147] In some embodiments, after receiving the new preset GC interval reported by the data management module 313, the parameter decision module 314 can also calculate heap-related parameters based on multiple parameters such as the memory growth rate, resident memory size, new preset GC interval, system load, etc. corresponding to the current scenario.

[0148] The Android runtime includes the core library and the virtual machine. The Android runtime is responsible for the scheduling and management of the Android system.

[0149] The core library consists of two parts: one part is the function that needs to be called by the Java language, and the other part is the Android core library.

[0150] The application layer and the system framework layer run in the virtual machine. The virtual machine executes the Java files of the application layer and the system 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.

[0151] The system library may include multiple functional modules, such as surface manager, media library, 3D graphics processing library (such as OpenGL ES), 2D graphics engine (such as SGL), etc.

[0152] The kernel layer is the layer between hardware and software. The kernel layer contains at least display driver, audio driver, and sensor driver.

[0153] Understandably, Figure 3 The layers shown are only exemplary. In actual applications, the electronic device may include more or fewer layers. Figure 3 The division of the levels shown and the modules included in each level are only exemplary and do not constitute a limitation of this application. In practical applications, there may be other division methods, each module may be located at different levels, or different modules may be integrated into one module, etc., and this application does not limit this.

[0154] The technical solutions involved in the following embodiments can all be used in Figure 1 , Figure 2 , Figure 3 It appears in the device with the structure shown in the figure.

[0155] It is understandable that in the embodiments of the present application, the electronic device can perform some or all of the steps in the embodiments of the present application, and these steps or operations are only examples. The embodiments of the present application can also perform other operations or variations of various operations. In addition, the various steps can be performed in different orders presented in the embodiments of the present application, and it is possible that not all operations in the embodiments of the present application need to be performed.

[0156] In some embodiments, the electronic device can determine the memory growth rate and / or resident memory size corresponding to the current scenario based on the heap-related information, and then calculate the heap-related parameters based on the memory growth rate and / or resident memory size corresponding to the current scenario, preset the GC interval time, etc., and determine the memory waterline corresponding to the current scenario based on the heap-related parameters. Subsequently, in this scenario, the electronic device can use the memory waterline corresponding to the scenario for GC.

[0157] Combination Figure 3 The architecture shown in this embodiment is as follows: Figure 4 A schematic diagram of a GC method provided in an embodiment of the present application is shown. Figure 4 As shown, the method comprises the following steps:

[0158] S401: The information reporting module obtains heap-related information from the virtual machine heap module.

[0159] In some examples, the heap related information may include, but is not limited to, the size of memory released by each GC, the size of heap memory after each GC, the type of each GC, the data in the heap memory before and after each GC, the timestamp of the end of each GC, and the scene information corresponding to each GC. Among them, the scene information can be used to determine the scene. In some examples, the scene information may include, but is not limited to, at least one of an application identity (ID), an activity ID, or an ability ID.

[0160] In some embodiments, different service types in the same application correspond to different scenarios. In some examples, the scenario can be divided at a coarse granularity, such as in this example, the scenario can include but is not limited to video scenarios, search scenarios, waterfall scenarios, etc. For example, the scenario corresponding to the video service is the video scenario, and the scenario corresponding to the search service is the search scenario, that is, the video service and the search service correspond to different scenarios. In other examples, the scenario can also be divided at a finer granularity, such as in this example, the scenario can include but is not limited to video on demand scenarios, live broadcast scenarios, search scenarios, waterfall scenarios, etc.

[0161] Optionally, in this embodiment, the scene information may include but is not limited to one or more of an application identifier, an activity identifier, a control type, etc. Exemplarily, the control type may include but is not limited to one or more of a video control (such as a surface view), a search control (such as a search box), a waterfall flow control (such as a list view), etc. Optionally, the corresponding business type may be determined through the scene information, and then the corresponding scene may be determined.

[0162] In some application scenarios, the same business type may correspond to the same activity.

[0163] In other application scenarios, the same service type may correspond to different activities, and different activities may correspond to the same scene. For example, if the service corresponding to activity1 is a video service and the service corresponding to activity2 is also a video service, then activity1 and activity2 correspond to the same scene, such as both are video scenes.

[0164] Of course, in a specific implementation, different activities can also be divided into different scenes. For example, activity1, activity2, and activity3 correspond to different scenes. Exemplarily, in this implementation, the scene information may include but is not limited to an application identifier and an activity identifier.

[0165] In some other embodiments, different applications correspond to different scenarios. For example, video application a, video application b, social application a, phone application a, phone application c, etc. correspond to different scenarios. Exemplarily, in this embodiment, the scenario information may include but is not limited to the application identifier.

[0166] Exemplarily, after one or more GCs are completed, the information reporting module may obtain heap-related information from the virtual machine heap module. The embodiment of the present application does not specifically limit the timing when the information reporting module obtains heap-related information.

[0167] S402: The information reporting module sends the heap related information to the data collection and processing module. Correspondingly, the data collection and processing module receives the heap related information from the information reporting module.

[0168] S403: The data collection and processing module determines the memory growth rate and / or resident memory size corresponding to different scenarios according to the heap-related information.

[0169] In some embodiments, for any scenario, the data collection and processing module can determine the memory growth rate according to the growth time of the heap memory and the growth amount of the heap memory in the scenario. Exemplarily, the data collection and processing module can determine the growth time of the heap memory according to the time when the previous GC ends and the time when the next GC ends, and determine the growth amount of the heap memory according to the size of the heap memory when the previous GC ends and the size of the heap memory before the next GC ends. The previous GC and the next GC can be any two adjacent GCs.

[0170] For example, Figure 5 A schematic diagram showing the growth time and growth amount of a heap memory provided by an embodiment of the present application is shown. Figure 5 As shown in the figure, at time T1, the previous GC execution ends, and the size of the heap memory is M1. At time T2, the current GC ends, and before the heap memory is cleaned up, the size of the heap memory is M2, and after the heap memory is cleaned up, the size of the heap memory is M3.

[0171] Then the heap memory growth amount M can satisfy Formula 5, the heap memory growth time T can satisfy Formula 6, and the memory growth rate S can satisfy Formula 7.

[0172] M=M2-M1 Formula 5

[0173] T=T2-T1 Formula 6

[0174]

[0175] However, since light GC can only clean up temporary memory applied after the last GC, it cannot clean up temporary memory applied before the last GC. Non-light GC can clean up temporary memory applied after the last GC as well as temporary memory applied before the last GC. If the type of this GC is light GC, since the cleaned heap memory may also include temporary memory, it may not be possible to determine the resident memory in this case.

[0176] Therefore, in some embodiments, when the type of this GC is non-lightweight GC, the size of the heap memory after the heap memory is cleaned up after the GC ends, such as Figure 5 M3 shown determines the resident memory. For example, M3 is directly determined as the resident memory, or the resident memory is determined based on M3 and the error amount, etc. Then, the data collection and processing module can obtain the memory growth rate and the resident memory size corresponding to the current scene.

[0177] In some embodiments, for a scene, the data collection and processing module may also determine the memory growth rate and resident memory size corresponding to the current scene based on multiple memory growth rates and multiple resident memory sizes historically obtained for the scene.

[0178] As a specific implementation, when a scenario occurs more than or equal to a preset number threshold, the data collection and processing module can determine the memory growth rate corresponding to the scenario by counting multiple memory growth rates obtained from the scenario history. Similarly, the data collection and processing module can count multiple resident memory sizes obtained from the scenario history to determine the resident memory size corresponding to the scenario.

[0179] As a specific example, the data collection and processing module can sort the historically acquired memory growth rates, and determine the memory growth rate peak value based on the top 20% of the memory growth rates, and use the memory growth rate peak value as the memory growth rate corresponding to the current scenario. Exemplarily, the memory growth rate peak value Smax can satisfy Formula 8 or Formula 9.

[0180]

[0181] In Formula 8, a represents the number of memory growth rates historically obtained in the current scenario, Mn represents the growth amount of heap memory corresponding to each memory growth rate in the top 20% of memory growth rates, and Tn represents the growth time of heap memory corresponding to each memory growth rate in the top 20% of memory growth rates.

[0182]

[0183] In Formula 9, a represents the number of memory growth rates obtained in the current scene history. Indicates the first memory growth rate among the top 20% memory growth rates. It indicates the second memory growth rate among the top 20% memory growth rates, and so on, all the way to the top 20%a memory growth rate.

[0184] Based on the above method, when the memory growth rate is high, the frequency of GC is more frequent, and when the user interacts with the electronic device, the memory growth rate is usually high. In this way, the peak value of the memory growth rate is determined based on the large memory growth rate obtained in history, and the corresponding memory growth rate obtained in different scenarios is large. When the memory waterline is determined based on the large memory growth rate, the memory waterline is high. In this way, the frequency of GC can be reduced, the power consumption of the device can be reduced, and the probability of users feeling that the electronic device is stuck can also be reduced.

[0185] The data collection and processing module can also obtain the average value of the resident memory size obtained historically, and use the average value of the resident memory size as the resident memory size corresponding to the current scene. Exemplarily, the average value m3 of the resident memory size can satisfy Formula 10.

[0186]

[0187] In formula 10, a represents the number of resident memory sizes obtained in the current scene history. M31 Indicates the resident memory size of the first historical acquisition, M3 2 Indicates the resident memory size obtained by the second history, and so on, until the resident memory size M3 obtained by the ath history a .

[0188] It can be understood that the above method of calculating the peak value of memory growth rate is only for illustrative purposes, and this application does not impose any restrictions on the method of calculating the peak value of memory growth rate. In actual applications, there may also be other calculation methods, such as: sorting the historically obtained memory growth rates, and obtaining various statistical values ​​such as the mode, median, and mean of the memory growth rates of the top 10%, the top 30%, or the top 40%, etc., to obtain the peak value of memory growth rate. Similarly, the above method of calculating the resident memory size is also only for illustrative purposes, and this application does not impose any restrictions on the method of calculating the resident memory size. For example: various statistical values ​​such as the mode and median of some or all of the resident memory sizes obtained historically can also be obtained, and the statistical value can be used as the resident memory size corresponding to the scenario.

[0189] S404: The data collection and processing module sends the memory growth rate and / or resident memory size corresponding to different scenarios to the data management module. Accordingly, the data management module receives the memory growth rate and / or resident memory size corresponding to different scenarios from the data collection and processing module.

[0190] S405: The AMS module sends the scene information to the data management module. Correspondingly, the data management module receives the scene information from the AMS module.

[0191] For an introduction to the scene information, please refer to the relevant introduction in step S401.

[0192] S406: The data management module sends at least one of the memory growth rate, the resident memory size, and the preset GC interval time corresponding to the current scene to the parameter decision module according to the scene information. Correspondingly, the parameter decision module receives at least one of the memory growth rate, the resident memory size, and the preset GC interval time corresponding to the current scene from the data management module.

[0193] It can be understood that the preset GC interval time may refer to the interval time between two GCs. Optionally, the two GCs may be two adjacent GCs or may not be two adjacent GCs. In some examples, the preset GC interval time may be set by the developer based on human factors. Human factors may refer to the statistical results of different users' requirements for GC interval time, such as the preset GC interval time may be 2 seconds or other durations, and this application does not impose specific restrictions on this.

[0194] S407: The parameter decision module determines a heap-related parameter according to at least one of a memory growth rate, a resident memory size, and a preset GC interval time corresponding to the current scenario.

[0195] Among them, the heap-related parameters can be used to determine the memory watermark corresponding to the current scene, and the memory watermark can be used to trigger the GC in the current scene. Exemplarily, the heap-related parameters can include one or more of heap utilization, heap maximum free memory, etc.

[0196] Combined with the above, the following describes the process of determining the heap utilization and the maximum free memory of the heap according to the memory growth rate and resident memory size corresponding to different scenarios determined under non-lightweight GC.

[0197] As mentioned above, the memory waterline under non-lightweight GC can be calculated according to Formula 1, Formula 2, and Formula 3. Since the size of the allocated memory in the GC process is not fixed and is small, the allocated memory in the previous GC process is ignored. Then the memory waterline can satisfy Formula 11.

[0198]

[0199] Among them, in formula 11, memory waterline-allocated memory is the memory size of the heap memory added when the GC is triggered next time. In some embodiments, the size of the heap memory added can be determined according to the memory growth rate corresponding to different scenarios and the preset GC interval time. Exemplarily, the size of the heap memory added can satisfy formula 12.

[0200] H=S*Expected GC interval time Formula 12

[0201] In Formula 12, H represents the size of the newly added heap memory, and S represents the memory growth rate corresponding to different scenarios.

[0202] In formula 11, the allocated memory is the resident memory size corresponding to the different scenarios determined above. The newly added memory size of the heap memory is still represented by H, and the allocated memory, that is, the resident memory size is represented by M3, then formula 11 can be expressed as formula 13.

[0203]

[0204] According to formula 13, when When the value of is minFree, H has nothing to do with the heap utilization and the maximum free memory maxFree of the heap. The value is min(maxFree, There are two situations:

[0205] One is The value of Then the heap utilization can satisfy Formula 14.

[0206]

[0207] According to formula 14, the smaller the heap utilization is and the larger H is, the lower the GC frequency is. On the contrary, the larger the heap utilization is and the smaller H is, the higher the GC frequency is.

[0208] Combined with Formula 12, the heap utilization can satisfy Formula 15.

[0209]

[0210] Another is The value of is the maximum free memory maxFree of the heap, then the maximum free memory maxFree of the heap can satisfy Formula 16.

[0211]

[0212] According to formula 16, the larger the heap maximum free memory max Free is, the larger H is, and the lower the GC frequency is. On the contrary, the smaller the heap maximum free memory max Free is, the smaller H is, and the higher the GC frequency is.

[0213] Combined with formula 12, the maximum free memory max Free of the heap can satisfy formula 17.

[0214]

[0215] In some embodiments, the parameter decision module may also determine the maximum free memory of the heap used to calculate the memory waterline corresponding to the current scene based on the maximum free memory of the heap preset by the system, and the maximum free memory of the heap determined according to the memory growth rate corresponding to the current scene and the preset GC interval time, such as Formula 17. For example, the maximum free memory of the heap used to calculate the memory waterline corresponding to the current scene may satisfy Formula 18.

[0216]

[0217] Among them, in formula 18, maxFree1 is the maximum free memory of the heap used to calculate the memory waterline corresponding to the current scene, and max Free2 is the maximum free memory of the heap preset by the system. It can be understood that according to formula 16, the larger the maximum free memory of the heap, the lower the frequency of GC. Therefore, taking the maximum value of maxFree1 can reduce the GC frequency, thereby achieving the purpose of reducing the power consumption of the device.

[0218] In other embodiments, the parameter decision module may also determine the heap utilization ultimately used to calculate the memory waterline corresponding to the current scenario based on the system preset heap utilization, as well as the heap utilization determined based on the system preset heap expansion coefficient, the preset GC interval time, the memory growth rate corresponding to the current scenario, and the resident memory size, such as Formula 15.

[0219] Optionally, in an embodiment of the present application, a system preset heap expansion factor may be greater than 1, such as 3, or other values.

[0220] For example, the heap utilization rate ultimately used to calculate the memory waterline corresponding to the current scenario may satisfy Formula 19.

[0221]

[0222] Among them, in formula 19, heap utilization 1 is the heap utilization that is finally used to calculate the memory waterline corresponding to the current scenario, and heap utilization 2 is the heap utilization preset by the system. It can be understood that according to formula 14, the smaller the heap utilization, the lower the GC frequency. Therefore, taking the minimum value of heap utilization 1 can reduce the GC frequency, thereby achieving the purpose of reducing the power consumption of the device.

[0223] In this embodiment, Figure 6 The present invention provides a schematic diagram of a process for determining the heap utilization and the maximum free memory of the heap according to the memory growth rate and the resident memory size corresponding to the current scenario. Figure 6 As shown, the method comprises the following steps:

[0224] S601, the parameter decision module obtains the preset heap utilization, the minimum free memory of the heap, the preset maximum free memory of the heap, the heap expansion factor, the memory growth rate corresponding to the current scenario, the resident memory size, and the preset GC interval time.

[0225] S602: The parameter decision module determines whether the minimum free memory of the heap is less than

[0226] The minimum free memory of the heap and the heap expansion factor may also be preset by the system. The minimum free memory of the heap is the minFree mentioned above, and H is determined according to the memory growth rate corresponding to the current scenario and the preset GC interval time, as shown in Formula 12.

[0227] If yes, execute step S603, if no, execute step S604.

[0228] S603. The parameter decision module determines the maximum free memory of the heap and the heap utilization rate used to calculate the memory waterline corresponding to the current scenario according to Formula 18 and Formula 19 respectively.

[0229] S604: The parameter decision module does not recalculate the heap related parameters.

[0230] It can be understood that in the embodiment of the present application, the parameter decision module does not recalculate the heap-related parameters, which may refer to using the system-preset heap-related parameters (such as the maximum free memory of the heap, the heap utilization rate, etc.) to determine the memory waterline.

[0231] In some embodiments, the parameter decision module may also determine the heap-related parameters according to at least one of the memory growth rate, the resident memory size, the preset GC interval time, and the system load corresponding to the current scenario.

[0232] Exemplarily, the system load may include but is not limited to one or more of the central processing unit (CPU) load, memory load, etc. It is understood that the CPU load may refer to the utilization of the CPU. The memory load may refer to the utilization of the system memory, and the heap memory can be requested for use from the system memory. The higher the CPU utilization, the greater the CPU load. Similarly, the higher the memory utilization, the greater the memory load.

[0233] In this embodiment, as a possible implementation, the newly added size H1 of the heap memory mentioned above can be determined according to formula 20.

[0234] H1=S*expected GC interval time*preset coefficient Formula 20

[0235] Among them, in formula 20, the preset coefficient can be determined according to the current CPU load, and the mapping relationship between the CPU load and the preset coefficient. In some embodiments, the CPU load is positively correlated with the preset coefficient, that is, the higher the CPU load, the larger the preset coefficient. Exemplarily, the preset coefficient is greater than or equal to 1, such as the preset coefficient can be greater than or equal to 1 and less than or equal to 2. The value of the preset coefficient can be set by the developer according to actual needs. For the introduction of other parameters in formula 20, please refer to the introduction of the corresponding parameters in formula 12.

[0236] Correspondingly, the above formula 18 can be transformed into formula 21.

[0237]

[0238] Among them, in Formula 21, maxFree3 is the maximum free memory of the heap ultimately used to calculate the memory waterline corresponding to the current scene. For the introduction of other parameters in Formula 21, please refer to the introduction of the corresponding parameters in Formula 18 and Formula 20.

[0239] Correspondingly, the above formula 19 can be transformed into formula 22.

[0240]

[0241] Among them, in formula 22, heap utilization 3 is the heap utilization finally used to calculate the memory waterline corresponding to the current scene. For the introduction of other parameters in formula 22, please refer to the introduction of the corresponding parameters in formula 19 and formula 20.

[0242] Of course, Formula 21 and Formula 22 can also be expressed in the form shown in Formula 18 and Formula 19 according to Formula 20, which will not be shown in detail here.

[0243] In this embodiment, the system load includes memory load and CPU load as an example. Figure 7 The present invention provides a schematic diagram of a process for determining the heap utilization and the maximum free memory of the heap according to the memory growth rate, resident memory size, and system load corresponding to the current scenario. Figure 7 As shown, the method comprises the following steps:

[0244] S701. The parameter decision module obtains the preset heap utilization, the minimum free memory of the heap, the preset maximum free memory of the heap, the heap expansion factor, the memory growth rate corresponding to the current scenario, the resident memory size, the preset GC interval time, the memory load, and the CPU load.

[0245] S702: The parameter decision module determines whether the memory load is greater than a memory load threshold (ie, a first threshold).

[0246] If yes, execute step S705, if no, execute step S703.

[0247] Alternatively, step S702 may also be implemented as a parameter decision module determining whether the remaining memory of the system is less than a second threshold value. If yes, step S705 is executed, and if no, step S703 is executed.

[0248] S703, the parameter decision module determines whether the minimum free memory of the heap is less than

[0249] If yes, execute step S704, if no, execute step S705.

[0250] Optionally, the embodiment of the present application does not limit the execution order of step S702 and step S703.

[0251] S704. The parameter decision module determines the maximum free memory of the heap and the heap utilization rate used to calculate the memory waterline corresponding to the current scenario according to Formula 21 and Formula 22 respectively.

[0252] S705: The parameter decision module does not recalculate the heap related parameters.

[0253] For an introduction to this step, please refer to the above Figure 6 The relevant introduction of step S604 is shown.

[0254] It is understandable that when the CPU load is high, GC may take longer, and frequent GC will increase the CPU load and make the system more laggy. Figure 7 The solution shown in the figure also takes the CPU load into consideration when setting the memory waterline. When the CPU load is high, GC is suppressed and the GC frequency is reduced, which can reduce the CPU load and thus reduce the probability of system freezes. When setting the memory waterline, the memory load is also taken into consideration. When the memory load is high, the GC frequency is increased, which can release the occupied memory in time and improve the performance of the device.

[0255] S408: The parameter decision module sends the heap-related parameters to the parameter setting module. Correspondingly, the parameter setting module receives the heap-related parameters from the parameter decision module.

[0256] It can be understood that in this embodiment, the parameter decision module directly sends the heap-related parameters to the parameter setting module as an example. In other embodiments, the parameter setting module can also determine the memory waterline according to the heap-related parameters, such as calculating the memory waterline according to Formula 1 to Formula 4, and then sending the obtained memory waterline to the parameter setting module.

[0257] S409: The parameter setting module sets heap-related parameters for the virtual machine heap memory.

[0258] Subsequently, the virtual machine heap memory can trigger GC based on the memory waterline determined by the heap-related parameters.

[0259] Based on the solution described in this embodiment, the corresponding heap-related parameters are determined according to the scenario. The heap-related parameters corresponding to different scenarios are different, and the memory watermark obtained according to the heap-related parameters may also be different. The effect of dynamically controlling the GC frequency is achieved, and the performance of the device can be improved while reducing the power consumption of the device.

[0260] For example, a user slides on an application interface for 10 seconds. Figure 8 A schematic diagram of the result of triggering GC provided in an embodiment of the present application is shown. Figure 8 (1) is the number of GCs triggered by the memory waterline when the system preset heap utilization and the maximum free memory of the heap are used to determine the memory waterline in the existing solution. Figure 8 As shown in (1), when the system preset heap utilization is 0.75 and the maximum free memory maxFree is 8, a total of 15 GCs are triggered. Figure 8(2) is the number of GCs triggered by the memory waterline when the memory waterline is determined using the technical solution provided in the embodiment of the present application. For example, taking the corresponding memory growth rate of 40 megabits per second, the resident memory size of 50 megabits, the preset GC interval of 2 seconds, and the heap expansion factor of 3 in this scenario as an example, according to the above formula 15, According to the above formula 17, we can get When determining the memory waterline based on the heap utilization and maximum free memory of the heap calculated above, such as Figure 8 As shown in (2), a total of 4 GCs were triggered.

[0261] For example, Table 1 also shows some relevant data of the existing solution and the technical solution provided by the embodiment of the present application under this example.

[0262] Table 1

[0263]

[0264] As shown in Table 1, compared with the existing solutions, the technical solution provided by the embodiment of the present application shortens the time for blocking the UI thread during GC and also shortens the time for occupying the CPU.

[0265] from Figure 8 As can be seen from Table 1, the solution for determining the memory watermark for triggering GC provided in the embodiment of the present application reduces the frequency of GC, thereby reducing the power consumption of the device and improving the performance of the device.

[0266] In some embodiments, the electronic device can also determine a new preset GC interval time based on user interaction events, calculate heap-related parameters based on the new preset GC interval time and the memory growth rate and / or resident memory size corresponding to the current scene, and determine the memory waterline corresponding to the current scene based on the heap-related parameters.

[0267] Combination Figure 3 The architecture shown in this embodiment is as follows: Fig. 9 A schematic diagram of another GC method provided in the embodiment of the present application is shown. Fig. 9 As shown, the method comprises the following steps:

[0268] S901: The IMS module sends user interaction information to the data management module. Correspondingly, the data management module receives the user interaction information from the IMS module.

[0269] The user interaction information may be used to indicate that a user interaction event currently exists. Exemplarily, the user interaction event may include, but is not limited to, various operations performed by the user on the electronic device.

[0270] S902. The data management module sends at least one of the memory growth rate, the resident memory size, and the new preset GC interval time corresponding to the current scene to the parameter decision module according to the user interaction information. Accordingly, the parameter decision module receives at least one of the memory growth rate, the resident memory size, and the new preset GC interval time corresponding to the current scene from the data management module.

[0271] It is understandable that the new preset GC interval time may also refer to the interval time between two GCs. Optionally, the two GCs may be two adjacent GCs or may not be two adjacent GCs.

[0272] In some embodiments, the new preset GC interval time corresponds to the user interaction information. Optionally, for different interaction information, the corresponding new preset GC interval time may be the same or different. For example, different new preset GC interval times may be set according to the type of interaction information.

[0273] In some embodiments, the length of the new preset GC interval is greater than the length of the preset GC interval.

[0274] Optionally, in this step, the memory growth rate and resident memory size corresponding to the current scene can also be determined by the data management module according to the scene information sent by the AMS module and sent to the parameter decision module. Please refer to the above description for the method of determining the memory growth rate and resident memory size corresponding to the current scene.

[0275] S903: The parameter decision module determines a heap-related parameter according to at least one of a memory growth rate, a resident memory size, and a new preset GC interval time corresponding to the current scenario.

[0276] In some embodiments, the preset GC interval time may be replaced by a new preset GC interval time. For the specific implementation of this step, please refer to Figure 4 The relevant implementation of step S407 is shown.

[0277] S904: The parameter decision module sends the heap-related parameters to the parameter setting module. Correspondingly, the parameter setting module receives the heap-related parameters from the parameter decision module.

[0278] S905: The parameter setting module sets heap-related parameters for the virtual machine heap memory.

[0279] For an introduction to step S904 and step S905, please refer to Figure 4 The description of step S408 and step S409 is shown.

[0280] based on Fig. 9The described solution further determines a larger memory waterline when there is a user interaction event, which can make the GC frequency lower, reduce the probability of user interaction events being blocked by GC, and further reduce the probability of users feeling that the electronic device is stuck.

[0281] In some embodiments, the effective time of the heap-related parameters calculated in step S903 satisfies a preset time range (such as less than or equal to a preset duration threshold), that is, within the preset time range, the memory watermark that triggers GC can be determined based on the heap-related parameters. Otherwise, the memory watermark that triggers GC cannot be determined based on the heap-related parameters. In this way, since the memory watermark set according to this embodiment may be relatively large, setting a certain effective time for the relatively large memory watermark can reduce the probability of not performing GC for a long time, thereby allowing the temporary memory of the application to be released in time, thereby improving the performance of the device.

[0282] In some examples, the preset time range may also be set based on human factors or other factors, or may be set by a developer based on actual needs. For example, the preset time range may be less than or equal to 5 seconds or may be other durations.

[0283] In some embodiments, after the usage time of the heap-related parameters calculated according to step S903 exceeds the effective time, the parameter decision module may also re-determine the heap-related parameters, such as based on Figure 4 The method shown calculates the heap-related parameters. Alternatively, when the scenario does not change, the parameter decision module can also restore the heap-related parameters to the heap-related parameters calculated in the scenario, etc. Correspondingly, the parameter decision module can also send the re-determined heap-related parameters to the parameter setting module.

[0284] For example, Fig.10 A schematic diagram of another GC method provided in the embodiment of the present application is shown. Fig.10 As shown, the method comprises the following steps:

[0285] S1001. The electronic device obtains scene information.

[0286] The scene information may be used to characterize the current scene. For a detailed description of the scene information, please refer to the above description.

[0287] In some embodiments, before executing step S1001, the electronic device may obtain a third parameter corresponding to the scene information, the third parameter including: the time when the previous GC ended, the heap memory size when the previous GC ended, the time when the next GC ended, the heap memory size before the next GC ended, and the previous GC and the next GC are two adjacent GCs; the memory growth rate is determined based on the third parameter.

[0288] In some embodiments, before executing step S1001, the electronic device may also determine the resident memory size according to the heap memory size at the end of the next GC when the type of the next GC is non-lightweight GC.

[0289] S1002: The electronic device determines a memory waterline corresponding to the scene information.

[0290] The memory waterline is determined according to a first parameter, and the first parameter includes at least one of a resident memory size and a memory growth rate size of the heap memory corresponding to the current scene.

[0291] In some embodiments, before executing step S1002, the electronic device may determine a second parameter according to the first parameter, the second parameter including at least one of a target heap maximum free memory and a target heap utilization rate, and determine a memory waterline according to the second parameter.

[0292] S1003. The electronic device triggers GC in the current scenario according to the memory waterline.

[0293] based on Fig.10 The technical solution can determine the corresponding scene according to the scene information. The memory watermark determined according to at least one of the resident memory size and memory growth rate size of the corresponding heap memory in different scenes may be different. Therefore, different memory watermarks can be used to trigger GC in different scenes, so as to achieve the effect of dynamically controlling the GC frequency. In this way, the performance of the device can be improved while reducing the power consumption of the device.

[0294] The above mainly introduces the solution provided by the embodiment of the present application from the perspective of the method. It is understandable that, in order to realize the above functions, the electronic device includes a hardware structure and / or software module corresponding to the execution of each function. In combination with the units and algorithm steps of each example described in the embodiment disclosed in this application, the embodiment of the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer-driven hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the technical solution of the embodiment of the present application.

[0295] The present application is an embodiment that can divide the functional modules of the electronic device according to the above method example. For example, each functional module can be divided corresponding to each function, or two or more functions can be integrated into one processing unit. The above integrated unit can be implemented in the form of hardware or in the form of software functional modules. It should be noted that the division of units in the embodiment of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation.

[0296] like Fig.11 1 is a schematic diagram of a structure of an electronic device provided in an embodiment of the present application, and the electronic device 1100 can be used to implement the methods described in the above method embodiments.

[0297] The processing unit 1101 is used to support the electronic device 1100 to execute Figures 1 to 10 The processing function of any one of the above.

[0298] The acquisition unit 1102 is used to support the electronic device 1100 to execute Figures 1 to 10 Any communication function.

[0299] Optional, Fig.11 The electronic device 1100 shown may also include a storage unit 1103, which stores a program or instruction. When the processing unit 1101 executes the program or instruction, Fig.11 The electronic device 1100 shown can execute the method described in the above method embodiment.

[0300] Optional, Fig.11 The electronic device 1100 shown may also include a display unit (not shown in the figure). The display unit may be used to support the electronic device 1100 to perform the display operation in the embodiment of the present application.

[0301] Optional, Fig.11 The electronic device 1100 shown may also include a communication unit, which is used to support the electronic device 1100 in executing the steps of communication between the electronic device and other devices in the embodiments of the present application.

[0302] Fig.11 The technical effects of the electronic device 1100 shown can refer to the technical effects described in the above method embodiments, and will not be repeated here. Fig.11 The processing unit 1101 involved in the electronic device 1100 shown can be implemented by a processor or a processor-related circuit component, which can be a processor or a processing module. The communication unit can be implemented by a transceiver or a transceiver-related circuit component, which can be a transceiver or a transceiver module.

[0303] The present application also provides a chip system, such as Fig.12As shown, the chip system includes at least one processor 1201 and at least one interface circuit 1202. The processor 1201 and the interface circuit 1202 can be interconnected via lines. For example, the interface circuit 1202 can be used to receive signals from other devices. For another example, the interface circuit 1202 can be used to send signals to other devices (such as processor 1201). Exemplarily, the interface circuit 1202 can read instructions stored in the memory and send the instructions to the processor 1201. When the instructions are executed by the processor 1201, the electronic device can execute the various steps performed by the electronic device in the above-mentioned embodiment. Of course, the chip system can also include other discrete devices, which are not specifically limited in the embodiments of the present application.

[0304] Optionally, the processor in the chip system may be one or more. The processor may be implemented by hardware or by software. When implemented by hardware, the processor may be a logic circuit, an integrated circuit, etc. When implemented by software, the processor may be a general-purpose processor implemented by reading software code stored in a memory.

[0305] Optionally, the memory in the chip system may be one or more. The memory may be integrated with the processor or may be separately provided with the processor, which is not limited in the present application. Exemplarily, the memory may be a non-transient processor, such as a read-only memory ROM, which may be integrated with the processor on the same chip or may be provided on different chips. The present application does not specifically limit the type of memory and the arrangement of the memory and the processor.

[0306] Exemplarily, the chip system can be a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on chip (SoC), a central processor unit (CPU), a network processor (NP), a digital signal processor (DSP), a microcontroller unit (MCU), a programmable logic device (PLD) or other integrated chips.

[0307] It should be understood that each step in the above method embodiment can be completed by an integrated logic circuit of hardware in a processor or by instructions in the form of software. The method steps disclosed in the embodiments of the present application can be directly embodied as being executed by a hardware processor, or by a combination of hardware and software modules in a processor.

[0308] An embodiment of the present application further provides a computer storage medium, in which computer instructions are stored. When the computer instructions are executed on an electronic device, the electronic device executes the method described in the above method embodiment.

[0309] An embodiment of the present application provides a computer program product, which includes: a computer program or instructions, when the computer program or instructions are executed on a computer, the computer executes the method described in the above method embodiment.

[0310] In addition, an embodiment of the present application also provides a device, which can specifically be a chip, component or module, and the device may include a connected processor and memory; wherein the memory is used to store computer-executable instructions, and when the device is running, the processor can execute the computer-executable instructions stored in the memory so that the device executes the methods in the above-mentioned method embodiments.

[0311] Among them, the electronic device, computer storage medium, computer program product or chip provided in this embodiment is used to execute the corresponding method provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding method provided above and will not be repeated here.

[0312] Through the description of the above implementation methods, technical personnel in the relevant field can understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0313] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The various embodiments can be combined with each other or referenced to each other without conflict. The device embodiments described above are merely schematic. For example, the division of modules or units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0314] The units described as separate components may or may not be physically separated, and the components shown as units may be one physical unit or multiple physical units, that is, they may be located in one place or distributed in multiple different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

[0315] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0316] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium, including several instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor (processor) to perform all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.

[0317] The above contents are only specific implementation methods of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A garbage collection (GC) method, characterized in that: Applied to electronic equipment, the method comprises: Acquiring scene information, where the scene information is used to characterize the current scene; Determine a memory waterline corresponding to the scene information, where the memory waterline is determined according to a first parameter, where the first parameter includes at least one of a resident memory size and a memory growth rate size of a heap memory corresponding to the current scene; A GC is triggered in the current scenario according to the memory watermark.

2. The method according to claim 1, characterized in that Before determining the memory waterline corresponding to the scene information, the method further includes: Determine a second parameter according to the first parameter, where the second parameter includes at least one of a target heap maximum free memory and a target heap utilization rate; The memory waterline is determined according to the second parameter.

3. The method according to claim 2, characterized in that The determining the second parameter according to the first parameter comprises: Obtaining preset parameters, wherein the preset parameters include a preset GC interval time, a preset maximum free memory of the heap, a preset heap expansion factor, and a preset heap utilization rate, wherein the preset GC interval time is the interval time between two GCs, and the preset heap expansion factor is greater than 1; The second parameter is determined according to the preset parameter and the first parameter.

4. The method according to claim 3, characterized in that The first parameter includes the memory speed-up size, and the second parameter includes the maximum free memory of the target heap; the maximum free memory of the target heap satisfies the following formula: Among them, maxFree1 is the maximum free memory of the target heap, maxFree2 is the maximum free memory of the preset heap, and S is the memory speed increase size.

5. The method according to claim 3 or 4, characterized in that: The first parameter includes the resident memory size and the memory speed-up size, and the second parameter includes the target heap utilization rate; the target heap utilization rate satisfies the following formula: Among them, the S is the memory speed increase size, and the M3 is the resident memory size.

6. The method according to any one of claims 3 to 5, characterized in that: When there is an interaction event in the current scene, the value of the preset GC interval time is a first value; when there is no interaction event in the current scene, the value of the preset GC interval time is a second value, the first value is greater than the second value, and the interaction event refers to an event in which a user interacts with the electronic device.

7. The method according to claim 6, characterized in that When the value of the preset GC interval is the first value, the memory waterline is valid within the preset time.

8. The method according to any one of claims 1 to 7, characterized in that: Before acquiring the scene information, the method further includes: Acquire a third parameter corresponding to the scenario information, the third parameter including: the time when a previous GC ends, the size of the heap memory when the previous GC ends, the time when a next GC ends, the size of the heap memory before the next GC ends, and the previous GC and the next GC are two adjacent GCs; The memory speed increase size is determined according to the third parameter.

9. The method according to claim 8, characterized in that Before acquiring the scene information, the method further includes: When the type of the subsequent GC is non-lightweight GC, the resident memory size is determined according to the heap memory size when the subsequent GC ends.

10. The method according to any one of claims 4, 6-9, characterized in that: Before determining the second parameter according to the first parameter, the method further includes: Determine the Greater than the preset minimum free memory of the heap.

11. The method according to any one of claims 1 to 10, characterized in that: Before determining the memory waterline corresponding to the scene information, the method further includes: Obtaining the current memory utilization of the electronic device; It is determined that the memory utilization is less than or equal to a first threshold.

12. The method according to any one of claims 1 to 10, characterized in that: Before determining the memory waterline corresponding to the scene information, the method further includes: Obtaining the current remaining memory size of the electronic device; It is determined that the remaining memory size is greater than or equal to a second threshold.

13. The method according to claim 3, characterized in that The determining the second parameter according to the preset parameter and the first parameter includes: Obtaining the current CPU utilization rate of the electronic device; Determine a preset coefficient corresponding to the CPU utilization, where the preset coefficient is greater than or equal to 1; The second parameter is determined according to the preset parameter, the first parameter, and the preset coefficient.

14. The method according to claim 13, characterized in that The target heap maximum free memory satisfies the following formula: Among them, maxFree3 is the maximum free memory of the target heap, maxFree2 is the maximum free memory of the preset heap, and S is the memory speed increase size.

15. The method according to claim 13, characterized in that The target heap utilization satisfies the following formula: Among them, the S is the memory speed increase size, and the M3 is the resident memory size.

16. The method according to any one of claims 1 to 15, characterized in that: The scene information includes at least one of an application identifier and an activity identifier.

17. An electronic device, characterized in that: The electronic device comprises a processor and a memory, wherein the memory is coupled to the processor, the memory is used to store computer program code, the computer program code comprises computer instructions, and the processor reads the computer instructions from the memory so that the electronic device executes the method as described in any one of claims 1 to 16.

18. A computer-readable storage medium, characterized in that: The computer-readable storage medium comprises a computer program, and when the computer program is executed on an electronic device, the electronic device is caused to execute the method according to any one of claims 1 to 16.

19. A computer program product, characterized in that The computer program product comprises: a computer program or instructions, and when the computer program or instructions are run on a computer, the computer is caused to perform the method according to any one of claims 1 to 16.