Resource cleanup method and apparatus

By dynamically adjusting resource cleanup strategies and combining the operating scenarios of foreground applications with the usage frequency of background applications, the problem of imbalance between memory usage and performance in existing technologies has been solved, achieving the best balance between memory and performance.

CN122431865APending Publication Date: 2026-07-21VIVO MOBILE COMM CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
VIVO MOBILE COMM CO LTD
Filing Date
2026-04-01
Publication Date
2026-07-21

AI Technical Summary

Technical Problem

Existing resource cleanup strategies cannot achieve a balance between memory usage and performance, cannot adapt to the different needs of various applications for GPU caching, and cannot dynamically adjust the strategy.

Method used

By dynamically adjusting resource cleanup strategies based on multi-dimensional data such as the operating scenario of the foreground application, the available memory of the graphics processor, and the usage frequency of the background application, including cache resource quotas, background resource retention thresholds, and resource cleanup time limits, the system can achieve adaptation between foreground and background applications.

Benefits of technology

While ensuring system performance, effectively reduce memory usage to achieve the optimal balance between memory usage and performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122431865A_ABST
    Figure CN122431865A_ABST
Patent Text Reader

Abstract

The application discloses a resource cleaning method and device, and belongs to the technical field of electronic equipment. The method comprises the following steps: determining second resource configuration information corresponding to a plurality of applications based on at least one of a running scene mode of a foreground application, an available memory amount of a graphic processor, a use frequency of at least one background application, and first resource configuration information corresponding to the plurality of applications respectively; the plurality of applications comprise the foreground application and the at least one background application; and executing a target resource cleaning strategy corresponding to the plurality of applications based on the second resource configuration information corresponding to the plurality of applications, at least one of the running scene mode of the foreground application, the available memory amount of the graphic processor, and the use frequency of the at least one background application.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of electronic equipment technology, specifically relating to a resource cleaning method and apparatus. Background Technology

[0002] With the development of electronic device technology, electronic devices can display increasingly sophisticated images and videos, placing a heavier burden on the graphics processing unit (GPU). To improve GPU rendering performance, applications typically have a set GPU cache size, enabling the reuse of certain rendering resources. This, combined with appropriate resource cleanup strategies, achieves a balance between performance and memory usage. Currently, most electronic devices use a default resource cleanup strategy, meaning all applications use the same strategy under various conditions.

[0003] However, different applications have different requirements for GPU caching. For example, 3D games / video applications require larger cache resource quotas and background resource retention thresholds, while lightweight applications require smaller cache resource quotas and background resource retention thresholds.

[0004] Once a process is created, it will continue to use the current resource cleanup strategy, and will not reselect a resource cleanup strategy unless the process is rebuilt.

[0005] Therefore, existing resource cleanup strategies are fixed and cannot achieve a balance between memory usage and performance. Summary of the Invention

[0006] The purpose of this application is to provide a resource cleanup method and apparatus that can achieve an optimal balance between memory usage and performance.

[0007] In a first aspect, embodiments of this application provide a resource cleanup method, including: Based on at least one of the following: the running scenario mode of the foreground application, the available memory of the graphics processor, the usage frequency of at least one background application, and the first resource configuration information corresponding to each of the multiple applications, the second resource configuration information corresponding to each of the multiple applications is determined. The multiple applications include the foreground application and at least one background application; Based on at least one of the following: the second resource configuration information corresponding to the multiple applications, the running scenario mode of the foreground application, the available memory of the graphics processor, and the usage frequency of the at least one background application, the target resource cleanup strategy corresponding to the multiple applications is executed. Wherein, the first resource configuration information or the second resource configuration information includes at least: Cache resource quotas used to constrain cache memory usage; A background resource retention threshold used to constrain the amount of resources an application retains while it is in the background. This is a time limit for cleaning up background resources to constrain the duration an application remains in the background.

[0008] Secondly, embodiments of this application provide a resource cleanup device, comprising: The determining module is used to determine the second resource configuration information corresponding to the multiple applications based on at least one of the following: the running scenario mode of the foreground application, the available memory of the graphics processor, the usage frequency of at least one background application, and the first resource configuration information corresponding to the multiple applications respectively; the multiple applications include the foreground application and at least one background application. The processing module is used to execute the target resource cleanup strategy corresponding to the multiple applications based on at least one of the second resource configuration information corresponding to the multiple applications, the running scenario mode of the foreground application, the available memory of the graphics processor, and the usage frequency of the at least one background application. Wherein, the first resource configuration information or the second resource configuration information includes at least: Cache resource quotas used to constrain cache memory usage; A background resource retention threshold used to constrain the amount of resources an application retains while it is in the background. This is a time limit for cleaning up background resources to constrain the duration an application remains in the background.

[0009] Thirdly, embodiments of this application provide an electronic device including a processor and a memory, wherein the memory stores programs or instructions executable on the processor, and the programs or instructions, when executed by the processor, implement the steps of the method described in the first aspect.

[0010] Fourthly, embodiments of this application provide a readable storage medium on which a program or instructions are stored, which, when executed by a processor, implement the steps of the method described in the first aspect.

[0011] Fifthly, embodiments of this application provide a chip, the chip including a processor and a communication interface, the communication interface being coupled to the processor, the processor being used to run programs or instructions to implement the method as described in the first aspect.

[0012] In a sixth aspect, embodiments of this application provide a computer program product stored in a storage medium, which is executed by at least one processor to implement the method described in the first aspect.

[0013] In this embodiment, different applications have different resource configuration information (i.e., first resource configuration information). During application operation, based on at least one of the following: the running scenario mode of the foreground application, the available memory of the graphics processor, and the usage frequency of at least one background application, as well as the first resource configuration information corresponding to each application, the second resource configuration information corresponding to each application is re-determined. Then, based on at least one of the second resource configuration information corresponding to each application, the running scenario mode of the foreground application, the available memory of the graphics processor, and the usage frequency of the background application, a target resource cleanup strategy adapted to the foreground and background applications is executed. That is, the target resource cleanup strategy is dynamically adjusted based on multi-dimensional data such as the second resource configuration information corresponding to the foreground and background applications, the running scenario mode of the foreground application, the available memory of the graphics processor, and the usage frequency of the background applications. Under the premise of ensuring system performance, it effectively reduces memory consumption, thereby achieving the optimal balance between memory consumption and performance. Attached Figure Description

[0014] Figure 1 This is a flowchart illustrating a resource cleanup method provided in some embodiments of this application; Figure 2 This is a schematic diagram illustrating the specific process of the resource cleanup method provided in some embodiments of this application; Figure 3 This is a graph showing GPU memory usage after resource cleanup using existing technologies and this application; Figure 4 These are schematic diagrams of the resource cleanup apparatus provided in some embodiments of this application; Figure 5 These are structural block diagrams of electronic devices provided in some embodiments of this application; Figure 6 These are structural block diagrams of electronic devices provided in some embodiments of this application. Detailed Implementation

[0015] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.

[0016] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such terms can be used interchangeably where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.

[0017] Currently, to improve GPU rendering performance, applications typically have a set GPU cache size. This allows for the reuse of certain rendering resources, and combined with appropriate resource cleanup strategies, a balance between performance and memory usage is achieved. Specifically, this includes eight detailed parameters for caching and resource management: 1. The scaling factor for the initial cache size is float initialMaxSurfaceAreaScale=1.0f, which means that the initial cache is allocated according to the screen size at a ratio of 1:1 by default. In other words, when the system allocates the rendering cache for the first time, it is allocated according to the screen size by default. If it is set to 1.5f, the initial cache will be 50% larger than the screen.

[0018] 2. The foreground cache size multiplier is float surfaceSizeMultiplier = 12.0f * 4.0f * 3.0f, which means that when the application is in the foreground, the rendering cache can be expanded to 144 times the screen area (i.e., 12×4×3).

[0019] 3. The percentage of cache retained when the application enters the background: float backgroundRetentionPercent=0.5f. This means that when the application goes to the background, the system will retain 50% of the rendering cache (such as textures and frame cache) instead of releasing it all immediately.

[0020] 4. After the last renderer is destroyed, nsecs_t contextTimeout=10_s, meaning that when the application is closed or all rendering threads stop, the GPU context (including shaders, state, etc.) will be retained for 10 seconds before being released.

[0021] 5. The minimum retention time for resource caching is nsecs_t minimumResourceRetention=10_s, which means that rendering resources (such as textures and buffers) will be retained for at least 10 seconds after they are no longer used before being recycled.

