A memory garbage recycling method and an electronic device
By setting personalized GC watermark values for different applications, the problem of low memory garbage collection efficiency in existing technologies is solved, achieving lower power consumption memory management.
Patent Information
- Application Number
- CN202211214485.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-30
- Publication Date
- 2025-10-24
- Estimated Expiration
- 2042-09-30
AI Technical Summary
Existing memory garbage collection methods are inefficient in electronic devices, resulting in increased power consumption.
By setting different GC watermark values for different types of applications, the frequency and resource consumption of garbage collection can be flexibly adjusted, enabling targeted memory management.
It reduces resource consumption caused by frequent garbage collection and reduces the power consumption of electronic devices.
Smart Images

Figure CN115543864B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of terminal, and in particular to a memory garbage recycling method and an electronic device. BACKGROUND
[0002] When an application program runs, it needs to occupy internal memory in an electronic device. The storage area occupied by the application program in the internal memory can also be referred to as memory space. As the running time of the application program increases, the memory space occupied by the application program will increase. At the same time, there will also be idle memory space in the occupied memory space that is no longer accessed by the application program.
[0003] Generally, the electronic device can use a garbage collection (GC) method to recycle the idle memory space, thereby improving the utilization efficiency of the memory space in the electronic device. However, the current memory garbage recycling method has the problem of poor recycling effect. SUMMARY
[0004] Embodiments of the present application provide a memory garbage recycling method and an electronic device, which are used to solve the problem of high GC energy consumption in the electronic device.
[0005] To achieve the above-mentioned purpose, embodiments of the present application adopt the following technical solutions:
[0006] In a first aspect, the present application provides a memory garbage recycling method, which is applied to an electronic device and includes the following steps: receiving a first operation of a user on a first application; starting the first application in response to the first operation, wherein the memory space occupied by the first application is a first memory value after the first application is processed by an i-th garbage collection during running, wherein i is a positive integer. When the memory size occupied by the first application reaches a first preset threshold value, the first application is processed by an i+1-th garbage collection. Receiving a second operation of the user on a second application; starting the second application in response to the second operation, wherein the memory space occupied by the second application is the first memory value after the second application is processed by a j-th garbage collection during running, wherein j is also a positive integer. When the memory size occupied by the second application reaches a second preset threshold value, the second application is processed by a j+1-th garbage collection, wherein the second preset threshold value is smaller than the first preset threshold value, and the size of the application program installation package of the second application is smaller than the size of the application program installation package of the first application.
[0007] Exemplarily, the first preset threshold value and the second preset threshold value can also be referred to as GC waterline values, which are applicable to the evaluation of the memory size threshold value for whether to perform GC on an application program.
[0008] In the method, the memory size occupied by the first application is recycled when the first memory value reaches the first preset threshold, and the memory size occupied by the second application is recycled when the first memory value reaches the second preset threshold, which is equivalent to setting different GC water line values for the first application and the second application.
[0009] In the present application, a larger GC water line value is allocated to an application program with a larger application program installation package, and a smaller GC water line value is allocated to an application program with a smaller application program installation package, so that the GC water line value can be set more targeted according to the type of the application program. Compared with the traditional scheme of setting a unified GC water line value, the present application scheme can reduce the occupation of resources due to frequent GC by flexibly setting different water line values for different applications, more targeted GC processing, reduce the occupation of resources, and reduce power consumption.
[0010] In other embodiments, the different types of application programs can also be applications with different memory access frequencies, different application load sizes, and the like.
[0011] In some embodiments, the first application and the second application are applications in a preset application set in the electronic device.
[0012] In the above embodiments, the electronic device only uses different GC water lines to perform GC processing on the applications in the preset application set, which is more targeted and can use different GC water lines to process applications with different user attention or different GC processing frequencies, which is more flexible.
[0013] In some embodiments, after starting the first application, the method further includes determining that the first application is in a preset application set of the electronic device, and after starting the second application, the method further includes determining that the second application is in the preset application set of the electronic device.
[0014] In some embodiments, the electronic device further includes a third application and a fourth application, the third application and the fourth application are applications outside the preset application set, and the method further includes:
[0015] receive a third operation of a user for a third application; in response to the third operation, start the third application, wherein a memory space size occupied by the third application after an mth garbage collection process during running of the third application is a second memory value, wherein m is a positive integer; when the memory size occupied by the third application reaches a third preset threshold value from the second memory value, perform an (m+1)th garbage collection process on the third application; receive a fourth operation of the user for a fourth application; in response to the fourth operation, start the fourth application, wherein a memory space size occupied by the fourth application after an nth garbage collection process during running of the fourth application is the second memory value, wherein n is a positive integer; when the memory size occupied by the fourth application reaches the third preset threshold value from the second memory value, perform an (n+1)th garbage collection process on the fourth application, and a size of an application program installation package of the third application is greater than a size of an application program installation package of the fourth application.
[0016] In the above embodiment, for some ordinary applications, a unified GC water line is used, the unified GC water line has universality, and a dedicated GC water line needs to be tested for a single application. For ordinary applications, the unified GC water line is also applicable, so that the test workload of the dedicated GC water line is reduced, and the configuration efficiency of the GC water line is improved.
[0017] In some embodiments, after the first application undergoes an (i+1)th garbage collection process during running of the first application, a memory space size occupied by the first application is a third memory value, and the method further includes: when the memory size occupied by the first application reaches a fourth preset threshold value from the third memory value, performing an (i+2)th garbage collection process on the first application; wherein the first memory value and the third memory value are different, and the fourth preset threshold value and the first preset threshold value are different.
[0018] In the above embodiment, for the first application, the actual occupied memory is different, and the allocated GC water line is different, so that the GC water line can adapt to different running stages of the application.
[0019] In some embodiments, a first mapping relationship is satisfied between the first memory value and the first preset threshold value, and the first mapping relationship is also satisfied between the third memory value and the fourth preset threshold value, the first mapping relationship is used to indicate a corresponding relationship between different memory values and different preset threshold values, the first mapping relationship is determined based on a first parameter corresponding to the first application, and the first parameter includes a first maximum threshold value, a first minimum threshold value, and a first proportional factor between a memory value and a preset threshold value.
[0020] In some embodiments, the second application occupies a fourth memory value after a j+1th garbage collection process, and the method further comprises: performing a j+2th garbage collection process on the second application when the memory size occupied by the second application reaches a fifth preset threshold from the fourth memory value; wherein the first memory value is different from the fourth memory value, and the fifth preset threshold is different from the second preset threshold.
[0021] In some embodiments, a second mapping relationship is satisfied between the first memory value and the second preset threshold, and the fourth memory value and the fifth preset threshold also satisfy the second mapping relationship, the second mapping relationship is used to indicate a corresponding relationship between different memory values and different preset thresholds, the second mapping relationship is determined based on a second parameter corresponding to the second application, and the second parameter includes a second maximum threshold, a second minimum threshold, and a second scale factor between a memory value and a preset threshold.
[0022] In some embodiments, the first application is a social application, and the second application is a clock application or a weather application.
[0023] In some embodiments, the application set includes an application program pre-configured by a developer, or the application set includes an application program that meets a preset requirement in at least one of an application usage frequency, an application load size, and an application installation package size. For example, an application that meets a preset usage frequency condition. For another example, an application that meets a preset load evaluation condition. For another example, an application that meets a preset installation package condition.
[0024] In a second aspect, an electronic device is provided. The electronic device includes one or more processors and memory. The memory is coupled to the processors and stores computer program code. The computer program code includes computer instructions that, when executed by the one or more processors, cause the one or more processors to: receive a first operation of a user on a first application; in response to the first operation, start the first application, wherein a memory space occupied by the first application after an i-th garbage collection process during a running process of the first application is a first memory value; when a memory size occupied by the first application reaches a first preset threshold from the first memory value, perform an (i+1)-th garbage collection process on the first application; receive a second operation of the user on a second application; in response to the second operation, start the second application, wherein a memory space occupied by the second application after a j-th garbage collection process during a running process of the second application is the first memory value; when a memory size occupied by the second application reaches a second preset threshold from the first memory value, perform an (j+1)-th garbage collection process on the second application, wherein the second preset threshold is less than the first preset threshold, and a size of an application installation package of the second application is less than a size of an application installation package of the first application.
[0025] In some embodiments, the first application and the second application are applications in a preset application set in the electronic device.
[0026] In some embodiments, the electronic device further includes a third application and a fourth application, the third application and the fourth application are applications outside the preset application set, and the one or more processors are configured to: receive a third operation of the user on the third application; in response to the third operation, start the third application, wherein a memory space occupied by the third application after an m-th garbage collection process during a running process of the third application is a second memory value; when a memory size occupied by the third application reaches a third preset threshold from the second memory value, perform an (m+1)-th garbage collection process on the third application; receive a fourth operation of the user on the fourth application; in response to the fourth operation, start the fourth application, wherein a memory space occupied by the fourth application after an n-th garbage collection process during a running process of the fourth application is the second memory value; when a memory size occupied by the fourth application reaches the third preset threshold from the second memory value, perform an (n+1)-th garbage collection process on the fourth application, and a size of an application installation package of the third application is greater than a size of an application installation package of the fourth application.
[0027] In some embodiments, the first application occupies a third memory value after the i+1th garbage collection, and the one or more processors are configured to perform an i+2th garbage collection on the first application when the memory size occupied by the first application reaches a fourth preset threshold from the third memory value, wherein the first memory value is different from the third memory value, and the fourth preset threshold is different from the first preset threshold.
[0028] In some embodiments, a first mapping relationship is satisfied between the first memory value and the first preset threshold, and the third memory value and the fourth preset threshold also satisfy the first mapping relationship, the first mapping relationship is used to indicate a corresponding relationship between different memory values and different preset thresholds, the first mapping relationship is determined based on a first parameter corresponding to the first application, and the first parameter includes a first maximum threshold, a first minimum threshold, and a first scale factor between a memory value and a preset threshold.
[0029] In some embodiments, the second application occupies a fourth memory value after the j+1th garbage collection, and the one or more processors are configured to perform a j+2th garbage collection on the second application when the memory size occupied by the second application reaches a fifth preset threshold from the fourth memory value, wherein the first memory value is different from the fourth memory value, and the fifth preset threshold is different from the second preset threshold.
[0030] In some embodiments, a second mapping relationship is satisfied between the first memory value and the second preset threshold, and the fourth memory value and the fifth preset threshold also satisfy the second mapping relationship, the second mapping relationship is used to indicate a corresponding relationship between different memory values and different preset thresholds, the second mapping relationship is determined based on a second parameter corresponding to the second application, and the second parameter includes a second maximum threshold, a second minimum threshold, and a second scale factor between a memory value and a preset threshold.
[0031] In some embodiments, the first application is a social application, and the second application is a clock application or a weather application.
[0032] In some embodiments, the application set includes an application program preconfigured by a developer, or the application set includes an application program that meets a preset requirement in at least one of an application usage frequency, an application load size, and an application installation package size.
[0033] In a third aspect, an embodiment of the present application provides a computer storage medium, comprising computer instructions. When the computer instructions are executed on an electronic device, the electronic device executes the method in the above-mentioned first aspect and its possible embodiments.
[0034] In a fourth aspect, the present application provides a computer program product. When the computer program product is run on the above-mentioned electronic device, the electronic device executes the method in the above-mentioned first aspect and its possible embodiments.
[0035] It can be understood that the electronic devices, computer storage media and computer program products provided in the above aspects are all applied to the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Figure 1 This is an example diagram of memory space occupied by an application provided in an embodiment of the present application;
[0037] Figure 2 This is an example diagram of GC provided in the embodiments of the present application;
[0038] Figure 3 An example diagram of the relationship between the actual memory space and the reserved memory space provided in an embodiment of the present application;
[0039] Figure 4 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application;
[0040] Figure 5 A flowchart of the steps of the memory garbage recovery method provided in an embodiment of the present application;
[0041] Figure 6 A flowchart of the sub-steps of S102 provided in an embodiment of the present application;
[0042] Figure 7 A flowchart of the sub-steps of S105 provided in an embodiment of the present application;
[0043] Figure 8 An example diagram of an implementation method of a memory garbage collection method provided in an embodiment of the present application;
[0044] Figure 9 An example diagram of the incubation application process provided in an embodiment of the present application;
[0045] Figure 10 This is an example diagram of a chip system provided in an embodiment of the present application. DETAILED DESCRIPTION
[0046] Hereinafter, the terms "first", "second", "third", etc. are used only for the purpose of description, and should not be understood as indicating or implying relative importance or implying the number of the technical features indicated. Therefore, the features defined with "first", "second", etc. can explicitly or implicitly include one or more of the features. In the description of the embodiments, unless otherwise stated, the meaning of "a plurality of" is two or more.
[0047] The memory in the electronic device is the basis for the running of all application programs. Among them, the above-mentioned memory can be divided into internal memory and external memory. The above-mentioned external memory can be used to store program files of various installed application programs. The above-mentioned internal memory can be used to provide storage space required during the running of the application program.
[0048] In some embodiments, when an application program is running, the electronic device can divide a block of exclusive storage area (also known as memory space) for the application program in the internal memory. Obviously, the more application programs running, the more internal memory occupied. Of course, the available memory space in the electronic device is limited, and in the case that the above-mentioned memory space is all occupied, not only other unstarted application programs cannot be normally started, but also the running effect of the started application programs is not good.
[0049] In some embodiments, the electronic device can use a garbage collection (GC) algorithm to manage the storage space of the internal memory. The above-mentioned GC algorithm is an automatic memory management mechanism. When the memory space occupied by a certain application program is no longer accessed by the application program, that is, there is an idle part in the memory space allocated to a certain application program, the GC algorithm can be used to recycle the idle memory space, so that the recycled memory space can be used by other application programs. In addition, the above-mentioned recycling of the idle memory space using the GC algorithm can also be referred to as GC.
[0050] The following describes the use scenario of the GC algorithm by taking application a as an example:
[0051] First, the electronic device can allocate a memory space exclusively used during the running of application a when application a is started and running.
[0052] Exemplarily, after the application a is started to run, the electronic device can determine the actual occupied memory space of the application a in the internal memory, which is referred to as the actual occupied memory space. It can be understood that the actual occupied memory space is the memory space that is being used by the application a. Then, the electronic device can determine the reserved memory space to be allocated to the application a according to the actual occupied memory space of the application a. It can be understood that the reserved memory space is the memory space that can be used by the application a but is not used at present, and the size of the reserved memory space is related to the size of the actual occupied memory space. In addition, the actual occupied memory space and the reserved memory space both belong to the memory space exclusively occupied by the application a. Of course, the actual memory space exclusively allocated by the electronic device to the application a can be slightly larger than the sum of the actual occupied memory space and the reserved memory space, or can be exactly equal to the sum of the actual occupied memory space and the reserved memory space.
[0053] During the running of the application a, the actual occupied memory space of the application a will increase. In this scenario, the application a can occupy the reserved memory space. It can be understood that the occupied part of the reserved memory space becomes the actual occupied memory space corresponding to the application a. In this way, as the actual occupied memory space corresponding to the application a continuously increases, the corresponding reserved memory space will become smaller. For example, Figure 1 As shown, when the application a is started to run, the actual occupied memory space is 60M, and the reserved memory space is 6M. After the application a runs for a period of time, the actual occupied memory space can become 65M, and the reserved memory space can become 1M.
[0054] Obviously, as the running time of the application a increases, the reserved memory space will become less and less, and the actual occupied memory space will become larger and larger. After the reserved memory space is all occupied by the application a, the electronic device needs to allocate exclusive memory space to the application a again.
[0055] In some embodiments, after the electronic device allocates exclusive memory space to the application a each time, the electronic device can determine the GC water line value corresponding to the application a, which is a threshold value for triggering the re-allocation of exclusive memory space. Generally, the GC water line value can be equal to the size of the exclusive memory space allocated to the application a, for example, equal to the sum of the size of the actual occupied memory space and the size of the reserved memory space. Alternatively, the GC water line value can be slightly larger than the sum of the size of the actual occupied memory space and the size of the reserved memory space.
[0056] Secondly, during the running of the application a, the corresponding actual occupied memory space will gradually increase, and when the actual occupied memory space reaches or exceeds the corresponding GC water line value, the electronic device can trigger the re-allocation of exclusive memory space to the application a.
[0057] In addition, there will be memory space in the actual occupied memory space that is no longer accessed (or used) by the application a, which is referred to as idle memory space.
[0058] Before the electronic device reallocates the exclusive memory space for the application a, the electronic device can reclaim the idle memory space corresponding to the application a through a GC algorithm. The process of reclaiming the idle memory space can refer to related technologies, which will not be described here. For example, Figure 2 As shown, the GC watermark value corresponding to the application a is 67M. After the real-occupied memory space of the application a reaches 67M, if there is 17M of idle memory space in the real-occupied memory space at this time, after the GC algorithm is processed, the real-occupied memory space corresponding to the application a will become 50M, that is, 17M of idle memory space is reclaimed.
[0059] Then, the electronic device can determine the reserved memory space corresponding to the application a according to the real-occupied memory space after the GC processing. In the above example, the real-occupied memory space corresponding to the application a is 50M after the GC. The electronic device can determine 5M of reserved memory space according to the 50M of real-occupied memory space. In this way, the memory space exclusively allocated to the application a is not less than 55M, for example, the application a can be allocated 56M of memory space which is exclusive. The GC watermark value corresponding to the application a can be updated to 56M. The 56M of memory space exclusively allocated to the application a includes 50M of real-occupied memory space and 5M of reserved memory space.
[0060] In this way, the electronic device can effectively manage the occupation of internal storage by various application programs by using the GC algorithm.
[0061] In addition, in the process of allocating the memory space exclusively to the application a, the electronic device needs to use a plurality of GC related parameters. The GC related parameters include one or a combination of the exclusive space upper limit value, the maximum reserved limit value, the minimum reserved limit value, and the space utilization rate.
[0062] The exclusive space upper limit value refers to the maximum value of the exclusive memory space that can be allocated to an application program. For example, if the exclusive space upper limit value is 512M, it means that the size of the exclusive memory space that can be allocated to a single application program does not exceed 512M. Exemplarily, the exclusive space upper limit values for lightweight application programs and large-volume application programs can be different. For example, the exclusive space upper limit value includes upper limit value 1 (for example, 384M) and upper limit value 2 (for example, 512M). The upper limit value 1 is the exclusive space upper limit value for lightweight application programs. The upper limit value 2 is the exclusive space upper limit value for large-volume application programs. Of course, the developer can mark whether the application program belongs to a lightweight application or a large-volume application. In this way, after the application program is installed, the electronic device can determine the exclusive space upper limit value corresponding to the type of the application program (lightweight or large-volume).
[0063] In some examples, if the corresponding real-occupied memory space size of the application a exceeds the corresponding exclusive space upper limit value, the electronic device can display a prompt information to prompt that the application a has a memory occupation abnormality problem.
[0064] In addition, the space utilization rate is used to calculate the proportion of the reserved memory space based on the real-occupied memory space. In other words, the space utilization rate can represent the relationship between the real-occupied memory space and the reserved memory space. When the reserved memory space is calculated based on the real-occupied memory space, the electronic device needs to ensure that the real-occupied memory space and the calculated reserved memory space meet the preset condition, which is related to the space utilization rate. Illustratively, the sum of the real-occupied memory space and the calculated reserved memory space is referred to as memory space 1, and when the proportion between the real-occupied memory space and the memory space 1 is equal to the above-mentioned space utilization rate, it is determined that the preset condition is met. For example, in the scenario where the space utilization rate is 75%, if the size of the real-occupied memory space is 75M, then the size of the reserved memory space can be calculated as 25M, so that the real-occupied memory space and the calculated reserved memory space meet the preset condition.
[0065] Of course, in some embodiments, the calculated reserved memory space can be different from the reserved memory space actually allocated by the electronic device to the application. In the above-mentioned embodiments, the GC-related parameters can further include a maximum reserved limit value and a minimum reserved limit value. The maximum reserved limit value indicates the maximum reserved memory space that can be allocated to the application. The minimum reserved limit value indicates the minimum reserved memory space that can be allocated to the application. For example, when the maximum reserved limit value is 8M, if the calculated reserved memory space is greater than 8M according to the real-occupied memory space and the space utilization rate, it is determined that the size of the actually allocated reserved memory space is equal to 8M. For example, when the minimum reserved limit value is 2M, if the calculated reserved memory space is less than 2M according to the real-occupied memory space and the space utilization rate, it is determined that the size of the actually allocated reserved memory space is equal to 2M.
[0066] In summary, when the space utilization rate is 0.75, the maximum reserved limit value is 8M, and the minimum reserved limit value is 2M, the relationship between the reserved memory space and the real-occupied memory space can be as shown in Figure 3 .
[0067] Obviously, when the electronic device allocates exclusive memory space (including reserved memory space) to the application, the size thereof is affected by the GC-related parameters. In addition, the above-mentioned GC-related parameters also affect the confirmation of the GC waterline value of the application. In some embodiments, all applications in the electronic device share a set of GC-related parameters.
[0068] Obviously, for a heavy-load application (e.g., a system service, a foreground running application, etc.), the GC waterline value determined by the GC-related parameters is low for the application, which can cause the application to frequently perform GC, i.e., increase the power consumption of the electronic device. Exemplarily, the heavy-load application corresponds to a large installation package volume, e.g., the installation package volume is greater than a first volume threshold. Exemplarily, the heavy-load application newly occupies a memory amount greater than a first memory threshold per unit time. Exemplarily, the system resources (computing resources and memory resources) occupied by the heavy-load application when the electronic device runs the application are greater than a first preset load threshold. Exemplarily, the memory access frequency during the running of the heavy-load application exceeds a first frequency value.
[0069] For a light-load application (e.g., a clock application or a background application that is not frequently used), the GC waterline value determined by the GC-related parameters is high for the application, so that the application cannot trigger GC for a long time, and the memory space occupied by the application cannot be effectively recycled, resulting in an increase in the resident memory. In addition, different third-party applications have large differences in GC performance, and some applications have low GC efficiency. Understandably, the light-load application corresponds to a small installation package volume, e.g., the installation package volume is less than a second volume threshold, and the first volume threshold is greater than the second volume threshold. Exemplarily, the light-load application newly occupies a memory amount less than a second memory threshold per unit time, and the first memory threshold is greater than the second memory threshold. Exemplarily, the system resources (computing resources and memory resources) occupied by the light-load application when the electronic device runs the application are less than a second preset load threshold, and the first preset load threshold is greater than the second preset load threshold. Exemplarily, the memory access frequency during the running of the light-load application is lower than a second frequency value. The first frequency value is greater than the second frequency value.
[0070] To address the problem of excessive resident memory, the electronic device can perform proactive GC. The proactive GC can be performed by the electronic device for an application when the application has not been GCed for a long time (e.g., when the time for which the application has not been GCed exceeds a specified time length). In addition to proactive GC, the electronic device can also provide multiple GC modes such as zoned GC and full-amount GC.
[0071] In summary, in the case of using the same set of GC-related parameters, the heavy-load application enables zoned GC and full-amount GC more frequently and proactive GC less frequently. The light-load application enables proactive GC more frequently. In addition, proactive GC can also increase the system energy consumption of the electronic device.
[0072] To improve the above problems, an embodiment of the present application provides a memory garbage recycling method applied to an electronic device. The method can match different GC related parameters for different application programs, and thus configure different GC waterlines for different types of application programs. The GC waterline configured in this way is more targeted. Compared with the traditional scheme of setting a unified GC waterline value, the present application scheme can reduce the resource occupation caused by frequent GC, more targetedly perform GC processing, reduce the resource occupation, and reduce power consumption.
[0073] Exemplarily, the electronic device can be a mobile phone, a tablet computer, a laptop, a handheld computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), an augmented reality (AR) \ virtual reality (VR) device, or other Android devices, and the like. The present application embodiment does not specially limit the specific form of the electronic device.
[0074] Please refer to Figure 4 for a structural schematic diagram of an electronic device 100 provided by an embodiment of the present application.
[0075] As shown in Figure 4 , the electronic device 100 can include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charge 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 loudspeaker 170A, a receiver 170B, a microphone 170C, a headset interface 170D, a sensor module 180, a key 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, and the like.
[0076] The sensor module 180 can include a pressure sensor, a gyroscope sensor, a barometric pressure sensor, a magnetic sensor, an acceleration sensor, a distance sensor, a proximity light sensor, a fingerprint sensor, a temperature sensor, a touch sensor, an ambient light sensor, and a bone conduction sensor, and the like.
[0077] It can be understood that the structure illustrated in the embodiment does not constitute a specific limitation on the electronic device 100. In other embodiments, the electronic device 100 can include more or fewer components than illustrated, or combine certain components, or split certain components, or different arrangement of components. The illustrated components can be implemented in hardware, software, or a combination of software and hardware.
[0078] The processor 110 can include one or more processing units, for example: the processor 110 can include an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Among them, different processing units can be independent devices, or can be integrated in one or more processors.
[0079] The controller can be the nerve center and command center of the electronic device 100. The controller can generate operation control signals according to instruction operation codes and timing signals, and complete the control of fetching and executing instructions.
[0080] The memory can also be provided in the processor 110, for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory can save instructions or data that the processor 110 has just used or repeatedly uses. If the processor 110 needs to use the instructions or data again, it can be directly called from the memory. This avoids repeated access and reduces the waiting time of the processor 110, thus improving the efficiency of the system.
[0081] In some embodiments, the processor 110 can include one or more interfaces. The interfaces can include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.
[0082] It can be understood that the interface connection relationship between the modules shown in the embodiments is only illustrative and does not constitute a limitation on the structure of the electronic device 100. In other embodiments, the electronic device 100 can also use different interface connection modes or combinations of multiple interface connection modes.
[0083] The electronic device 100 implements a display function through a GPU, a display screen 194, and an application processor, etc. The GPU is a microprocessor for image processing, connected to the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 can include one or more GPUs that execute program instructions to generate or change display information.
[0084] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can use a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light emitting diode (AMOLED), a flexible light-emitting diode (FLED), a Miniled, a MicroLed, a Micro-oLed, a quantum dot light emitting diode (QLED), etc.
[0085] The electronic device 100 can implement a photographing function through an ISP, a camera 193, a video codec, a GPU, a display 194, and an application processor, etc.
[0086] The ISP is used to process data fed back by the camera 193. For example, when taking a photo, the shutter is opened, light is transmitted to the camera photosensitive element through the lens, the light signal is converted into an electrical signal, and the camera photosensitive element transmits the electrical signal to the ISP for processing to convert it into an image visible to the naked eye. The ISP can also perform algorithm optimization on the noise, brightness, and skin color of the image. The ISP can also optimize parameters such as exposure and color temperature of the shooting scene. In some embodiments, the ISP can be disposed in the camera 193.
[0087] The camera 193 is used to capture still images or videos. Objects generate optical images through lenses and project them onto photosensitive elements. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the light signal into an electrical signal, which is then transmitted to the ISP to convert it into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into a standard image signal in formats such as RGB and YUV. In some embodiments, the electronic device 100 can include N cameras 193, where N is a positive integer greater than 1.
[0088] The digital signal processor is used to process digital signals, in addition to processing digital image signals, it can also process other digital signals. For example, when the electronic device 100 selects a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy, etc.
[0089] The video codec is used to compress or decompress digital videos. The electronic device 100 can support one or more video codecs. In this way, the electronic device 100 can play or record videos in multiple encoding formats, such as moving picture experts group (MPEG) 1, MPEG 2, MPEG 3, MPEG 4, etc.
[0090] The NPU is a neural-network (NN) computing processor that learns from the structure of biological neural networks, such as the transmission mode between human brain neurons, to quickly process input information and continuously self-learn. Through the NPU, the electronic device 100 can implement intelligent cognitive applications such as image recognition, face recognition, voice recognition, and text understanding, etc.
[0091] The implementation details of the memory garbage recovery method provided by the embodiments of the present application are described below with reference to the drawings.
[0092] In the embodiments of the present application, as shown in Figure 5 The memory garbage recovery method includes the following steps.
[0093] S101, when the application program 1 is started, the identifier 1 of the application program 1 is obtained.
[0094] The identifier 1 can uniquely indicate the application program 1. For example, the identifier 1 can be the application name corresponding to the application program 1. For another example, the identifier 1 can also be the process name corresponding to the application program 1, that is, the name of the application process created when the application program 1 is running.
[0095] In some embodiments, the developer of the application program 1 can write the identifier 1 in the application configuration file of the application program 1. The application configuration file is a program file belonging to the application program 1, which can include an executable file exclusive to the application program 1. It can be understood that when the electronic device creates the application process corresponding to the application program 1, it needs to parse the application configuration file corresponding to the application program 1. When the corresponding application configuration file is parsed, the electronic device can obtain the corresponding identifier 1.
[0096] S102, when the identifier 1 belongs to the preconfigured list, the GC related parameter 1 corresponding to the identifier 1 is queried.
[0097] In some embodiments, the electronic device contains an application set, which can indicate all application programs that need to be configured with exclusive GC related parameters. In some embodiments, the application set can be a preconfigured list, or an application list integrated in a program file. The embodiments of the present application do not limit this, and in the subsequent embodiments, the preconfigured list is mainly taken as an example for description.
[0098] In some embodiments, the application set can be configured by the system developer of the electronic device. Before the system developer adds a newly released application program to the application set, the newly released application program does not belong to the application set, and the exclusive GC related parameter corresponding to the newly released application program is not contained in the application set.
[0099] In addition, if the volume size of the installation package corresponding to the application program is between the first volume threshold and the second volume threshold, the application program can also not be placed in the application set.
[0100] If the newly added memory occupation amount of the application program per unit time is between the first memory threshold and the second memory threshold, the application program can also not be placed in the application set.
[0101] If the frequency of accessing the memory space by the application program is between the first frequency value and the second frequency value, the application program can also not be put into the application set.
[0102] In addition, the application program with low application usage frequency, short average running time of single running, or low download volume can also not be put into the application set. It can be understood that the way of evaluating whether the application usage frequency is high and whether the average usage time is short can refer to related technologies, for example, by mining the user usage records of each application program, a frequency threshold for defining the high and low of the application usage frequency and a time threshold for evaluating the long and short of the usage time are obtained. As for the download volume threshold for determining whether the download volume is low, the download volumes of each application program can be clustered to obtain the corresponding download threshold.
[0103] In summary, the application set includes the application programs specified by the system developer, and can also include the application programs meeting the first condition. The first condition can include various types of conditions, which can also be preset. For example, the first condition (or referred to as the preset requirement) can be at least one of the condition for the application usage frequency, the condition for the running load, the condition for the installation package size, etc. For example, the condition for the application usage frequency can include that the application usage frequency of the application program in a specified period (such as one day) is greater than a frequency threshold 1 or less than a frequency threshold 2, and the frequency threshold 1 is greater than the frequency threshold 2. The condition for the running load can include that the number of accessing the memory space per unit time during the running of the application program exceeds the first frequency value or is lower than the second frequency value. The condition for the installation package size can include that the installation package size of the application program is greater than a first volume threshold or less than a second volume threshold, etc.
[0104] In addition, if an application program does not meet the first condition, the system developer also has the right to add it to the application set.
[0105] In some embodiments, the preconfigured list is one form of existence of the application set in the electronic device. The preconfigured list can be a parameter list parsed from the system configuration file 1, and the preconfigured list includes a plurality of identifiers and GC-related parameters corresponding to each identifier. The plurality of identifiers can indicate a plurality of application programs, and the application programs indicated by the plurality of identifiers are all application programs that need to be configured with exclusive GC-related parameters.
[0106] For example, Figure 6 As shown, S102 can include the following sub-steps:
[0107] S102-1, the electronic device can parse the system configuration file 1 to obtain a preconfigured list.
[0108] For example, Figure 6As shown, the parsed pre-configuration list includes identifiers such as system_server, health, and camera. The identifier "system_server" indicates the system service application, the identifier "health" indicates the health application, and the identifier "camera" indicates the camera application. In other words, the system service application, health application, and camera application in the electronic device are all selected as applications for which exclusive GC-related parameters need to be configured.
[0109] In the preconfigured list above, the GC parameters corresponding to the identifier "system_server" are [8M 32M 0.5], which means the minimum reserved limit is 8M, the maximum reserved limit is 32M, and the space utilization is 0.5. The GC parameters corresponding to the identifier "health" are [2M 8M 0.75], which means the minimum reserved limit is 2M, the maximum reserved limit is 8M, and the space utilization is 0.75. The GC parameters corresponding to the identifier "camera" are [2M 8M0.8], which means the minimum reserved limit is 2M, the maximum reserved limit is 8M, and the space utilization is 0.8.
[0110] S102-2: When the identifier 1 is the same as an identifier in the pre-configuration list, determine the GC-related parameter 1 according to the GC-related parameter corresponding to the identifier 1 in the pre-configuration list.
[0111] like Figure 6 As shown in the figure, when ID 1 is a system service, the GC-related parameters corresponding to ID 1 in the preconfigured list include [8M 32M 0.5]. In this way, it can be determined that the minimum reserved limit value in GC-related parameter 1 is 8M, the maximum reserved limit value is 32M, and the space utilization rate is 0.5.
[0112] In addition, the GC-related parameter 1 may also include an exclusive space upper limit value. Among them, the exclusive space upper limit value corresponding to the GC-related parameter 1 may be the same as the exclusive space upper limit value in the system default GC-related parameter (such as called GC-related parameter 2). It can be understood that the GC-related parameter 2 is a universal GC-related parameter applicable to all applications, and the GC-related parameter 2 includes multiple parameters such as the minimum reserved limit value, the maximum reserved limit value, the space utilization rate and the exclusive space upper limit value. The electronic device can parse the above-mentioned GC-related parameter 2 from the system configuration parameters during the power-on phase. The above-mentioned GC-related parameter 2 does not belong to the pre-configuration list.
[0113] The GC-related parameter 1 is a dedicated GC parameter applicable to the system service application. In addition, there is a difference between the GC-related parameter 1 and the GC-related parameter 2, such as at least one of the corresponding minimum reserved limit, the maximum reserved limit, and the space utilization is different.
[0114] In S103, the application program 1 is allocated with the exclusive memory space according to the GC-related parameter 1.
[0115] In some embodiments, the electronic device first determines the actual occupied memory space of the application process corresponding to the application program 1, that is, the real occupied memory space of the application program 1. Then, according to the real occupied memory space and the space utilization and the maximum reserved limit in the GC-related parameter 1, the reserved memory space corresponding to the application program 1 is determined. In this way, according to the real occupied memory space and the reserved memory space, the exclusive memory space allocated to the application program 1 can be determined.
[0116] For example, Figure 6 As shown, in the case that the application process corresponding to the application program 1 has occupied 50M, the calculated reserved memory space is 50M according to the space utilization. Under the limitation of the maximum reserved limit of 32M, the actual reserved memory space can be determined as 32M. In this way, the exclusive memory space allocated to the application program 1 includes the real occupied memory space of 50M and the reserved memory space of 32M.
[0117] In some examples, the size of the exclusive memory space allocated to the application program 1 can be slightly larger than 82M, such as 83M. In other examples, the size of the exclusive memory space allocated to the application program 1 can be equal to 82M.
[0118] For another example, in the case that the application process corresponding to the application program 1 has occupied 20M, the calculated reserved memory space is 20M according to the space utilization. It can be understood that 20M is less than the maximum reserved limit (32M) in the GC-related parameter 1 and greater than the minimum reserved limit (8M) in the GC-related parameter 1. The electronic device can determine that the reserved memory space allocated to the application program 1 is 20M. In this way, the exclusive memory space allocated to the application program 1 by the electronic device includes the real occupied memory space of 20M and the reserved memory space of 20M.
[0119] For another example, in the case that the application process corresponding to the application program 1 has occupied 6M, the calculated reserved memory space is 6M according to the space utilization. It can be understood that 6M is less than the minimum reserved limit in the GC-related parameter 1. The electronic device can determine that the reserved memory space allocated to the application program 1 is equal to the minimum reserved limit (that is, 8M). In this way, the exclusive memory space allocated to the application program 1 by the electronic device includes the real occupied memory space of 6M and the reserved memory space of 8M.
[0120] After determining the memory space allocated exclusively to the application 1, a GC waterline value corresponding to the application 1 is determined according to the size of the memory space allocated exclusively to the application 1. For example, the GC waterline value is equal to the size of the memory space allocated exclusively to the application 1. In the example above, when the size of the memory space allocated exclusively to the application 1 is 82M, the GC waterline value corresponding to the application 1 is determined to be equal to 82M.
[0121] In this way, when the actual occupied memory space exceeds 82M during the running of the application 1, the electronic device can trigger GC for the application 1.
[0122] In the above embodiment, the electronic device can enable GC-related parameters specific to a specific application (e.g., the application 1). The specific GC-related parameters can be empirical values for the specific application. Through the specific GC-related parameters, a GC waterline value suitable for the specific application can be determined. The GC waterline value can avoid frequent triggering of GC or long-term failure to trigger GC. In this way, the system energy consumption of the electronic device can be effectively reduced.
[0123] In some embodiments, common heavy-load applications and light-load applications in the electronic device can be configured as specific applications, and then the GC-related parameters corresponding to the specific applications can be determined through testing or the like. For example, for each specific application, different GC-related parameters can be enabled, and the energy consumption caused during the running of the specific application can be recorded. In this way, the GC-related parameter causing the lowest energy consumption can be selected as the specific GC-related parameter corresponding to the specific application.
[0124] After determining the specific applications and the corresponding specific GC-related parameters, the identifiers corresponding to the specific applications can be obtained, and a system configuration file 1 corresponding to a pre-configuration list can be generated according to the identifiers and the specific GC-related parameters, and the system configuration file 1 can be stored in the electronic device. In this way, the pre-configuration list can include identifiers and specific GC-related parameters corresponding to heavy-load applications, and can also include identifiers and specific GC-related parameters corresponding to light-load applications.
[0125] In some possible embodiments, the same specific application can include multiple sets of specific GC-related parameters. Different sets of specific GC-related parameters are suitable for the specific application in different running stages.
[0126] For example, the application b belongs to a heavy load application, the GC related parameters of the application b include the GC related parameter a and the GC related parameter b. The GC related parameter a is suitable for the start stage of the application b or the light load stage of the application b. The GC related parameter b is suitable for the heavy load stage of the application b.
[0127] In this way, the electronic device can allocate the exclusive memory space for the application b and determine the corresponding GC waterline according to the GC related parameter a at the start stage of the application b. Then, the electronic device can distinguish whether the application b is in the heavy load stage or the light load stage according to the running time of the application b. For example, the application b is determined to be in the light load stage within the time 1 (for example, 10 minutes) of the start running of the application b. The application b is determined to be in the heavy load stage outside the time 1 (for example, 10 minutes) of the start running of the application b.
[0128] For example, the electronic device can allocate the exclusive memory space for the application b and determine the corresponding GC waterline according to the GC related parameter a within the time 1 (for example, 10 minutes) after the start of the application b. If the GC is triggered after the time 1 (for example, 10 minutes) of the start of the application b, the electronic device can allocate the exclusive memory space for the application b and determine the corresponding GC waterline according to the GC related parameter b.
[0129] In other embodiments, the electronic device can also determine whether the application b is in the heavy load stage or the light load stage according to the change of the actual occupied memory space of the application program.
[0130] For example, the electronic device can determine the exclusive memory space and the corresponding GC waterline of the application b according to the GC related parameter a at the start of the application b. Then, the electronic device can periodically acquire the space size of the actual occupied memory space of the application b. In this way, the electronic device can calculate the change rate of the actual occupied memory space of the application b per unit time, that is, the ratio between the difference of the space size acquired at adjacent times and the corresponding time interval. For example, the space size of the actual occupied memory space of the application b acquired this time is 56M, the space size of the actual occupied memory space of the application b acquired at the adjacent last time is 52M, and the time interval between the two acquisitions is 2s. Therefore, the corresponding change rate is 2M / s. In this way, the electronic device can acquire the latest change rate before the application b triggers the GC each time. If the change rate is greater than a threshold 1, the GC related parameter of the application b is determined to be the GC related parameter b. If the change rate is not greater than the threshold 1, the GC related parameter of the application b is determined to be the GC related parameter a.
[0131] In some scenarios, an electronic device has a first application and a second application installed. Both the first application and the second application are in a preset application set, but there are differences between them. For example, the difference between the first application and the second application can be at least one of the following:
[0132] (1) The first application may be a heavy-load application, and the second application may be a light-load application.
[0133] (2) The size of the installation package of the first application is larger than the size of the installation package of the second application.
[0134] (3) During operation, the amount of memory newly occupied per unit time by the first application is greater than the amount of memory newly occupied per unit time by the second application.
[0135] (4) The running load (the amount of system resources occupied) of the first application is greater than the running load of the second application.
[0136] (5) During operation, the memory access frequency per unit time of the first application is higher than the memory access frequency per unit time of the second application.
[0137] For example, the first application may be a social application that needs to run in the foreground for a long time, and the second application may be a clock application or a weather application provided by the system.
[0138] In addition, the multiple identifiers included in the preconfigured list can also be referred to as multiple application identifiers. The multiple application identifiers include a first identifier indicating a first application and a second identifier indicating a second application. In some embodiments, the electronic device receives a first operation of the user on a first application. The first operation can indicate running the first application, for example, clicking on the application icon of the first application. Then, the electronic device starts the first application in response to the first operation. In this way, the first application also enters the running state.
[0139] During the execution of a first application, the electronic device performs multiple garbage collections on the first application. After the first application undergoes the i-th garbage collection process, if the memory space occupied by the first application reaches a first memory value, the electronic device sets a first preset threshold (i.e., a GC waterline) for the first application based on the first memory value. Thus, after the memory space occupied by the first application reaches the first preset threshold from the first memory value, the i+1-th garbage collection process for the first application is triggered.
[0140] In some embodiments, the electronic device receives a second user operation on a second application. The second operation may indicate running the second application, such as clicking an application icon of the second application. Then, the electronic device launches the second application in response to the second operation. Thus, the second application also enters the running state.
[0141] Similarly, during the running of the second application, the electronic device will perform multiple GCs for the second application. After the second application has undergone the jth garbage collection, if the memory space occupied by the second application is also the first memory value, the electronic device sets a second preset threshold (i.e., GC waterline) for the second application according to the first memory value. In this way, after the memory size occupied by the second application reaches the second preset threshold from the first memory value, the (j+1)th garbage collection for the second application is triggered.
[0142] However, since the first application and the second application are both in the application set and both correspond to their own exclusive GC-related parameters, even if the first application and the second application actually occupy the same memory space after GC, the GC waterlines allocated to them are different. In addition, due to the aforementioned differences between the first application and the second application, the first preset threshold is greater than the second preset threshold.
[0143] In the case where the first application is a heavy-load application and the second application is a light-load application, compared with using the same GC-related parameter configuration to set a unified GC waterline, in the embodiment of the present application, a higher GC waterline is configured for the first application, which can avoid frequent triggering of GC for the first application. A lower GC parameter is also configured for the second application, which avoids the scenario that the second application cannot be GCed during its running, causing the memory space occupied by the second application to be unable to be effectively recycled, resulting in excessive resident memory in the system.
[0144] In addition, if the memory space occupied by the first application is different after each GC, the electronic device configures different GC waterlines for it. For example, after the (i+1)th garbage collection during the running of the first application, the memory space occupied by the first application is a third memory value. When the memory size occupied by the first application reaches a fourth preset threshold (GC waterline) from the third memory value, the (i+2)th garbage collection for the first application is performed. The first memory value is different from the third memory value, and the fourth preset threshold is different from the first preset threshold.
[0145] If the memory space occupied by the second application is different after each GC, the electronic device configures different GC waterlines for it. For example, after the (j+1)th garbage collection during the running of the second application, the memory space occupied by the second application is a fourth memory value. When the memory size occupied by the second application reaches a fifth preset threshold (GC waterline) from the fourth memory value, the (i+2)th garbage collection for the second application is performed. The first memory value is different from the fourth memory value, and the fifth preset threshold is different from the second preset threshold.
[0146] In addition, i and j are both positive integers greater than 0, and can be the same or different, which are not limited in the embodiments of the present application.
[0147] In some embodiments, the first mapping relationship between the first memory value and the first preset threshold value is satisfied, and the third mapping relationship between the third memory value and the fourth preset threshold value is also satisfied. The first mapping relationship indicates a corresponding relationship between different memory values and different preset threshold values, and the first mapping relationship is determined based on a first parameter corresponding to the first application. The first parameter includes a first maximum threshold value, a first minimum threshold value, and a first scale factor between the memory value and the preset threshold value. The first maximum threshold value, the first minimum threshold value, and the first scale factor can be determined according to the GC-related parameters corresponding to the first application. For example, the first maximum threshold value can be an upper limit value of the exclusive space corresponding to the first application, and the first minimum threshold value can be a minimum reserved limit value corresponding to the first application. The first scale factor can be converted according to the space utilization rate corresponding to the first application. It can be understood that the space utilization rate can indicate the change rate between the real occupied memory space and the reserved memory space, and the first scale factor is the change rate between the exclusive memory space (the sum of the real occupied memory space and the reserved memory space) and the real occupied memory space. In addition, the first mapping relationship can be a segmented linear function, and the corresponding relationship between the memory value and the preset threshold value is different in different stages.
[0148] In some embodiments, for an application program that does not need to use the exclusive GC-related parameters, the system default GC-related parameters can be directly used to determine the corresponding exclusive memory space and the GC waterline value. In addition, the system default GC-related parameters can be referred to as the fourth parameter. For example, Figure 5 As shown, the method further includes:
[0149] S104, when the application program 2 is started and runs, the identifier 2 of the application program 2 is obtained.
[0150] In some embodiments, the identifier 2 can uniquely indicate the application program 2. For example, the identifier 2 can be the application name corresponding to the application program 2. For another example, the identifier 2 can also be the process name corresponding to the application program 2, that is, the name of the application process created when the application program 2 runs.
[0151] S105, when the identifier 2 does not belong to the preconfigured list, the memory space exclusively allocated to the application program 2 is determined according to the system default GC-related parameters 2. For example, Figure 7 As shown, S105 can include the following sub-steps:
[0152] S105-1, the electronic device can obtain the preconfigured list.
[0153] In some embodiments, if the system configuration file 1 has been parsed, the pre-configuration list is directly obtained. If the system configuration file 1 has not been parsed, the system configuration file 1 is parsed first to obtain the pre-configuration list.
[0154] S105-2, if the identification 2 is different from the identifications in the pre-configuration list, the GC related parameter 2 is obtained.
[0155] As shown in FIG. 1 1, when the identification 2 is "chat", the pre-configuration list does not contain the identification "chat". In this way, the electronic device can query the GC related parameter 2 parsed in the booting stage. It can be understood that when the identification 2 is "chat", it can indicate that the application program 2 belongs to a chat application. In addition, since the pre-configuration list does not contain the identification "chat", it indicates that the application program 2 does not belong to an application that requires a dedicated GC related parameter, that is, for the application program 2, the system default GC related parameter 2 is the most suitable GC related parameter. Figure 7
[0156] S105-3, according to the GC related parameter 2 and the real occupied memory space corresponding to the application program 2, the reserved memory space allocated to the application program 2 is determined.
[0157] For example, Figure 7 As shown in FIG. 12, the GC related parameter 2 includes a minimum reserved limit value of 2M, a maximum reserved limit value of 12M, a space utilization rate of 0.8, and an exclusive space upper limit value of 512M. In the case where the application process corresponding to the application program 2 has occupied 50M, according to the space utilization rate, the calculated reserved memory space is 12.5M. Under the limitation of the maximum reserved limit value (for example, 12M), the actual reserved memory space can be determined as 12M.
[0158] For another example, in the case where the application process corresponding to the application program 2 has occupied 40M, according to the space utilization rate, the calculated reserved memory space is 10M. It can be understood that 10M is less than the maximum reserved limit value (12M) in the GC related parameter 2, and greater than the minimum reserved limit value (2M) in the GC related parameter 2. The electronic device can determine that the reserved memory space allocated to the application program 2 is 10M.
[0159] For another example, in the case where the application process corresponding to the application program 2 has occupied 6M, according to the space utilization rate, the calculated reserved memory space is 1.5M. It can be understood that 1.5M is less than the minimum reserved limit value (2M) in the GC related parameter 2. The electronic device can determine that the reserved memory space allocated to the application program 2 is equal to the minimum reserved limit value (that is, 2M).
[0160] In this way, the electronic device determines the memory space exclusively allocated to the application program 2 according to the real occupied memory space corresponding to the application program 2 and the reserved memory space.
[0161] In some embodiments, the memory space allocated exclusively to the application 2 includes the real memory space and the reserved memory space. Illustratively, the size of the memory space allocated exclusively to the application 2 can be equal to the sum of the real memory space and the reserved memory space. Illustratively, the size of the memory space allocated exclusively to the application 2 can be slightly larger than the sum of the real memory space and the reserved memory space.
[0162] In this way, the electronic device can determine the GC water line value corresponding to the application 2 according to the size of the exclusive memory space allocated to the application 2. When the real memory space corresponding to the application 2 is greater than or equal to the corresponding GC water line value, the GC for the application 2 can be triggered.
[0163] In other embodiments, the application icons of the third application and the fourth application (referred to as the third identifier) are not included in the preconfigured list, that is, the third application and the fourth application do not belong to the preset application set.
[0164] In some embodiments, the electronic device receives a third operation of a user for the third application, which can indicate running the third application, such as an operation of clicking the application icon of the third application. Then, the electronic device starts the third application in response to the third operation. In this way, the third application also enters the running state.
[0165] During the running of the third application, the electronic device performs multiple GCs for the third application. After the third application undergoes the mth garbage collection processing, if the memory space occupied by the third application is the second memory value, the electronic device sets the third preset threshold (i.e., the GC water line) for the third application according to the second memory value. In this way, after the memory size occupied by the third application reaches the third preset threshold from the second memory value, the m+1th garbage collection processing for the third application is triggered.
[0166] In some embodiments, the electronic device receives a fourth operation of a user for the fourth application, which can indicate running the fourth application, such as an operation of clicking the application icon of the fourth application. Then, the electronic device starts the fourth application in response to the fourth operation. In this way, the fourth application also enters the running state.
[0167] During the running of the fourth application, the electronic device performs multiple GCs for the fourth application. After the fourth application undergoes the nth garbage collection processing, if the memory space occupied by the fourth application is also the second memory value, the electronic device sets the third preset threshold (i.e., the GC water line) for the fourth application according to the second memory value. In this way, after the memory size occupied by the fourth application reaches the third preset threshold from the second memory value, the n+1th garbage collection processing for the fourth application is triggered.
[0168] That is, for the application programs not belonging to the application set, even if the third application and the fourth application exist, the electronic device sets GC waterlines for them according to the same GC-related parameters, such as the difference between the first application and the second application.
[0169] In addition, m and n are positive integers greater than 0, and can be the same or different, which is not limited in the embodiments of the present application.
[0170] In some embodiments, the first memory value and the second preset threshold value satisfy a second mapping relationship, and the fourth memory value and the fifth preset threshold value also satisfy the second mapping relationship. The second mapping relationship is used to indicate a corresponding relationship between different memory values and different preset threshold values. The second mapping relationship is determined based on a second parameter corresponding to the second application. The second parameter includes a second maximum threshold value, a second minimum threshold value, and a second scale factor between the memory value and the preset threshold value.
[0171] The second maximum threshold value, the second minimum threshold value, and the second scale factor can be determined according to the GC-related parameters corresponding to the second application. For example, the second maximum threshold value can be an upper limit value of the exclusive space corresponding to the second application, and the second minimum threshold value can be a minimum reserved limit value corresponding to the second application. The second scale factor can be converted according to the space utilization rate corresponding to the second application. In addition, the second mapping relationship can be a segmented linear function, and the corresponding relationship between the memory value and the preset threshold value is different at different stages.
[0172] As an implementation manner, the method can be cooperated by multiple software modules in the electronic device. For example, the electronic device can include a hatcher, a device initialization, a run time, a memory management module, and a parameter management module. The hatcher is used to indicate the run time and hatch the application processes corresponding to the application programs. The device initialization is used to create a virtual machine running the hatching process. The run time is used to hatch the application processes corresponding to the application programs. The memory management module is used to configure the GC-related parameters corresponding to the application programs and perform GC, etc. The parameter management module is used to parse the system configuration file to obtain the pre-configuration list.
[0173] In some embodiments, after the electronic device is powered on, as shown in Figure 8 The process of allocating the memory space is as follows:
[0174] S1, the device initialization instructs the run time to create a virtual machine.
[0175] S2, the run time creates a hatching process after creating the virtual machine.
[0176] It can be understood that the program file corresponding to the application program includes a common file. The common file can be an executable file required by all application programs installed in the electronic device. For example, a system configuration file 2 can be included, which contains system default GC related parameters.
[0177] In some embodiments, the runtime can create the hatching process by parsing the common file. In addition, the space occupied by the hatching process in the internal memory can be referred to as memory space 2, and the electronic device can store the data obtained by parsing the common file in the memory space 2, such as writing the parsed system default GC related parameters into the memory space 2. Of course, the electronic device can also write data generated during the running of the hatching process into the memory space 2.
[0178] S3, the runtime initializes the hatching process.
[0179] In some embodiments, the implementation process of S3 can refer to related technologies, which will not be described here.
[0180] S4, the runtime sends the system default GC related parameters and the system configuration file 1 to the memory management module.
[0181] In some embodiments, by sending the system default GC related parameters to the memory management module, the GC related parameters corresponding to the hatching process can be configured as the system default GC related parameters. In this way, when GC is performed on the hatching process, the system default GC related parameters can be used. In addition, by sending the system configuration file 1 to the memory management module, the memory management module is instructed to trigger the parameter management module to parse the system configuration file 1.
[0182] S5, the memory management module sends the system configuration file 1 to the parameter management module.
[0183] S6, the parameter management module parses the system configuration file 1 to obtain and store the pre-configuration list.
[0184] In some embodiments, S1 and S6 described above belong to steps performed by the electronic device in the hatching start stage, which can occur in the scenario of starting up the electronic device. After the above steps, the runtime can complete the creation of the hatcher. After the hatcher is created, the application start stage is entered. In this stage, the electronic device can create processes corresponding to other application programs through the hatcher. That is, the above method can also include:
[0185] S7, in response to an operation of starting the application program 1, the hatcher instructs the runtime to create an application process a corresponding to the application program 1.
[0186] S8, the runtime creates the application process a according to the hatching process and the application program 1 corresponding to the exclusive executable file.
[0187] In some embodiments, the runtime can access the memory space 2 occupied by the hatching process and copy the data in the memory space 2 to the memory space 3, which is a different storage area in the internal memory from the memory space 2. For example Figure 9 As shown, the internal memory includes the memory space 2, which is a memory area occupied by the hatching process. When the runtime creates the application process a, it first copies the data stored in the memory space 2 to the memory space 3, and then parses the application program 1 corresponding to the exclusive executable file in the memory space 3, so that the application process a occupying the memory space 3 can be created, and the application program 1 can also start to provide corresponding services to the user.
[0188] S9, the runtime sends the identification 1 corresponding to the application program 1 to the parameter management module.
[0189] S10, the parameter management module determines the GC related parameter 1 corresponding to the identification 1.
[0190] In some embodiments, the corresponding GC related parameter 1 can be queried from the above preconfigured list by using the identification 1.
[0191] S11, the parameter management module sends the GC related parameter 1 to the memory management module.
[0192] S12, the memory management module configures the GC related parameter of the application process a as the GC related parameter 1.
[0193] S13, in response to the operation of starting the application program 2, the hatcher instructs the runtime to create the application process b corresponding to the application program 2.
[0194] S14, the runtime creates the application process b according to the hatching process and the application program 2 corresponding to the exclusive executable file.
[0195] In some embodiments, the runtime can access the memory space 2 occupied by the hatching process and copy the data in the memory space 2 to the memory space 4, which is a different storage area in the internal memory from the memory space 2. Then, in the memory space 4, the application program 2 corresponding to the exclusive executable file is parsed, so that the application process b occupying the memory space 4 can be created, and the application program 2 can also start to provide corresponding services to the user.
[0196] S15, the runtime sends the identification 2 corresponding to the application program 2 to the parameter management module.
[0197] S16, the parameter management module determines that the identification 2 does not belong to the preconfigured list.
[0198] In some embodiments, the parameter management module queries the pre-configuration list and finds that the identity 2 is not included in the pre-configuration list, and determines that the identity 2 does not belong to the pre-configuration list. Thus, the process ends, and since the incubation process also adopts the system default GC-related parameters, the application process b hatched through the incubation process also adopts the system default GC-related parameters without reconfiguring the GC-related parameters.
[0199] The differences between the electronic device (e.g., a mobile phone) using the method provided in the present application and the electronic device not using the method provided in the present application are introduced below through the GC frequency and memory occupation in the actual running process of various types of application programs.
[0200] Exemplarily, the third-party application Weibo™ commonly used in the electronic device belongs to a heavy-load application. Taking Weibo™ as a test object, the GC situation of Weibo™ in the scenario in which the electronic device uses the method provided in the present application (referred to as scenario 1) and the scenario in which the electronic device does not use the method provided in the present application (referred to as scenario 2) is tested, and the test results are shown in Table 1.
[0201] Table 1
[0202]
[0203] Among them, the GC interval is the interval duration between two adjacent GCs, the GC average time is the average value of the duration of a single GC, the GC number is the total number of GCs during the running of Weibo™, and the GC total duration is the total duration of the actual execution of GC during the running of Weibo™.
[0204] Obviously, according to the test results in Table 1, compared with the method not using the present application, after using the method provided in the present application, the GC interval of the electronic device for Weibo™ is longer, the GC number is fewer, although the GC average time is slightly longer, but the GC total duration is shorter, that is, the problem of frequent GC of the third-party heavy-load application is obviously improved, and the occupation duration of the system resources by GC is effectively reduced.
[0205] Exemplarily, the system server in the electronic device belongs to a heavy-load system application. Taking the system server as a test object, the GC situation of the system server in the scenario in which the electronic device uses the method provided in the present application (referred to as scenario 1) and the scenario in which the electronic device does not use the method provided in the present application (referred to as scenario 2) is tested, and the test results are shown in Table 2.
[0206] Table 2
[0207] system server GC times GC interval (s) GC total duration (s) Scenario 2 3102 65.79 68919 Scenario 1 1796 163.97 38172
[0208] According to the test results in Table 2, compared with not using the method of the present application, after using the method provided by the present application, within the same running time, the electronic device has a longer GC interval for the system server, fewer GC times, and a shorter total GC time. In other words, the problem of frequent GC in heavily loaded system applications is significantly improved, and the time that GC occupies system resources is effectively reduced.
[0209] As another example, the process com.android.phone in an electronic device is a light-load application process. Using com.android.phone as the test object, the electronic device was tested using the method provided by this application (e.g., Scenario 1) and not using the method provided by this application (e.g., Scenario 2). The corresponding GC performance of com.android.phone is shown in Table 3 below:
[0210] Table 3
[0211] com.android.phone Resident memory size Scenario 2 69M Scenario 1 47M
[0212] The test results in Table 3 show that, compared to applications without this method, the method provided by this application reduces the resident memory usage of the com.android.phone file within the same runtime. This significantly improves the issue of lightly loaded applications failing to trigger GC for extended periods, leading to excessive resident memory usage.
[0213] An embodiment of the present application further provides an electronic device, which may include a memory and one or more processors. The memory and processor are coupled. The memory is used to store computer program code, which includes computer instructions. When the processor executes the computer instructions, the electronic device performs each step of the above embodiment. Of course, the electronic device includes but is not limited to the above memory and one or more processors.
[0214] The present application also provides a chip system, which can be applied to the terminal device in the above embodiment. Figure 10 As shown, the chip system includes at least one processor 2201 and at least one interface circuit 2202. The processor 2201 can be the processor in the above-mentioned electronic device. The processor 2201 and the interface circuit 2202 can be interconnected via a line. The processor 2201 can receive and execute computer instructions from the memory of the above-mentioned electronic device through the interface circuit 2202. When the computer instructions are executed by the processor 2201, the electronic device can perform the various steps in the above-mentioned embodiment. Of course, the chip system can also include other discrete components, which are not specifically limited in this embodiment of the present application.
[0215] In some embodiments, through the description of the above embodiments, those skilled in the art can clearly understand that, for the convenience and brevity of description, only the above division of functional modules is exemplified, and in actual application, the above functions can be completed by different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. The specific working process of the system, device and unit described above can refer to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0216] The functional units in each embodiment of the present application can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit. The above integrated unit can be realized in the form of hardware, or in the form of a software functional unit.
[0217] The integrated unit, if realized in the form of a software functional unit and sold or used as an independent product, can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the embodiments of the present application essentially or say the part that contributes to the prior art or the whole or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, and includes a number of instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor execute all or part of the steps of the methods described in various embodiments of the present application. The foregoing storage medium includes: a flash memory, a mobile hard disk, a read-only memory, a random access memory, a magnetic disk or an optical disk, and various media that can store program codes.
[0218] The above is only a specific implementation of the embodiments of the present application, but the protection scope of the embodiments of the present application is not limited thereto. Any change or replacement within the technical scope disclosed in the embodiments of the present application should be covered in the protection scope of the embodiments of the present application. Therefore, the protection scope of the embodiments of the present application should be subject to the protection scope of the claims.
Claims
1. A method of garbage collection of memory, characterized by, The method is applied to an electronic device, and the method comprises: receiving a first operation of a user for a first application; in response to the first operation, starting the first application, wherein a memory space size occupied by the first application after an i-th garbage collection process during running of the first application is a first memory value, i being a positive integer; when the memory size occupied by the first application reaches a first preset threshold from the first memory value, performing an (i+1)-th garbage collection process for the first application; wherein a first mapping relationship between the first memory value and the first preset threshold is satisfied, the first mapping relationship is used to indicate a corresponding relationship between different memory values and different preset thresholds, the first mapping relationship is determined based on a first parameter corresponding to the first application, the first parameter comprising a first maximum threshold, a first minimum threshold and a first scale factor between a memory value and a preset threshold; the first maximum threshold is an upper limit value of a memory space exclusively occupied by the first application, and the first minimum threshold is a minimum reserved limit value corresponding to the first application; the first scale factor is a change rate between the memory space exclusively occupied by the first application and an actually occupied memory space; the first mapping relationship is a segmented linear function, and the corresponding relationship between the memory value and the preset threshold is different in different stages; receiving a second operation for a second application; in response to the second operation, starting the second application, wherein a memory space size occupied by the second application after a j-th garbage collection process during running of the second application is the first memory value, j being a positive integer; when the memory size occupied by the second application reaches a second preset threshold from the first memory value, performing a (j+1)-th garbage collection process for the second application, wherein the second preset threshold is smaller than the first preset threshold, and a size of an application program installation package of the second application is smaller than a size of an application program installation package of the first application.
2. The method of claim 1, wherein, The first application and the second application are applications in a preset application set in the electronic device.
3. The method of claim 2, wherein, The electronic device further comprises a third application and a fourth application, the third application and the fourth application are applications outside the preset application set, and the method further comprises: receiving a third operation of the user for the third application; in response to the third operation, starting the third application, wherein a memory space size occupied by the third application after an m-th garbage collection process during running of the third application is a second memory value, m being a positive integer; when the memory size occupied by the third application reaches a third preset threshold from the second memory value, performing an (m+1)-th garbage collection process for the third application; receiving a fourth operation of the user for the fourth application; in response to the fourth operation, starting the fourth application, wherein a memory space size occupied by the fourth application after an n-th garbage collection process during running of the fourth application is the second memory value, n being a positive integer; When the memory size occupied by the fourth application reaches the third preset threshold value from the third memory value, the fourth application is subjected to n+1th garbage collection processing, and the size of the application program installation package of the third application is greater than the size of the application program installation package of the fourth application.
4. The method according to any one of claims 1 to 3, characterized in that, After the first application is subjected to i+1th garbage collection processing during running, the memory space size occupied by the first application is a third memory value, and the method further includes: When the memory size occupied by the first application reaches a fourth preset threshold value from the third memory value, the first application is subjected to i+2th garbage collection processing; wherein the first memory value and the third memory value are different, and the fourth preset threshold value and the first preset threshold value are different.
5. The method of claim 4, wherein, The third memory value and the fourth preset threshold value also satisfy the first mapping relationship.
6. The method according to any one of claims 1 to 3, characterized in that, After the second application is subjected to j+1th garbage collection processing during running, the memory space size occupied by the second application is a fourth memory value, and the method further includes: When the memory size occupied by the second application reaches a fifth preset threshold value from the fourth memory value, the second application is subjected to j+2th garbage collection processing; wherein the first memory value and the fourth memory value are different, and the fifth preset threshold value and the second preset threshold value are different.
7. The method of claim 6, wherein, The first memory value and the second preset threshold value satisfy a second mapping relationship, and the fourth memory value and the fifth preset threshold value also satisfy the second mapping relationship, the second mapping relationship is used to indicate the corresponding relationship between different memory values and different preset threshold values, the second mapping relationship is determined based on a second parameter corresponding to the second application, the second parameter includes a second maximum threshold value, a second minimum threshold value, and a second scale factor between the memory value and the preset threshold value; wherein the second maximum threshold value is an upper limit value of the memory space exclusively occupied by the second application; the second minimum threshold value is a minimum reserved limit value corresponding to the second application; the second scale factor is the change rate between the memory space exclusively occupied by the second application and the actually occupied memory space; the second mapping relationship is a segmented linear function, and the corresponding relationship between the memory value and the preset threshold value is different in different stages.
8. The method according to any one of claims 1 to 3, characterized in that, The first application is a social application, and the second application is a clock application or a weather application.
9. The method of claim 2 or 3, wherein, The application set includes preconfigured application programs, or the application set includes application programs that meet preset requirements in at least one of application use frequency, application load size, and application installation package size.
10. An electronic device, comprising: An electronic device includes one or more processors and a memory; the memory is coupled with the processor, and the memory is used to store computer program code, the computer program code includes computer instructions, when the one or more processors execute the computer instructions, the one or more processors are used to execute the method in any one of claims 1-9.
11. A computer storage medium, characterized in that The computer instructions are used to cause the electronic device to execute the method in any one of claims 1-9 when the computer instructions run on the electronic device.
12. A computer program medium, characterized in that, The computer program medium comprises a computer program which, when running on a computer, causes the computer to perform the method according to any one of claims 1-9.
Citation Information
Patent Citations
Junk memory recycling method and device, electronic equipment and storage medium
CN111258921A