[0022] 6. Whether to clear the cache when the page is not visible: bool useAlternativeUiHidden = true. true means that when the page is obscured or invisible, the system will automatically clear some rendering cache to save memory.

[0023] 7. Whether to only clean up temporary resources when the UI is hidden or the background is collected: bool purgeScratchOnly=true, true means that only temporary resources are cleaned up when the UI is hidden or the background is collected, false means that all cleanable resources are cleaned up when the UI is hidden or the background is collected.

[0024] 8. Whether to release the GPU context only when all contexts stop: bool releaseContextOnStoppedOnly = false. true means to release the GPU context only when all contexts stop, false means to release the GPU context when the main rendering stops, even if some rendering threads are still running.

[0025] By combining the above 8 parameters, you can adjust the cache size that the foreground application can use and the amount of memory that needs to be cleared after the application goes to the background.

[0026] The following parameter combination strategies currently exist: Default strategy: This uses the default values ​​for these 8 parameters, which is also the main resource cleanup strategy in electronic devices.

[0027] Persistence strategy: Use this strategy for system processes and applications that require persistence to maintain more cache.

[0028] Low Random Access Memory (RAM) Device Strategy: For devices with limited RAM, adjust the GPU cache size for foreground applications and increase the resource reservation ratio.

[0029] Extremely low memory strategy: Use the cache as little as possible and reclaim the cache as much as possible.

[0030] For most electronic devices and everyday applications, the default strategy is used, meaning that all applications use the same resource cleanup strategy under various conditions.

[0031] Current application GPU caching strategies have the following shortcomings: Different applications have different requirements for GPU caching, and all applications use the same strategy, which fails to differentiate the approach.

[0032] Once a process is created, it will continue to use the current policy. It will not reselect a policy unless the process is rebuilt, and it does not support dynamic policy adjustment.

[0033] UI_HIDDEN only clears a small amount of cache, while BACKGROUND will destroy the context directly. Although more cache is cleared, the subsequent context reconstruction will cause performance loss and reduce the performance experience. Therefore, the cache clearing strategy is not reasonable.

[0034] Therefore, this application provides a resource cleanup method and apparatus that can dynamically adjust resource cleanup strategies through multi-dimensional data, effectively reducing memory usage while ensuring system performance, thereby achieving the optimal balance between memory usage and performance.

[0035] The resource cleanup method provided in this application will be described below with reference to the accompanying drawings, through specific embodiments and application scenarios.

[0036] It should be noted that the resource cleanup method provided in this application can be executed by electronic devices such as mobile phones, tablets, laptops, PDAs, and in-vehicle electronic devices. Some embodiments of this application use electronic devices as the executing entity to illustrate the resource cleanup method provided in this application.

[0037] like Figure 1 As shown in the figure, this application embodiment provides a resource cleanup method, which may specifically include the following steps: Step 101: The electronic device determines the second resource configuration information corresponding to the multiple applications based on at least one of the following: the running scenario mode of the foreground application, the available memory of the graphics processor, the usage frequency of at least one background application, and the first resource configuration information corresponding to the multiple applications respectively; the multiple applications include the foreground application and at least one background application.

[0038] Specifically, when an electronic device is simultaneously running a foreground application in the foreground state and a background application in the background state, the system acquires the first resource configuration information of the foreground application and the first resource configuration information of each background application. During the operation of the foreground and background applications, at least one of the following is monitored in real time: the current running mode of the foreground application, the available memory of the GPU, and the usage frequency of each background application. A time period can be set to collect the user's usage frequency of each background application during this period.

[0039] The operating scenario modes include: high-load operating scenario mode and low-load operating scenario mode; among them, the high-load operating scenario mode includes: multi-image refresh, video scrolling, application execution interface animation, etc.

[0040] Based on at least one of the following: the runtime scenario of the foreground application, the available memory of the GPU, and the usage frequency of each background application, as well as the first resource configuration information of the foreground application, the second resource configuration information corresponding to the foreground application is redefined.

[0041] In one embodiment, the first resource configuration information or the second resource configuration information in step 101 includes at least: Cache resource quotas used to constrain cache memory usage; A background resource retention threshold used to constrain the amount of resources an application retains while it is in the background. This is a time limit for cleaning up background resources to constrain the duration an application remains in the background.

[0042] Specifically, each application is configured with corresponding cache resources, which include cleanable cache resources and non-cleanable cache resources. Cleanable cache resources are volatile cache data: data that can be safely reclaimed by the system and has no impact on the core functions of the application, such as decoded image copies and rendering results of inactive pages. Non-cleanable cache resources are persistent context data: data that is necessary to maintain the functional state of the application or ensure performance and is costly to rebuild, such as GPU context, network long-lived connection states, and core database transaction logs.

[0043] The cache resource quota, or cache resource size, is determined by the product of the screen resolution, the scaling factor of the initial cache size, and the multiple of the foreground cache size.

[0044] Background resource retention threshold, also known as background availability, refers to the minimum resource limit set by the system for background applications. In other words, it's the maximum amount of resources the system allows an application to continue using after it enters the background. Background activity exceeding this threshold will be strictly restricted or terminated by the system. The background resource retention threshold is determined based on the product of screen resolution, the scaling factor of the initial cache size, a multiple of the foreground cache size, and the proportion of cache retained when the application enters the background.

[0045] The background resource cleanup time limit is the minimum retention time for resource cache.

[0046] Step 102: The electronic device executes the target resource cleanup strategy corresponding to the multiple applications based on at least one of the second resource configuration information corresponding to the multiple applications, the running scenario mode of the foreground application, the available memory of the graphics processor, and the usage frequency of the at least one background application.

[0047] Specifically, based on at least one of the following: the second resource configuration information corresponding to the foreground application and the second resource configuration information corresponding to each background application, the running scenario mode of the foreground application, the available memory of the GPU, and the usage frequency of each background application, the target resource cleanup strategy adapted to the foreground and background applications (i.e., foreground and background applications) can be dynamically adjusted. This can effectively reduce memory usage while ensuring system performance, thereby achieving the optimal balance between memory usage and performance.

[0048] In this embodiment, different applications have different resource configuration information (i.e., first resource configuration information). During application operation, based on at least one of the following: the running scenario mode of the foreground application, the available memory of the graphics processor, and the usage frequency of at least one background application, as well as the first resource configuration information corresponding to each application, the second resource configuration information corresponding to each application is re-determined. Then, based on at least one of the second resource configuration information corresponding to each application, the running scenario mode of the foreground application, the available memory of the graphics processor, and the usage frequency of the background application, a target resource cleanup strategy adapted to the foreground and background applications is executed. That is, the target resource cleanup strategy is dynamically adjusted based on multi-dimensional data such as the second resource configuration information corresponding to the foreground and background applications, the running scenario mode of the foreground application, the available memory of the graphics processor, and the usage frequency of the background applications. Under the premise of ensuring system performance, it effectively reduces memory consumption, thereby achieving the optimal balance between memory consumption and performance.

[0049] In an optional specific embodiment, prior to step 101, the method further includes: When the process of the foreground application does not exist, the electronic device obtains the first resource configuration information corresponding to the foreground application; wherein, the first resource configuration information corresponding to the foreground application is the baseline resource configuration predefined by the foreground application; During the loading process of the foreground application, the electronic device executes the initial resource cleanup strategy corresponding to the foreground application based on the first resource configuration information corresponding to the foreground application. When the process of the foreground application is loaded, the electronic device obtains the first resource configuration information corresponding to the at least one background application, and obtains at least one of the following: the running scenario mode of the foreground application, the available memory of the graphics processor, and the usage frequency of the at least one background application; wherein, the first resource configuration information corresponding to the at least one background application is the current resource configuration of the at least one background application.

[0050] Specifically, different applications require different baseline resource configurations. For example, game applications often need larger textures, maintain high frame rate rendering, and handle real-time interactions, so they are given larger cache resource quotas and larger background resource retention thresholds. Video applications need to buffer videos, so they are also provided with larger cache resource quotas, but video applications do not require larger background resource retention thresholds.

[0051] For example: Table 1 illustrates the baseline resource configurations for different types of applications: Table 1

[0052] Specifically, regarding cache resource quotas, the largest cache resource quota is greater than the larger cache resource quota, the larger cache resource quota is greater than the medium cache resource quota, and the medium cache resource quota is greater than the smaller cache resource quota. The specific value range can be dynamically set and adjusted based on the hardware configuration of the electronic device, system version, and other factors.

[0053] If a user input to launch the first application is received, the system responds to this input and determines that the first application is the foreground application. At this point, it needs to determine if the first application is in a cold start state. If the rendering thread (RenderThread, etc.) of the first application is not present, it indicates that the rendering thread needs to be loaded, confirming a cold start. In this case, the system needs to obtain the baseline resource configuration corresponding to the foreground application (i.e., the first application). When loading the rendering thread (RenderThread, etc.) of the foreground application, an initial resource cleanup strategy is generated based on the baseline resource configuration and executed. This initial resource cleanup strategy means allocating and cleaning up resources according to the baseline resource configuration.

[0054] When the foreground application's process has finished loading, obtain the current resource configuration (i.e., the resource configuration currently being used) of each background application in the background state. Additionally, it is also necessary to obtain at least one of the following: the current running mode of the foreground application, the amount of available memory on the GPU, and the usage frequency of each background application.

[0055] In some embodiments of this application, the first input is used to trigger the launch of the first application, and the first input can be a first operation. Exemplarily, the first input includes, but is not limited to: touch input or click input by the user on the icon of the first application using a touch device such as a finger or stylus, or a voice command input by the user, or a specific gesture input by the user, or other feasible inputs. The specific input can be determined according to actual usage needs, and this embodiment of the invention does not impose limitations. For example, the first input can be: a click input by the user on the icon of the first application.

[0056] The specific gesture in this application embodiment can be any one of the following: single-click gesture, swipe gesture, drag gesture, pressure recognition gesture, long-press gesture, area change gesture, double-press gesture, and double-tap gesture; In this embodiment, the click input can be a single click, a double click, or any number of clicks, or it can be a long press or a short press.

[0057] In an optional specific embodiment, the method further includes: The electronic device, in response to an input to launch a first application, determines that the first application is a foreground application; When the process of the foreground application exists, the electronic device obtains the first resource configuration information corresponding to the foreground application and the first resource configuration information corresponding to the at least one background application, and obtains at least one of the following: the running scenario mode of the foreground application, the available memory of the graphics processor, and the usage frequency of the at least one background application; wherein, the first resource configuration information corresponding to the foreground application is the current resource configuration of the foreground application, and the first resource configuration information corresponding to the at least one background application is the current resource configuration of the at least one background application.

[0058] Specifically, if a user input to start the first application is received, the system responds to this input and determines that the first application is a foreground application. At this point, it needs to determine whether the first application is a cold start. If the rendering thread and other threads of the first application exist, it means that the rendering thread and other threads of the first application do not need to be loaded, and the first application is determined not to be a cold start. Then, it is necessary to obtain the current resource configuration of the foreground application (i.e., the first application) and the current resource configuration of each background application. In addition, it is also necessary to obtain at least one of the following: the current running scene mode of the foreground application, the amount of available memory of the GPU, and the usage frequency of each background application.

[0059] In one optional embodiment, the current resource configuration includes one of the following: Predefined baseline resource configuration; The dynamic resource configuration is an adjustment to the predefined baseline resource configuration.

[0060] Specifically, the current resource configuration of the first application can be a pre-configured baseline resource configuration of the first application, as shown in Table 1; the current resource configuration of the first application can also be a dynamic resource configuration after adjusting the baseline resource configuration of the first application through this application.

[0061] The following sections will explain the process of determining the second resource configuration information and the target resource cleanup strategy, using the foreground application's runtime scenario, the available memory of the graphics processor, and the usage frequency of the background application as examples: Example 1 In an optional specific embodiment, step 101 determines the second resource configuration information corresponding to the multiple applications based on at least one of the following: the running scenario mode of the foreground application, the available memory of the graphics processor, the usage frequency of at least one background application, and the first resource configuration information corresponding to each of the multiple applications. This includes: The electronic device determines the memory state of the graphics processor based on the amount of available memory in the graphics processor, and the memory state includes: a first memory state, a second memory state, or a third memory state; When the memory state is the first memory state, the electronic device determines that the second resource configuration information corresponding to the plurality of applications is the same as the first resource configuration information corresponding to the plurality of applications. When the memory state is the second memory state, the electronic device reduces the background resource retention threshold in the first resource configuration information corresponding to the foreground application to obtain the second resource configuration information corresponding to the foreground application, and determines that the second resource configuration information corresponding to at least one background application is the same as the first resource configuration information corresponding to at least one background application, or reduces the background resource retention threshold in the first resource configuration information corresponding to at least one background application to obtain the second resource configuration information corresponding to at least one background application. When the electronic device is in the third memory state, it determines that the second resource configuration information corresponding to the plurality of applications is the same as the first resource configuration information corresponding to the plurality of applications.

[0062] Specifically, the first memory state is a state of sufficient memory, the second memory state is a state of moderate memory, and the third memory state is a state of insufficient memory. When the available memory of the GPU is obtained, the GPU's memory state is determined based on this available memory. If the GPU's memory state is sufficient, the current resource configuration of each application (foreground application and each background application) remains unchanged; that is, the second resource configuration information of the foreground application is the same as the first resource configuration information of the foreground application, and the second resource configuration information of each background application is the same as the first resource configuration information of the background application.

[0063] If the GPU's memory status is medium, then the background resource retention threshold in the first resource configuration information corresponding to the foreground application is reduced to decrease memory usage when the foreground application moves to the background. This yields the second resource configuration information for the foreground application, while keeping the current resource configuration of each background application unchanged. That is, the second resource configuration information of the foreground application, relative to the first resource configuration information, has the same cache resource quota, the same background resource cleanup timeout, and a lower background resource retention threshold; the second resource configuration information of the background application, relative to the first resource configuration information, has the same cache resource quota, the same background resource cleanup timeout, and the same background resource retention threshold. Alternatively, If the GPU's memory status is medium, then the background resource retention threshold in the first resource configuration information corresponding to the foreground application is reduced to obtain the second resource configuration information corresponding to the foreground application. Similarly, the background resource retention threshold in the first resource configuration information corresponding to each background application is reduced to decrease the memory usage of the background applications, resulting in the second resource configuration information corresponding to each background application. In other words, the second resource configuration information of the foreground application, compared to the first resource configuration information of the foreground application, has the same cache resource quota, the same background resource cleanup time limit, and a lower background resource retention threshold. Similarly, the second resource configuration information of the background application, compared to the first resource configuration information of the background application, has the same cache resource quota, the same background resource cleanup time limit, and a lower background resource retention threshold.

[0064] If the GPU's memory status is insufficient, the current resource configuration of each application (foreground application and each background application) remains unchanged. That is, the second resource configuration information of the foreground application is the same as the first resource configuration information of the foreground application, and the second resource configuration information of each background application is the same as the first resource configuration information of the background application.

[0065] For example, assuming the total system memory is 12GB, if the available memory of the GPU is more than 10GB, it means that the GPU resources are plentiful, and the GPU memory status is determined to be sufficient; if the available memory of the GPU is between 6GB and 10GB, it means that the GPU resources are becoming strained, and the GPU memory status is determined to be moderate; if the available memory of the GPU is less than 6GB, it means that the GPU resources are strained, and the GPU memory status is determined to be insufficient.

[0066] In an optional specific embodiment, step 102, based on at least one of the second resource configuration information corresponding to the plurality of applications, the running scenario mode of the foreground application, the available memory of the graphics processor, and the usage frequency of the at least one background application, executes a target resource cleanup strategy corresponding to the plurality of applications, including: When the electronic device has sufficient memory, it determines the target resource cleanup strategy for the multiple applications as a light resource cleanup strategy based on the second resource configuration information corresponding to each of the multiple applications, and executes the light resource cleanup strategy. When the electronic device is in a state of medium memory, it determines that the target resource cleanup strategy for the multiple applications is a medium resource cleanup strategy and executes the medium resource cleanup strategy. When the electronic device is in a state of insufficient memory, it determines that the target resource cleanup strategy for the multiple applications is a heavy resource cleanup strategy and executes the heavy resource cleanup strategy.

[0067] Specifically, if the GPU's memory status is sufficient, then based on the second resource configuration information of the foreground application and the second resource configuration information of each background application, the light resource cleanup strategy is used as the target resource cleanup strategy, and resource cleanup is performed according to the light resource cleanup strategy. That is, the light resource cleanup strategy means that resources are allocated and lightly cleaned up according to the second resource configuration information of the foreground and background applications in order to reduce the reclamation of memory resources.

[0068] If the GPU's memory status is medium, then based on the second resource configuration information of the foreground application and the second resource configuration information of each background application, the medium resource cleanup strategy is used as the target resource cleanup strategy, and resource cleanup is performed according to the medium resource cleanup strategy. That is, the medium resource cleanup strategy means that resources are allocated and medium resource cleanup is performed according to the second resource configuration information of the foreground and background applications to increase the reclamation of memory resources.

[0069] If the GPU's memory status is insufficient, then based on the second resource configuration information of the foreground application and the second resource configuration information of each background application, the heavy resource cleanup strategy is used as the target resource cleanup strategy, and resource cleanup is performed according to the heavy resource cleanup strategy. That is, the heavy resource cleanup strategy means that resources are allocated and heavily cleaned up according to the second resource configuration information of the foreground and background applications in order to reclaim as much memory resources as possible.

[0070] Example 2 In an optional specific embodiment, step 101 determines the second resource configuration information corresponding to the multiple applications based on at least one of the following: the running scenario mode of the foreground application, the available memory of the graphics processor, the usage frequency of at least one background application, and the first resource configuration information corresponding to each of the multiple applications. This includes: The electronic device determines the frequency category of the at least one background application based on the usage frequency of the at least one background application, and the frequency category includes: a first frequency category, a second frequency category, or a third frequency category; When the frequency category of the background application is the first frequency category, the electronic device determines that the second resource configuration information corresponding to the multiple applications is the same as the first resource configuration information corresponding to the multiple applications. When the frequency category of the background application is the second frequency category, the electronic device determines that the second resource configuration information corresponding to the multiple applications is the same as the first resource configuration information corresponding to the multiple applications, or determines that the second resource configuration information corresponding to the foreground application is the same as the first resource configuration information corresponding to the foreground application, and lowers the background resource retention threshold in the first resource configuration information corresponding to at least one background application to obtain the second resource configuration information corresponding to at least one background application. When the frequency category of the background application is the third frequency category, the electronic device determines that the second resource configuration information corresponding to the multiple applications is the same as the first resource configuration information corresponding to the multiple applications.

[0071] Specifically, the first frequency category is high frequency, the second frequency category is medium frequency, and the third frequency category is low frequency. When the usage frequency of each background application is obtained, the frequency category of each background application is determined based on its usage frequency. If the frequency category of a background application is high frequency, the current resource configuration of each application (foreground application and each background application) remains unchanged; that is, the second resource configuration information of the foreground application is the same as the first resource configuration information of the foreground application, and the second resource configuration information of each background application is the same as the first resource configuration information of the background application.

[0072] If the frequency category of the background application is medium frequency, then the current resource configuration of each application (foreground application and each background application) remains unchanged. That is, the second resource configuration information of the foreground application is the same as the first resource configuration information of the foreground application, and the second resource configuration information of each background application is the same as the first resource configuration information of the background application. Or, If the frequency category of the background application is medium frequency, then the current resource configuration of the foreground application remains unchanged, that is, the second resource configuration information of the foreground application is the same as the first resource configuration information of the foreground application. Then, the background resource retention threshold in the first resource configuration information of each background application is reduced to obtain the second resource configuration information of each background application. That is, the second resource configuration information of the foreground application is the same as the first resource configuration information of the foreground application in terms of cache resource quota, background resource cleanup time limit, and background resource retention threshold. The second resource configuration information of the background application is the same as the first resource configuration information of the background application in terms of cache resource quota, background resource cleanup time limit, and lower background resource retention threshold.

[0073] If the frequency category of the background application is low frequency, then the current resource configuration of each application (foreground application and each background application) remains unchanged. That is, the second resource configuration information of the foreground application is the same as the first resource configuration information of the foreground application, and the second resource configuration information of each background application is the same as the first resource configuration information of the background application.

[0074] For example, if a background application is opened more than 30 times a week, the frequency category of the background application is determined to be high frequency; if the frequency of the background application is opened between 6 and 30 times a week, the frequency category of the background application is determined to be medium frequency; and if the frequency of the background application is opened less than 6 times a week, the frequency category of the background application is determined to be low frequency.

[0075] It's worth noting that the data collection frequency can also be defined as a fixed time period within a day. For example, during the lunch break from 11 AM to 1 PM, users frequently use food delivery apps. Therefore, the usage frequency of background food delivery apps during the lunch break and at other times can be separately analyzed. This allows for targeted adjustments to resource management strategies to achieve the optimal balance between memory usage and performance. Similarly, during the evening period after 7 PM, users frequently use video apps. Therefore, the usage frequency of background video apps during the evening period and at other times can be separately analyzed. This allows for targeted adjustments to resource management strategies to achieve the optimal balance between memory usage and performance.

[0076] In an optional specific embodiment, step 102, based on at least one of the second resource configuration information corresponding to the plurality of applications, the running scenario mode of the foreground application, the available memory of the graphics processor, and the usage frequency of the at least one background application, executes a target resource cleanup strategy corresponding to the plurality of applications, including: When the frequency category of the background application is high frequency, the electronic device determines the target resource cleanup strategy corresponding to the multiple applications as a light resource cleanup strategy based on the second resource configuration information corresponding to the multiple applications, and executes the light resource cleanup strategy. When the frequency category of the background application is medium frequency, the electronic device determines that the target resource cleanup strategy corresponding to the multiple applications is a medium resource cleanup strategy and executes the medium resource cleanup strategy. When the frequency category of the background application is low frequency, the electronic device determines that the target resource cleanup strategy corresponding to the multiple applications is a heavy resource cleanup strategy and executes the heavy resource cleanup strategy.

[0077] Specifically, if the frequency category of the background application is high frequency, then based on the second resource configuration information of the foreground application and the second resource configuration information of each background application, the light resource cleanup strategy is used as the target resource cleanup strategy, and resource cleanup is performed according to the light resource cleanup strategy. That is, the light resource cleanup strategy means that resources are allocated and lightly cleaned up according to the second resource configuration information of the foreground and background applications in order to reduce the reclamation of memory resources.

[0078] If the frequency category of the background application is medium frequency, then based on the second resource configuration information of the foreground application and the second resource configuration information of each background application, the medium resource cleanup strategy is used as the target resource cleanup strategy, and resource cleanup is performed according to the medium resource cleanup strategy. That is, the medium resource cleanup strategy means that resources are allocated and medium resource cleanup is performed according to the second resource configuration information of the foreground and background applications to increase the reclamation of memory resources.

[0079] If the frequency category of the background application is low frequency, then based on the second resource configuration information of the foreground application and the second resource configuration information of each background application, the heavy resource cleanup strategy is used as the target resource cleanup strategy, and resource cleanup is performed according to the heavy resource cleanup strategy. That is, the heavy resource cleanup strategy means that resource allocation and heavy resource cleanup are performed according to the second resource configuration information of the foreground and background applications in order to reclaim as much memory resource as possible.

[0080] Example 3 In an optional specific embodiment, step 101 determines the second resource configuration information corresponding to the multiple applications based on at least one of the following: the running scenario mode of the foreground application, the available memory of the graphics processor, the usage frequency of at least one background application, and the first resource configuration information corresponding to each of the multiple applications. This includes: When the electronic device is in a high-load running scenario mode for the foreground application, it increases the background resource retention threshold in the first resource configuration information corresponding to the foreground application to obtain the second resource configuration information corresponding to the foreground application, and determines that the second resource configuration information corresponding to at least one background application is the same as the first resource configuration information corresponding to at least one background application. When the electronic device switches the running scenario mode of the foreground application from the high-load running scenario mode to the non-high-load running scenario mode, it updates the background resource retention threshold in the second resource configuration information corresponding to the foreground application to the background resource retention threshold in the first resource configuration information corresponding to the foreground application.

[0081] Specifically, during the user's use of the foreground application, the system continuously monitors the foreground application's runtime mode and determines whether it is a high-load runtime mode. If the foreground application is in a high-load runtime mode, more cache resources are needed. This increases the background resource retention threshold in the foreground application's first resource configuration information to increase memory usage when the foreground application is moved to the background. This results in the foreground application's second resource configuration information, while keeping the current resource configuration of each background application unchanged. Specifically, the second resource configuration information of the foreground application, compared to its first resource configuration information, has the same cache resource quota, the same background resource cleanup timeout, and a higher background resource retention threshold. Similarly, the second resource configuration information of the background applications, compared to their first resource configuration information, has the same cache resource quota, the same background resource cleanup timeout, and the same background resource retention threshold.

[0082] If the foreground application is running in a non-high-load scenario, then the current resource configuration of each application (foreground application and each background application) remains unchanged. That is, the second resource configuration information of the foreground application is the same as the first resource configuration information of the foreground application, and the second resource configuration information of each background application is the same as the first resource configuration information of the background application.

[0083] If the running scenario mode of the foreground application is switched from high-load running scenario mode to low-load running scenario mode, the increased background resource retention threshold will be restored to avoid resource waste. That is, the background resource retention threshold in the second resource configuration information corresponding to the foreground application will be restored to the background resource retention threshold in the first resource configuration information corresponding to the foreground application, so as to obtain the second resource configuration information after the background resource retention threshold is restored. In other words, the background resource retention threshold in the updated second resource configuration information is the same as the background resource retention threshold in the first resource configuration information.

[0084] In an optional specific embodiment, step 102, based on at least one of the second resource configuration information corresponding to the plurality of applications, the running scenario mode of the foreground application, the available memory of the graphics processor, and the usage frequency of the at least one background application, executes a target resource cleanup strategy corresponding to the plurality of applications, including: When the electronic device is running in a high-load scenario mode for the foreground application, it determines the target resource cleanup strategy for the multiple applications as a light resource cleanup strategy based on the second resource configuration information corresponding to each of the multiple applications, and executes the light resource cleanup strategy.

[0085] Specifically, if the foreground application is running in a high-load scenario, then based on the second resource configuration information of the foreground application and the second resource configuration information of each background application, the light resource cleanup strategy is used as the target resource cleanup strategy, and resource cleanup is performed according to the light resource cleanup strategy. That is, the light resource cleanup strategy means that resources are allocated and lightly cleaned up according to the second resource configuration information of the foreground and background applications in order to reduce the reclamation of memory resources.

[0086] If the foreground application is running in a non-high-load scenario, then the current resource cleanup strategy will continue to be implemented.

[0087] Example 4 When the available memory of the GPU and the usage frequency of each background application are obtained, the second resource configuration information corresponding to the foreground and background applications is first determined based on the method of Example 1. Then, the second resource configuration information is updated based on the method of Example 2. Finally, the target resource cleanup strategy is determined and executed based on the second resource configuration information updated through Example 2. That is, when the frequency category of the background application is high, the target resource cleanup strategy corresponding to the multiple applications is determined to be a light resource cleanup strategy based on the updated second resource configuration information corresponding to the multiple applications, and the light resource cleanup strategy is executed; when the frequency category of the background application is medium, the target resource cleanup strategy corresponding to the multiple applications is determined to be a medium resource cleanup strategy, and the medium resource cleanup strategy is executed; when the frequency category of the background application is low, the updated target resource cleanup strategy corresponding to the multiple applications is determined to be a heavy resource cleanup strategy, and the heavy resource cleanup strategy is executed.

[0088] Example 5 When the available memory of the GPU and the running scenario mode of the foreground application are obtained, the second resource configuration information corresponding to the foreground and background applications is first determined based on the method of Example 1, and then the second resource configuration information is updated based on the method of Example 3. If the running scenario mode of the foreground application is determined to be a high-load running scenario mode through Example 3, the target resource cleanup strategy is determined and executed based on the second resource configuration information updated through Example 3. If the running scenario mode of the foreground application is determined to be a non-high-load running scenario mode through Example 3, the target resource cleanup strategy is determined and executed based on the second resource configuration information updated through Example 3 and the available memory of the GPU.

[0089] Example 6 Upon obtaining the available memory of the GPU, the usage frequency of each background application, and the running scenario mode of the foreground application, the second resource configuration information corresponding to the foreground and background applications is first determined based on the method of Example 1. Then, the second resource configuration information is updated based on the method of Example 2. Finally, the second resource configuration information updated in Example 2 is updated based on the method of Example 3. If the running scenario mode of the foreground application is determined to be a high-load running scenario mode using the method of Example 3, a target resource cleanup strategy is determined and executed based on the second resource configuration information updated in Example 3. If the running scenario mode of the foreground application is determined to be a non-high-load running scenario mode using the method of Example 3, a target resource cleanup strategy is determined and executed based on the second resource configuration information updated in Example 3 and the usage frequency of each background application.

[0090] In an optional specific embodiment, the cache cleanup strategies mentioned in Embodiments 1 to 6 above are described as follows: The light cache cleanup strategy includes: when the foreground application switches from a foreground state to a background state, cleaning up the cleanable cache resources of the foreground application according to the background resource retention threshold in the second resource configuration information of the foreground application, and cleaning up the cleanable cache resources of the at least one background application according to the background resource retention threshold in the second resource configuration information of the at least one background application. The moderate cache cleanup strategy includes: when the foreground application switches from a foreground state to a background state, cleaning up the cleanable cache resources of the foreground application according to the background resource retention threshold in the second resource configuration information of the foreground application; and cleaning up the cleanable cache resources of the at least one background application according to the background resource retention threshold in the second resource configuration information of the at least one background application; or, The moderate cache cleanup strategy includes: when the foreground application switches from a foreground state to a background state, cleaning up all cleanable cache resources of the foreground application, and cleaning up all cleanable cache resources of at least one background application. The heavy cache cleanup strategy includes: when the foreground application switches from a foreground state to a background state, cleaning up all cleanable cache resources of the foreground application and the hardware execution context associated with the foreground application, and cleaning up all cleanable cache resources of the at least one background application and the hardware execution context associated with the at least one background application.

[0091] Specifically, for the lightweight cache cleanup strategy UI_HIDDEN, when the foreground application switches from foreground to background, the cleanup of the foreground application's cleanable cache resources is performed based on the background resource retention threshold in the foreground application's second resource configuration information. This continues until the remaining undisturbed cleanable cache resources reach the background resource retention threshold in the foreground application's second resource configuration information, at which point cleanup stops. Furthermore, the cleanup of each background application's cleanable cache resources is performed based on the background resource retention threshold in the second resource configuration information of that background application, continuing until the remaining undisturbed cleanable cache resources reach the background resource retention threshold for that background application, at which point cleanup stops.

[0092] For the moderate cache cleanup strategy UI_HIDDEN_HIGH, when the foreground application switches from foreground to background, if the background resource retention threshold in the foreground application's second resource configuration information is lower than the background resource retention threshold in the foreground application's first resource configuration information, then the cleanable cache resources of the foreground application are cleaned according to the background resource retention threshold in the foreground application's second resource configuration information. This continues until the remaining undisturbed cleanable cache resources reach the background resource retention threshold in the foreground application's second resource configuration information, at which point cleanup stops. Furthermore, the cleanable cache resources of each background application are cleaned according to the background resource retention threshold in the second resource configuration information of that background application. This continues until the remaining undisturbed cleanable cache resources reach the background resource retention threshold in the second resource configuration information of that background application, at which point cleanup stops. Alternatively, For the moderate cache cleanup strategy UI_HIDDEN_HIGH, when the foreground application switches from foreground to background, if the background resource retention threshold in the second resource configuration information of the foreground application is the same as the background resource retention threshold in the first resource configuration information of the foreground application, then all cleanable cache resources of the foreground application are cleaned up, and all cleanable cache resources of each background application are also cleaned up, but the GPU context is still retained.

[0093] The heavy cache cleanup strategy BACKGROUND cleans up all cached resources of both the foreground and background applications (including resources in the middle layer and GPU context) when the foreground application switches from the foreground state to the background state. This effectively reduces memory usage while ensuring system performance, thus achieving the optimal balance between memory usage and performance.

[0094] The above embodiments categorize cache cleanup strategies, employing different levels of cache cleanup for different situations, which can effectively resolve the contradiction between performance loss and resource cleanup intensity.

[0095] like Figure 2 As shown, the above resource cleanup method will be described below through a specific embodiment: Step 201: The electronic device responds to the input to start the first application and determines that the first application is a foreground application.

[0096] Step 202: The electronic device determines whether the process of the foreground application exists. If it does not exist, proceed to step 203; if it does exist, proceed to step 204.

[0097] Step 203: During the loading process of the foreground application, the electronic device uses the baseline resource configuration of the foreground application as the first resource configuration information, and determines and executes the initial resource cleanup strategy of the foreground application based on the first resource configuration information.

[0098] Step 204: If the foreground application process has finished loading or the foreground application process exists, the electronic device obtains the first resource configuration information of at least one background application, and obtains at least one of the following: the running scene mode of the foreground application, the amount of available memory of the graphics processor, and the usage frequency of at least one background application.

[0099] Step 205: The electronic device determines the target resource cleanup strategy based on the amount of available memory in the graphics processor.

[0100] Step 206: The electronic device updates the target resource cleanup strategy based on the usage frequency of at least one background application.

[0101] Step 207: The electronic device updates the target resource cleanup strategy based on the running scenario mode of the foreground application.

[0102] Step 208: The electronic device executes the latest target resource cleanup strategy.

[0103] In one embodiment, two tests are performed on the dynamic resource cleanup strategy of this application and the fixed resource cleanup strategy of the prior art: Test 1: Multiple applications were selected, and both the existing fixed resource cleanup strategy and the dynamic resource cleanup strategy of this application were applied to these applications. The GPU cache resources occupied by each application after it leaves the background were compared under these two strategies. Tests showed that, compared to the fixed resource cleanup strategy, the dynamic resource cleanup strategy resulted in lower GPU cache resources occupied by applications leaving the background, thus reclaiming more memory resources. Table 2 shows the statistics of GPU cache resources occupied by different applications after leaving the background under the two strategies: Table 2

[0104] Test 2: like Figure 3As shown, 30 applications were launched (tested 3 times). These applications used the existing fixed resource cleanup strategy (i.e., the default strategy) and the dynamic resource cleanup strategy of this application, respectively. The cache resources occupied by the GPU were observed when using these 30 applications. During use, the dynamic resource cleanup strategy (i.e., the dynamic strategy) occupied less cache resources to free up more memory resources.

[0105] Therefore, in this embodiment, different applications are configured with different resource settings to avoid resource shortages or waste. During application operation, resource cleanup strategies are dynamically adjusted based on multi-dimensional data such as the running scenario of the foreground application, the available memory of the graphics processor, and the usage frequency of each background application. This effectively reduces memory usage while ensuring system performance, thereby achieving an optimal balance between memory consumption and performance. Furthermore, the cache cleanup strategy is tiered, employing different levels of cache cleanup for different situations, which effectively resolves the contradiction between performance loss and resource cleanup intensity.

[0106] The resource cleanup method provided in this application can be executed by a resource cleanup device. This application uses an example of a resource cleanup device executing the resource cleanup method to illustrate the resource cleanup device provided in this application.

[0107] like Figure 4 As shown in the illustration, this application also provides a resource cleanup device 400, which specifically includes: The determining module 401 is used to determine the second resource configuration information corresponding to the multiple applications based on at least one of the running scenario mode of the foreground application, the available memory of the graphics processor, the usage frequency of at least one background application, and the first resource configuration information corresponding to the multiple applications respectively; the multiple applications include the foreground application and at least one background application. The processing module 402 is used to execute the target resource cleanup strategy corresponding to the multiple applications based on at least one of the second resource configuration information corresponding to the multiple applications, the running scenario mode of the foreground application, the available memory of the graphics processor, and the usage frequency of the at least one background application. Wherein, the first resource configuration information or the second resource configuration information includes at least: Cache resource quotas used to constrain cache memory usage; A background resource retention threshold used to constrain the amount of resources an application retains while it is in the background. This is a time limit for cleaning up background resources to constrain the duration an application remains in the background.

[0108] Optionally, the device further includes: The acquisition module is used to acquire first resource configuration information corresponding to the foreground application when the process of the foreground application does not exist; wherein, the first resource configuration information corresponding to the foreground application is a predefined baseline resource configuration of the foreground application; The processing module is further configured to execute an initial resource cleanup strategy corresponding to the foreground application based on the first resource configuration information corresponding to the foreground application during the process loading of the foreground application. The acquisition module is further configured to acquire, when the process of the foreground application has finished loading, first resource configuration information corresponding to the at least one background application, and acquire at least one of the following: the running scenario mode of the foreground application, the available memory of the graphics processor, and the usage frequency of the at least one background application; wherein, the first resource configuration information corresponding to the at least one background application is the current resource configuration of the at least one background application.

[0109] Optionally, when determining the second resource configuration information corresponding to the multiple applications based on at least one of the running scenario mode of the foreground application, the available memory of the graphics processor, the usage frequency of at least one background application, and the first resource configuration information corresponding to the multiple applications, the determining module 401 is specifically used for: Based on the available memory of the graphics processor, the memory state of the graphics processor is determined, and the memory state includes: a first memory state, a second memory state, or a third memory state; When the memory state is the first memory state, it is determined that the second resource configuration information corresponding to the plurality of applications is the same as the first resource configuration information corresponding to the plurality of applications. When the memory state is the second memory state, the background resource retention threshold in the first resource configuration information corresponding to the foreground application is reduced to obtain the second resource configuration information corresponding to the foreground application, and it is determined that the second resource configuration information corresponding to the at least one background application is the same as the first resource configuration information corresponding to the at least one background application, or the background resource retention threshold in the first resource configuration information corresponding to the at least one background application is reduced to obtain the second resource configuration information corresponding to the at least one background application. When the memory state is the third memory state, it is determined that the second resource configuration information corresponding to the plurality of applications is the same as the first resource configuration information corresponding to the plurality of applications.

[0110] Optionally, when determining the second resource configuration information corresponding to the multiple applications based on at least one of the running scenario mode of the foreground application, the available memory of the graphics processor, the usage frequency of at least one background application, and the first resource configuration information corresponding to the multiple applications, the determining module 401 is specifically used for: Based on the usage frequency of the at least one background application, a frequency category of the at least one background application is determined, and the frequency category includes: a first frequency category, a second frequency category, or a third frequency category; When the frequency category of the background application is the first frequency category, it is determined that the second resource configuration information corresponding to the plurality of applications is the same as the first resource configuration information corresponding to the plurality of applications. When the frequency category of the background application is the second frequency category, it is determined that the second resource configuration information corresponding to the plurality of applications is the same as the first resource configuration information corresponding to the plurality of applications; or, it is determined that the second resource configuration information corresponding to the foreground application is the same as the first resource configuration information corresponding to the foreground application, and the background resource retention threshold in the first resource configuration information corresponding to at least one background application is reduced to obtain the second resource configuration information corresponding to at least one background application. When the frequency category of the background application is the third frequency category, it is determined that the second resource configuration information corresponding to the multiple applications is the same as the first resource configuration information corresponding to the multiple applications.

[0111] Optionally, when determining the second resource configuration information corresponding to the multiple applications based on at least one of the running scenario mode of the foreground application, the available memory of the graphics processor, the usage frequency of at least one background application, and the first resource configuration information corresponding to the multiple applications, the determining module 401 is specifically used for: When the running scenario mode of the foreground application is a high-load running scenario mode, the background resource retention threshold in the first resource configuration information corresponding to the foreground application is increased to obtain the second resource configuration information corresponding to the foreground application, and it is determined that the second resource configuration information corresponding to the at least one background application is the same as the first resource configuration information corresponding to the at least one background application. When the running scenario mode of the foreground application is switched from the high-load running scenario mode to the non-high-load running scenario mode, the background resource retention threshold in the second resource configuration information corresponding to the foreground application is updated to the background resource retention threshold in the first resource configuration information corresponding to the foreground application.

[0112] The resource cleanup device in this application embodiment can be an electronic device or a component within an electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal or other devices besides a terminal. For example, the electronic device can be a mobile phone, tablet computer, laptop computer, PDA, in-vehicle electronic device, mobile internet device (MID), augmented reality (AR) / virtual reality (VR) device, robot, wearable device, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc. It can also be a server, network attached storage (NAS), personal computer (PC), television (TV), ATM, or self-service machine, etc. This application embodiment does not specifically limit the scope of the device.

[0113] The resource cleanup device in this application embodiment can be a device with an operating system. This operating system can be Android, iOS, or other possible operating systems; this application embodiment does not specifically limit the specific operating system used.

[0114] The resource cleanup device provided in this application embodiment can achieve... Figures 1 to 3 The various processes implemented in the method implementation examples will not be described again here to avoid repetition.

[0115] Optionally, such as Figure 5 As shown, this application embodiment also provides an electronic device 900, including a processor 901 and a memory 902. The memory 902 stores a program or instructions that can run on the processor 901. When the program or instructions are executed by the processor 901, they implement the various steps of the above-described resource cleanup method embodiment and can achieve the same technical effect. To avoid repetition, they will not be described again here.

[0116] It should be noted that the electronic devices in the embodiments of this application include the mobile electronic devices and non-mobile electronic devices described above.

[0117] Figure 6 A schematic diagram of the hardware structure of an electronic device to implement an embodiment of this application.

[0118] The electronic device 1000 includes, but is not limited to, components such as: radio frequency unit 1001, network module 1002, audio output unit 1003, input unit 1004, sensor 1005, display unit 1006, user input unit 1007, interface unit 1008, memory 1009, and processor 1010.

[0119] Those skilled in the art will understand that the electronic device 1000 may also include a power supply (such as a battery) for supplying power to various components. The power supply may be logically connected to the processor 1010 through a power management system, thereby enabling functions such as managing charging, discharging, and power consumption through the power management system. Figure 6 The electronic device structure shown does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown, or combine certain components, or have different component arrangements, which will not be elaborated here.

[0120] The processor 1010 is configured to determine second resource configuration information for each of the foreground application based on at least one of the following: the running scenario mode of the foreground application, the available memory of the graphics processor, the usage frequency of at least one background application, and first resource configuration information corresponding to each of the multiple applications; the multiple applications include the foreground application and at least one background application. Based on at least one of the following: the second resource configuration information corresponding to the multiple applications, the running scenario mode of the foreground application, the available memory of the graphics processor, and the usage frequency of the at least one background application, the target resource cleanup strategy corresponding to the multiple applications is executed. Wherein, the first resource configuration information or the second resource configuration information includes at least: Cache resource quotas used to constrain cache memory usage; A background resource retention threshold used to constrain the amount of resources an application retains while it is in the background. This is a time limit for cleaning up background resources to constrain the duration an application remains in the background.

[0121] Optionally, the processor 1010 is further configured to: If the process of the foreground application does not exist, obtain the first resource configuration information corresponding to the foreground application; wherein, the first resource configuration information corresponding to the foreground application is the baseline resource configuration predefined by the foreground application; During the loading process of the foreground application, an initial resource cleanup strategy corresponding to the foreground application is executed based on the first resource configuration information corresponding to the foreground application. When the process of the foreground application is loaded, first resource configuration information corresponding to the at least one background application is obtained, and at least one of the following is obtained: the running scenario mode of the foreground application, the available memory of the graphics processor, and the usage frequency of the at least one background application; wherein, the first resource configuration information corresponding to the at least one background application is the current resource configuration of the at least one background application.

[0122] Optionally, when the processor 1010 determines the second resource configuration information corresponding to the multiple applications based on at least one of the running scenario mode of the foreground application, the available memory of the graphics processor, the usage frequency of at least one background application, and the first resource configuration information corresponding to the multiple applications respectively, it is specifically used for: Based on the available memory of the graphics processor, the memory state of the graphics processor is determined, and the memory state includes: a first memory state, a second memory state, or a third memory state; When the memory state is the first memory state, it is determined that the second resource configuration information corresponding to the plurality of applications is the same as the first resource configuration information corresponding to the plurality of applications. When the memory state is the second memory state, the background resource retention threshold in the first resource configuration information corresponding to the foreground application is reduced to obtain the second resource configuration information corresponding to the foreground application, and it is determined that the second resource configuration information corresponding to the at least one background application is the same as the first resource configuration information corresponding to the at least one background application, or the background resource retention threshold in the first resource configuration information corresponding to the at least one background application is reduced to obtain the second resource configuration information corresponding to the at least one background application. When the memory state is the third memory state, it is determined that the second resource configuration information corresponding to the plurality of applications is the same as the first resource configuration information corresponding to the plurality of applications.

[0123] Optionally, when the processor 1010 determines the second resource configuration information corresponding to the multiple applications based on at least one of the running scenario mode of the foreground application, the available memory of the graphics processor, the usage frequency of at least one background application, and the first resource configuration information corresponding to the multiple applications respectively, it is specifically used for: Based on the usage frequency of the at least one background application, a frequency category of the at least one background application is determined, and the frequency category includes: a first frequency category, a second frequency category, or a third frequency category; When the frequency category of the background application is the first frequency category, it is determined that the second resource configuration information corresponding to the plurality of applications is the same as the first resource configuration information corresponding to the plurality of applications. When the frequency category of the background application is the second frequency category, it is determined that the second resource configuration information corresponding to the plurality of applications is the same as the first resource configuration information corresponding to the plurality of applications; or, it is determined that the second resource configuration information corresponding to the foreground application is the same as the first resource configuration information corresponding to the foreground application, and the background resource retention threshold in the first resource configuration information corresponding to at least one background application is reduced to obtain the second resource configuration information corresponding to at least one background application. When the frequency category of the background application is the third frequency category, it is determined that the second resource configuration information corresponding to the multiple applications is the same as the first resource configuration information corresponding to the multiple applications.

[0124] Optionally, when the processor 1010 determines the second resource configuration information corresponding to the multiple applications based on at least one of the running scenario mode of the foreground application, the available memory of the graphics processor, the usage frequency of at least one background application, and the first resource configuration information corresponding to the multiple applications respectively, it is specifically used for: When the running scenario mode of the foreground application is a high-load running scenario mode, the background resource retention threshold in the first resource configuration information corresponding to the foreground application is increased to obtain the second resource configuration information corresponding to the foreground application, and it is determined that the second resource configuration information corresponding to the at least one background application is the same as the first resource configuration information corresponding to the at least one background application. When the running scenario mode of the foreground application is switched from the high-load running scenario mode to the non-high-load running scenario mode, the background resource retention threshold in the second resource configuration information corresponding to the foreground application is updated to the background resource retention threshold in the first resource configuration information corresponding to the foreground application.

[0125] It should be understood that, in this embodiment, the input unit 1004 may include a graphics processing unit (GPU) 10041 and a microphone 10042. The GPU 10041 processes image data of still images or videos obtained by an image capture device (such as a camera) in video capture mode or image capture mode. The display unit 1006 may include a display panel 10061, which may be configured in the form of a liquid crystal display, an organic light-emitting diode, etc. The user input unit 1007 includes at least one of a touch panel 10071 and other input devices 10072. The touch panel 10071 is also called a touch screen. The touch panel 10071 may include a touch detection device and a touch controller. Other input devices 10072 may include, but are not limited to, physical keyboards, function keys (such as volume control buttons, power buttons, etc.), trackballs, mice, joysticks, etc., which will not be described in detail here.

[0126] The memory 1009 can be used to store software programs and various data. The memory 1009 may primarily include a first storage area for storing programs or instructions and a second storage area for storing data. The first storage area may store the operating system, application programs or instructions required for at least one function (such as sound playback, image playback, etc.). Furthermore, the memory 1009 may include volatile memory or non-volatile memory, or both. The non-volatile memory may be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory can be random access memory (RAM), static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct memory bus RAM (DRRAM). The memory 1009 in this embodiment includes, but is not limited to, these and any other suitable types of memory.

[0127] The processor 1010 may include one or more processing units; optionally, the processor 1010 integrates an application processor and a modem processor, wherein the application processor mainly handles operations involving the operating system, user interface, and applications, and the modem processor mainly handles wireless communication signals, such as a baseband processor. It is understood that the aforementioned modem processor may also not be integrated into the processor 1010.

[0128] This application also provides a readable storage medium storing a program or instructions. When the program or instructions are executed by a processor, they implement the various processes of the above-described resource cleanup method embodiments and achieve the same technical effect. To avoid repetition, they will not be described again here.

[0129] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.

[0130] This application embodiment also provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the various processes of the above-described resource cleanup method embodiments and can achieve the same technical effect. To avoid repetition, it will not be described again here.

[0131] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.

[0132] This application provides a computer program product that is stored in a storage medium and executed by at least one processor to implement the various processes of the resource cleanup method embodiments described above, and achieves the same technical effect. To avoid repetition, it will not be described again here.

[0133] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.

[0134] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a computer software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.

[0135] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.

Claims

1. A resource cleanup method, characterized in that, include: Based on at least one of the following: the running scenario mode of the foreground application, the available memory of the graphics processor, the usage frequency of at least one background application, and the first resource configuration information corresponding to each of the multiple applications, the second resource configuration information corresponding to each of the multiple applications is determined. The multiple applications include the foreground application and at least one background application; Based on at least one of the following: the second resource configuration information corresponding to the multiple applications, the running scenario mode of the foreground application, the available memory of the graphics processor, and the usage frequency of the at least one background application, the target resource cleanup strategy corresponding to the multiple applications is executed. Wherein, the first resource configuration information or the second resource configuration information includes at least: Cache resource quotas used to constrain cache memory usage; A background resource retention threshold used to constrain the amount of resources an application retains while it is in the background. This is a time limit for cleaning up background resources to constrain the duration an application remains in the background.

2. The method according to claim 1, characterized in that, The method further includes: If the process of the foreground application does not exist, obtain the first resource configuration information corresponding to the foreground application; wherein, the first resource configuration information corresponding to the foreground application is the baseline resource configuration predefined by the foreground application; During the loading process of the foreground application, an initial resource cleanup strategy corresponding to the foreground application is executed based on the first resource configuration information corresponding to the foreground application. When the process of the foreground application is loaded, first resource configuration information corresponding to the at least one background application is obtained, and at least one of the following is obtained: the running scenario mode of the foreground application, the available memory of the graphics processor, and the usage frequency of the at least one background application; wherein, the first resource configuration information corresponding to the at least one background application is the current resource configuration of the at least one background application.

3. The method according to claim 1, characterized in that, The determination of second resource configuration information for each of the multiple applications, based on at least one of the foreground application's runtime scenario mode, the available memory of the graphics processor, and the usage frequency of at least one background application, and first resource configuration information corresponding to each application, includes: Based on the available memory of the graphics processor, the memory state of the graphics processor is determined, and the memory state includes: a first memory state, a second memory state, or a third memory state; When the memory state is the first memory state, it is determined that the second resource configuration information corresponding to the plurality of applications is the same as the first resource configuration information corresponding to the plurality of applications. When the memory state is the second memory state, the background resource retention threshold in the first resource configuration information corresponding to the foreground application is reduced to obtain the second resource configuration information corresponding to the foreground application, and it is determined that the second resource configuration information corresponding to the at least one background application is the same as the first resource configuration information corresponding to the at least one background application, or the background resource retention threshold in the first resource configuration information corresponding to the at least one background application is reduced to obtain the second resource configuration information corresponding to the at least one background application. When the memory state is the third memory state, it is determined that the second resource configuration information corresponding to the plurality of applications is the same as the first resource configuration information corresponding to the plurality of applications.

4. The method according to claim 1, characterized in that, The determination of second resource configuration information for each of the multiple applications, based on at least one of the foreground application's runtime scenario mode, the available memory of the graphics processor, and the usage frequency of at least one background application, and first resource configuration information corresponding to each application, includes: Based on the usage frequency of the at least one background application, a frequency category of the at least one background application is determined, and the frequency category includes: a first frequency category, a second frequency category, or a third frequency category; When the frequency category of the background application is the first frequency category, it is determined that the second resource configuration information corresponding to the plurality of applications is the same as the first resource configuration information corresponding to the plurality of applications. When the frequency category of the background application is the second frequency category, it is determined that the second resource configuration information corresponding to the plurality of applications is the same as the first resource configuration information corresponding to the plurality of applications; or, it is determined that the second resource configuration information corresponding to the foreground application is the same as the first resource configuration information corresponding to the foreground application and the background resource retention threshold in the first resource configuration information corresponding to at least one background application is reduced to obtain the second resource configuration information corresponding to at least one background application. When the frequency category of the background application is the third frequency category, it is determined that the second resource configuration information corresponding to the multiple applications is the same as the first resource configuration information corresponding to the multiple applications.

5. The method according to claim 1, characterized in that, The determination of second resource configuration information for each of the multiple applications, based on at least one of the foreground application's runtime scenario mode, the available memory of the graphics processor, and the usage frequency of at least one background application, and first resource configuration information corresponding to each application, includes: When the running scenario mode of the foreground application is a high-load running scenario mode, the background resource retention threshold in the first resource configuration information corresponding to the foreground application is increased to obtain the second resource configuration information corresponding to the foreground application, and it is determined that the second resource configuration information corresponding to the at least one background application is the same as the first resource configuration information corresponding to the at least one background application. When the running scenario mode of the foreground application is switched from the high-load running scenario mode to the non-high-load running scenario mode, the background resource retention threshold in the second resource configuration information corresponding to the foreground application is updated to the background resource retention threshold in the first resource configuration information corresponding to the foreground application.

6. A resource cleaning device, characterized in that, include: The determining module is used to determine the second resource configuration information corresponding to the multiple applications based on at least one of the following: the running scenario mode of the foreground application, the available memory of the graphics processor, the usage frequency of at least one background application, and the first resource configuration information corresponding to the multiple applications respectively; the multiple applications include the foreground application and at least one background application. The processing module is used to execute the target resource cleanup strategy corresponding to the multiple applications based on at least one of the second resource configuration information corresponding to the multiple applications, the running scenario mode of the foreground application, the available memory of the graphics processor, and the usage frequency of the at least one background application. Wherein, the first resource configuration information or the second resource configuration information includes at least: Cache resource quotas used to constrain cache memory usage; A background resource retention threshold used to constrain the amount of resources an application retains while it is in the background. This is a time limit for cleaning up background resources to constrain the duration an application remains in the background.

7. The apparatus according to claim 6, characterized in that, The device further includes: The acquisition module is used to acquire first resource configuration information corresponding to the foreground application when the process of the foreground application does not exist; wherein, the first resource configuration information corresponding to the foreground application is a predefined baseline resource configuration of the foreground application; The processing module is further configured to execute an initial resource cleanup strategy corresponding to the foreground application based on the first resource configuration information corresponding to the foreground application during the process loading of the foreground application. The acquisition module is further configured to acquire, when the process of the foreground application has finished loading, first resource configuration information corresponding to the at least one background application, and acquire at least one of the following: the running scenario mode of the foreground application, the available memory of the graphics processor, and the usage frequency of the at least one background application; wherein, the first resource configuration information corresponding to the at least one background application is the current resource configuration of the at least one background application.

8. The apparatus according to claim 6, characterized in that, When determining the second resource configuration information corresponding to the multiple applications based on at least one of the following: the running scenario mode of the foreground application, the available memory of the graphics processor, the usage frequency of at least one background application, and the first resource configuration information corresponding to the multiple applications, the determining module is specifically used for: Based on the available memory of the graphics processor, the memory state of the graphics processor is determined, and the memory state includes: a first memory state, a second memory state, or a third memory state; When the memory state is the first memory state, it is determined that the second resource configuration information corresponding to the plurality of applications is the same as the first resource configuration information corresponding to the plurality of applications. When the memory state is the second memory state, the background resource retention threshold in the first resource configuration information corresponding to the foreground application is reduced to obtain the second resource configuration information corresponding to the foreground application, and it is determined that the second resource configuration information corresponding to the at least one background application is the same as the first resource configuration information corresponding to the at least one background application, or the background resource retention threshold in the first resource configuration information corresponding to the at least one background application is reduced to obtain the second resource configuration information corresponding to the at least one background application. When the memory state is the third memory state, it is determined that the second resource configuration information corresponding to the plurality of applications is the same as the first resource configuration information corresponding to the plurality of applications.

9. The apparatus according to claim 6, characterized in that, When determining the second resource configuration information corresponding to the multiple applications based on at least one of the following: the running scenario mode of the foreground application, the available memory of the graphics processor, the usage frequency of at least one background application, and the first resource configuration information corresponding to the multiple applications, the determining module is specifically used for: Based on the usage frequency of the at least one background application, a frequency category of the at least one background application is determined, and the frequency category includes: a first frequency category, a second frequency category, or a third frequency category; When the frequency category of the background application is the first frequency category, it is determined that the second resource configuration information corresponding to the plurality of applications is the same as the first resource configuration information corresponding to the plurality of applications. When the frequency category of the background application is the second frequency category, it is determined that the second resource configuration information corresponding to the plurality of applications is the same as the first resource configuration information corresponding to the plurality of applications; or, it is determined that the second resource configuration information corresponding to the foreground application is the same as the first resource configuration information corresponding to the foreground application, and the background resource retention threshold in the first resource configuration information corresponding to at least one background application is reduced to obtain the second resource configuration information corresponding to at least one background application. When the frequency category of the background application is the third frequency category, it is determined that the second resource configuration information corresponding to the multiple applications is the same as the first resource configuration information corresponding to the multiple applications.

10. The apparatus according to claim 6, characterized in that, When determining the second resource configuration information corresponding to the multiple applications based on at least one of the following: the running scenario mode of the foreground application, the available memory of the graphics processor, the usage frequency of at least one background application, and the first resource configuration information corresponding to the multiple applications, the determining module is specifically used for: When the running scenario mode of the foreground application is a high-load running scenario mode, the background resource retention threshold in the first resource configuration information corresponding to the foreground application is increased to obtain the second resource configuration information corresponding to the foreground application, and it is determined that the second resource configuration information corresponding to the at least one background application is the same as the first resource configuration information corresponding to the at least one background application. When the running scenario mode of the foreground application is switched from the high-load running scenario mode to the non-high-load running scenario mode, the background resource retention threshold in the second resource configuration information corresponding to the foreground application is updated to the background resource retention threshold in the first resource configuration information corresponding to the foreground application.