Memory recovery method, memory recovery device, electronic device, and storage medium

By defining usage scenarios and setting capacity thresholds in the terminal, the memory reclamation strategy is dynamically adjusted, solving the problem that existing memory reclamation methods cannot meet user needs and achieving more efficient memory management.

CN122111629APending Publication Date: 2026-05-29BEIJING XIAOMI MOBILE SOFTWARE CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
BEIJING XIAOMI MOBILE SOFTWARE CO LTD
Filing Date
2024-11-27
Publication Date
2026-05-29

Smart Images

  • Figure CN122111629A_ABST
    Figure CN122111629A_ABST
Patent Text Reader

Abstract

The present disclosure relates to a memory recycling method, a memory recycling device, an electronic device and a storage medium. The memory recycling method comprises: determining a current running state of an application program in a terminal, and determining a current use scenario of the terminal based on the current running state, wherein different running states correspond to different use scenarios of the terminal; determining a capacity threshold based on the current use scenario of the terminal and a mapping relationship, wherein the mapping relationship is a mapping relationship between a use scenario corresponding to the terminal and a capacity threshold, and different use scenarios correspond to different capacity thresholds; and performing memory recycling in response to monitoring that a remaining capacity of the memory of the terminal meets the capacity threshold. The memory recycling method provided by the embodiments of the present disclosure can realize dynamic adjustment of a memory recycling strategy.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of information processing, and in particular to a memory reclamation method, a memory reclamation device, an electronic device, and a storage medium. Background Technology

[0002] Memory reclamation is one of the processes by which the operating system manages memory resources. It involves releasing memory that is no longer needed in the operating system so that it can be reused by other processes or operations.

[0003] In related technologies, memory reclamation methods are difficult to meet users' needs. Summary of the Invention

[0004] To overcome the problems existing in related technologies, this disclosure provides a memory reclamation method, a memory reclamation device, an electronic device, and a storage medium.

[0005] According to a first aspect of the present disclosure, a memory reclamation method is provided, comprising: determining the current running state of an application in a terminal, and determining the current usage scenario of the terminal based on the current running state, wherein different running states correspond to different usage scenarios of the terminal; determining a capacity threshold based on the current usage scenario of the terminal and a mapping relationship, wherein the mapping relationship is a mapping relationship between the usage scenario corresponding to the terminal and the capacity threshold, and different usage scenarios correspond to different capacity thresholds; and performing memory reclamation in response to detecting that the remaining memory capacity of the terminal meets the capacity threshold.

[0006] In some possible implementations, determining the capacity threshold based on the usage scenario and the mapping relationship includes: determining a first capacity threshold corresponding to the usage scenario and / or a second capacity threshold corresponding to the usage scenario based on the usage scenario and the mapping relationship; wherein the first capacity threshold represents the capacity threshold that triggers memory reclamation, and the second threshold represents the capacity threshold that triggers the cessation of memory reclamation.

[0007] In some possible implementations, the use case includes: a first scenario and a second scenario, wherein the first scenario includes a scenario where the application is in a running state, and the second scenario includes other scenarios besides the first scenario; determining the capacity threshold includes: in response to the use case being the first scenario, determining a first capacity threshold as M, and / or determining a second capacity threshold as N; in response to the use case being the second scenario, determining a first capacity threshold as P, and / or determining a second capacity threshold as Q; wherein M is greater than or equal to 0, N is greater than or equal to 0, P is greater than or equal to 0, Q is greater than or equal to 0, M is greater than or equal to P, and N is greater than or equal to Q.

[0008] In some possible implementations, after determining the current usage scenario of the terminal, the method further includes: predicting the future usage scenario of the terminal based on the current usage scenario of the terminal and the user's historical information on using the terminal; determining the future capacity threshold based on the future usage scenario and the mapping relationship; and performing memory reclamation processing in response to detecting that the remaining memory capacity of the terminal at the future time meets the requirement of the future capacity threshold.

[0009] In some possible implementations, determining the current running state of an application in the terminal includes: in response to detecting a startup request corresponding to the application, determining that the current running state of the application is a startup state, wherein the usage scenario corresponding to the startup state is a first scenario; in response to detecting the removal of a target window from the terminal display interface, determining that the current running state of the application is a non-startup state, wherein the usage scenario corresponding to the non-startup state is a second scenario, and the target window is a window that exists in the startup state of the application.

[0010] According to a second aspect of the present disclosure, a memory reclamation apparatus is provided, comprising: a determining unit, configured to determine the current running state of an application in a terminal, and determine the current usage scenario of the terminal based on the current running state, and configured to determine a capacity threshold based on the current usage scenario of the terminal and a mapping relationship, wherein the mapping relationship is a mapping relationship between the usage scenario corresponding to the terminal and the capacity threshold, different usage scenarios correspond to different capacity thresholds, and different running states correspond to different usage scenarios of the terminal; and a memory reclamation unit, configured to perform memory reclamation when it is detected that the memory capacity of the terminal meets the capacity threshold.

[0011] In some possible implementations, the determining unit determines the capacity threshold based on the usage scenario and the mapping relationship in the following manner: based on the usage scenario and the mapping relationship, it determines a first capacity threshold corresponding to the usage scenario and / or a second capacity threshold corresponding to the usage scenario; wherein, the first capacity threshold represents the capacity threshold that triggers memory reclamation, and the second threshold represents the capacity threshold that triggers the cessation of memory reclamation.

[0012] In some possible implementations, the usage scenarios include: a first scenario and a second scenario, wherein the first scenario includes a scenario where the application is in a running state, and the second scenario includes other scenarios besides the first scenario; the determining unit determines the capacity threshold in the following manner: when the usage scenario is the first scenario, it determines the first capacity threshold as M, and / or determines the second capacity threshold as N; when the usage scenario is the second scenario, it determines the first capacity threshold as P, and / or determines the second capacity threshold as Q; wherein M is greater than or equal to 0, N is greater than or equal to 0, P is greater than or equal to 0, Q is greater than or equal to 0, M is greater than or equal to P, and N is greater than or equal to Q.

[0013] In some possible implementations, after determining the current usage scenario of the terminal, the determining unit is further configured to: predict the usage scenario of the terminal at a future time based on the current usage scenario of the terminal and the user's historical information on using the terminal; the determining unit is further configured to: determine the future capacity threshold at the future time based on the usage scenario at the future time and the mapping relationship; the memory reclamation unit is further configured to: perform memory reclamation processing when it is detected that the remaining memory capacity of the terminal at the future time meets the requirements of the future capacity threshold.

[0014] In some possible implementations, the determining unit determines the current running state of the application in the terminal in the following ways: when a startup request corresponding to the application is detected, the current running state of the application is determined to be a startup state, wherein the usage scenario corresponding to the startup state is a first scenario; when a target window is detected to be removed from the terminal display interface, the current running state of the application is determined to be a non-startup state, wherein the usage scenario corresponding to the non-startup state is a second scenario, and the target window is a window that exists in the startup state of the application.

[0015] According to a third aspect of the present disclosure, an electronic device is provided, comprising: a processor; a memory for storing processor-executable instructions; wherein the processor is configured to: execute the memory reclamation method described in the first aspect or any of some possible embodiments of the first aspect.

[0016] According to a fourth aspect of the present disclosure, a storage medium is provided, the storage medium storing instructions that, when executed by a processor, enable the processor to perform the memory reclamation method described in the first aspect or any of the possible implementations of the first aspect.

[0017] The technical solutions provided by the embodiments of this disclosure can include the following beneficial effects: By determining the running state of the application in the terminal, the usage scenario corresponding to the terminal is determined. Since the mapping relationship is between different usage scenarios and different capacity thresholds, a capacity threshold matching the current usage scenario of the terminal can be determined based on the determined current usage scenario and the mapping relationship. The capacity threshold is used as the trigger threshold for memory reclamation processing, and memory reclamation is performed when the remaining memory capacity of the terminal meets the capacity threshold requirement. Therefore, the memory reclamation strategy can be adjusted promptly when the current usage scenario of the terminal changes, thereby reducing the possibility of system performance degradation caused by a mismatch between the memory reclamation strategy and the current scenario, or the inability to meet sudden system demands due to a mismatch between the memory reclamation strategy and the current scenario.

[0018] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description

[0019] The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure.

[0020] Figure 1 This is a flow chart of a memory reclamation method according to an exemplary embodiment. Figure 1 .

[0021] Figure 2A This is a flowchart illustrating a method for determining the current running state of a program running in a terminal, according to an exemplary embodiment.

[0022] Figure 2B This is a flowchart illustrating a program startup process according to an exemplary embodiment.

[0023] Figure 3 This is a flowchart illustrating a method for determining a capacity threshold according to an exemplary embodiment. Figure 1 .

[0024] Figure 4A This is a flowchart of a method for determining a capacity threshold according to an exemplary embodiment.

[0025] Figure 4B This is a schematic diagram illustrating a method for determining a capacity threshold according to an exemplary embodiment.

[0026] Figure 4C This is a schematic flowchart of a memory reclamation method according to an exemplary embodiment.

[0027] Figure 5 This is a flowchart illustrating a memory reclamation method according to an exemplary embodiment. Figure 3 .

[0028] Figure 6 This is a block diagram of a memory reclamation device according to an exemplary embodiment. Figure 1 .

[0029] Figure 7 This is a block diagram illustrating an electronic device according to an exemplary embodiment.

[0030] Figure 8 This is a block diagram two illustrating a memory reclamation device according to an exemplary embodiment. Detailed Implementation

[0031] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure.

[0032] Memory reclamation is one of the processes by which the operating system manages memory resources. It involves releasing memory that is no longer needed in the operating system so that it can be reused by other processes or operations.

[0033] In some scenarios, there are various ways to implement memory reclamation (hereinafter referred to as memory reclamation methods). For ease of understanding, the following will use Linux as an example to illustrate the memory reclamation methods, which may include the following A1) to C1): A1) background memory reclamation method, B1) direct memory reclamation method, or C1) memory exhaustion mechanism (Out Of Memory, OOM).

[0034] However, the aforementioned memory reclamation methods can be understood as a static method. That is, memory reclamation is implemented by configuring static trigger conditions. For example, a fixed threshold can be configured, and memory reclamation can be triggered when the terminal memory usage meets the threshold requirements.

[0035] It is understandable that the operating system may be affected by user operations or process running status, corresponding to multiple use cases. However, static memory reclamation methods are not suitable for all use cases. In some cases, static memory reclamation methods may lead to a decrease in system performance due to excessive memory reclamation, or fail to meet the system's sudden demand due to untimely memory reclamation.

[0036] Based on this, to solve the aforementioned technical problems, this disclosure proposes a memory reclamation method. By determining the current usage scenario of the terminal and combining the mapping relationship between the usage scenario and a threshold (e.g., a threshold for memory reclamation), a threshold corresponding to the current usage scenario is determined. Memory reclamation is then performed when the remaining memory capacity in the current usage scenario meets the threshold requirement. Since a pre-established association between different usage scenarios of the terminal and different thresholds is established, the threshold matching the current usage scenario can be determined by identifying the current usage scenario. Memory reclamation can then be performed based on the determined threshold, thereby achieving dynamic adjustment of operating system memory reclamation.

[0037] It should be noted that the memory reclamation method provided in this disclosure can be applied to network devices. Network devices may include, for example, terminals. Terminals include, but are not limited to, at least one of the following: mobile phones, wearable devices, IoT devices, automobiles with communication capabilities, smart cars, tablets, computers with wireless transceiver capabilities, virtual reality (VR) terminal devices, augmented reality (AR) terminal devices, wireless terminal devices in industrial control, wireless terminal devices in self-driving, wireless terminal devices in remote medical surgery, wireless terminal devices in smart grids, wireless terminal devices in transportation safety, wireless terminal devices in smart cities, and wireless terminal devices in smart homes.

[0038] It should be noted that all actions involving the acquisition of signals, information, or data in this disclosure are carried out in compliance with the relevant data protection laws and policies of the country where the location is situated, and with authorization from the owner of the relevant device.

[0039] In the embodiments of this disclosure, terms such as “in response to…”, “in response to determining…”, “in the case of…”, “when…”, “if…”, “if…”, etc., can be used interchangeably.

[0040] In the embodiments disclosed herein, terms such as “greater than”, “greater than or equal to”, “not less than”, “more than”, “more than or equal to”, “not less than”, “higher than”, “higher than or equal to”, “not lower than”, and “above” can be substituted for each other, and terms such as “less than”, “less than or equal to”, “not greater than”, “less than”, “less than or equal to”, “not more than”, “lower than”, “lower than or equal to”, “not higher than”, and “below” can be substituted for each other.

[0041] For ease of understanding, some technical terms involved in the embodiments of this disclosure will be explained by way of example below:

[0042] Operating system status: This usually refers to the operating status of the operating system, which can include: performance status (such as CPU usage, memory usage, hard disk usage, or network usage) or process status (such as the resource usage of currently running processes).

[0043] Application lifecycle: refers to the entire process of an application from creation and operation to termination, which typically includes the following stages A1) to G1):

[0044] A1) Installation: The application is installed into the operating system, which may include copying necessary files, setting configurations, and registry entries.

[0045] B1) Startup: When a user or system starts an application, the operating system loads the application's code and resources into memory, and the application executes initialization code to prepare the runtime environment.

[0046] C1) Running: The application enters the main execution phase, responding to user input, performing tasks, and processing data. During this phase, the application may create multiple threads or processes to perform different tasks.

[0047] D1) Paused: For some applications, especially mobile applications, the application may pause when the user switches to another application or the device enters a sleep state. In a paused state, the application does not execute any code, but its state and memory contents are usually preserved.

[0048] E1) Resumed: Resumes from a paused state, allowing the application to continue executing its previous state and tasks.

[0049] F1 Shutdown: The user or system closes the application. The application executes cleanup code, such as saving data, releasing resources, and unloading the application from memory to terminate its operation.

[0050] G1 Uninstallation: The application is completely removed from the operating system, including deleting all related files and configuration items.

[0051] It should be noted that the startup state of the application mentioned in the embodiments of this disclosure may be, for example, the state corresponding to B1), while the non-startup state of the application mentioned in the embodiments of this disclosure may be, for example, one or more of A1), C1), D1), E1), F1), or G1).

[0052] Framework Hook (FW HOOK): In software development, FW HOOK may refer to a hook mechanism provided within a software framework, allowing developers to insert custom code when the framework performs specific operations. Hooks are typically used to extend or change the behavior of a framework without modifying its core code. For example, many web frameworks provide event hooks, allowing developers to execute custom logic at specific points in the request's lifecycle. In embodiments of this disclosure, the application of FW HOOK may include, for example, setting "monitoring points" with FW HOOK mechanisms (e.g., "monitoring point 1" and / or "monitoring point 2" in the embodiments of this disclosure below) or performing "instrumentation" based on FW HOOK mechanisms.

[0053] KSWAPD is a kernel thread in the Linux kernel whose main responsibility is to manage the operating system's swap space and paging of memory pages. When memory is insufficient, KSWAPD is responsible for moving infrequently used pages from physical memory to swap space (if swap space is configured) to free up physical memory for other processes that need it more. KSWAPD is also responsible for swapping pages that have already been swapped out back into physical memory when needed.

[0054] A free page refers to a page frame in the virtual memory system that is not used by any process. A page frame is considered free when it is not allocated to any process by the operating system. Free pages can be used by the operating system to satisfy new memory allocation requests, such as when a process requests more memory. The operating system maintains a list or pool of free pages to track which page frames are free and can be quickly allocated to processes that need memory. In this embodiment, a free page can be understood as unused memory space (or remaining memory capacity), which can be allocated to various applications and system processes. When terminal memory (or remaining memory capacity) is insufficient, the system may allocate additional memory from free pages to meet the demand. When an application or process no longer needs to use certain memory, this memory can be reclaimed and returned to the free page pool for use by other programs, improving memory utilization.

[0055] In an operating system, physical memory is divided into fixed-size blocks, each called a page frame. Each page frame can store a portion of virtual memory data.

[0056] The process file system (proc file system): In Linux operating systems, the proc file system is a special file system that is not based on traditional block devices but is dynamically created by the operating system kernel. It provides users with a virtual file and directory hierarchy through which they can access and manipulate kernel runtime information. The proc file system is typically mounted under the proc directory, and users and programs can access it using standard file system operations such as the commands cat, more, and echo. It is an indispensable part of Linux and other Unix-like systems, greatly facilitating system administration and maintenance.

[0057] Figure 1 This is a flow chart of a memory reclamation method according to an exemplary embodiment. Figure 1 ,like Figure 1 As shown, the memory reclamation method is used in terminals or servers, and the memory reclamation method includes the following steps.

[0058] In step S11, the current running state of the application in the terminal is determined, and the current usage scenario of the terminal is determined based on the current running state.

[0059] In step S12, a capacity threshold is determined based on the current usage scenario of the terminal and the mapping relationship, wherein the mapping relationship is the mapping relationship between the usage scenario corresponding to the terminal and the capacity threshold.

[0060] In step S13, memory reclamation is performed in response to the detection that the remaining memory capacity of the terminal meets the capacity threshold.

[0061] The usage scenario is determined based on the running status of the application deployed on the terminal. Different running statuses of the application correspond to different usage scenarios of the terminal, and different usage scenarios correspond to different capacity thresholds. The mapping relationship is a preset mapping relationship.

[0062] In this embodiment, a mapping relationship can be established to determine the correlation between different usage scenarios and different capacity thresholds. Based on the determined usage scenario of the terminal and the mapping relationship, a capacity threshold matching the terminal's current usage scenario can be determined. This capacity threshold is used as the trigger threshold for memory reclamation, and memory reclamation is performed when the terminal's remaining memory capacity meets the threshold requirement. Therefore, the memory reclamation strategy can be adjusted promptly when the terminal's current usage scenario changes, thereby reducing the possibility of system performance degradation or failure to meet sudden system demands due to a mismatch between the memory reclamation strategy and the current scenario.

[0063] In some embodiments, terms such as "terminal use case", "operating system use case", "operating system use case of terminal", or "operating system use case deployed on terminal" can be used interchangeably.

[0064] In some embodiments, terms such as "resource recycling," "memory recycling," "space recycling," and "storage resource recycling" can be used interchangeably.

[0065] In some embodiments, terms such as "remaining memory capacity threshold," "capacity threshold," "threshold," "memory threshold," "resource amount threshold," "storage space threshold," and "water level" can be used interchangeably. For "capacity threshold," its form can be, for example, a numerical value (an exact value or a percentage value, etc.) or a numerical range (an exact range or a percentage range, etc.) describing the remaining memory capacity of the terminal.

[0066] It is understandable that the current usage scenario of the terminal can be understood as the usage scenario corresponding to the terminal's operating system. The usage scenario corresponding to the terminal's operating system (hereinafter referred to as usage scenario) can include multiple usage scenarios, and the division of multiple usage scenarios can be based on factors that can affect the state of the operating system.

[0067] For example, factors that can affect the state of the operating system may include one or more of the following: A2) to C2)

[0068] A2) Hardware resources: For example, processor-related resources (e.g., processor speed, number of cores, cache size, etc.), memory-related resources (e.g., memory size or memory speed, etc.) or storage device-related resources (e.g., hard drive read / write speed or hard drive capacity, etc.).

[0069] B2) Software resources: For example, system load-related resources (e.g., the number of applications, the resource requirements of the applications, or the running status of the applications) or system services (e.g., the resource overhead of background services or the resource overhead of daemons).

[0070] C2) System configuration: For example, the configuration parameters of the operating system kernel or the performance of the operating system kernel.

[0071] Therefore, the usage scenarios corresponding to the terminal's operating system can be categorized based on the factors mentioned above. For ease of understanding, the following will categorize the usage scenarios based on the application's running state, using Linux as an example for illustration.

[0072] It should be noted that the operating system corresponding to the embodiments of this disclosure can also be other operating systems, such as Android, Windows, iOS, etc.

[0073] It should also be noted that in some monitoring scenarios, such as monitoring scenario A, memory reclamation is triggered by monitoring the terminal's remaining memory capacity (hereinafter referred to as remaining memory capacity). Meeting a capacity threshold requirement for remaining memory capacity can be understood as the terminal's remaining memory capacity meeting the capacity threshold requirement. Since there is a correlation between the terminal's remaining memory capacity and blank pages, in some monitoring scenarios, such as monitoring scenario B, memory reclamation can also be triggered by monitoring the capacity corresponding to blank pages. For example, memory reclamation is performed in response to detecting that the terminal's blank page capacity meets the capacity threshold requirement. In some scenarios, both monitoring scenario A and monitoring scenario B may be included simultaneously. In this case, for example, a mapping relationship can be used to determine the capacity thresholds corresponding to the two different monitoring scenarios.

[0074] It is understood that the capacity threshold has different meanings in the different monitoring scenarios described above. For example, the meanings of the capacity threshold in monitoring scenario A and monitoring scenario B are different (for example, the meaning of the capacity threshold in monitoring scenario A can be understood as the remaining memory capacity threshold of the terminal, while the meaning of the capacity threshold in monitoring scenario B can be understood as the capacity threshold of the terminal's blank pages). However, it is understood that regardless of the scenario, it falls within the scope of protection of the embodiments disclosed herein.

[0075] For ease of understanding, the following description will be based on monitoring scenario A. For the implementation of this embodiment in monitoring scenario B or other related monitoring scenarios, please refer to the description of the relevant implementation in monitoring scenario A for adaptive adjustment.

[0076] In some embodiments, determining the current usage scenario can be achieved by monitoring the running status of applications in the terminal and dividing the usage scenario based on the monitoring results, so that different monitoring results correspond to different usage scenarios.

[0077] For ease of understanding, the following embodiments divide the running state of an application into a "started state" and a "non-started state," and further divide the usage scenarios into "first scenario" and "second scenario" based on the "started state" and "non-started state." For example, when the application is in the started state, the corresponding usage scenario is the first scenario; when the application is in the non-started state, the corresponding usage scenario is the second scenario, and so on.

[0078] Figure 2A This is a flowchart illustrating a method for determining the current running state of a program running in a terminal, according to an exemplary embodiment. Figure 2A As shown, the method for determining the current running status of a program in a terminal includes the following steps.

[0079] In step S21, relevant information of the application is monitored, wherein different types of relevant information correspond to different running states of the application.

[0080] In step S22-1, in response to detecting the startup request corresponding to the application, the current running state of the application is determined to be the startup state.

[0081] In step S22-2, in response to the detection that the target window has been removed from the terminal display interface, it is determined that the current running state of the application is a non-starting state, wherein the target window is the window that exists in the corresponding starting state of the application.

[0082] In this embodiment of the disclosure, since different types of relevant information correspond to different running states of applications, the running state of an application can be determined by monitoring the relevant information of the application, and then the current usage scenario of the terminal can be determined based on the running state of the application, thereby realizing the determination of the current usage scenario.

[0083] It is understandable that detecting a startup request for an application could mean detecting a startup request for one application, or it could mean detecting startup requests for multiple applications.

[0084] It is understandable that different applications may have different lifecycles. The current running state of an application can be determined based on the characteristics of each state in the application's lifecycle (such as the process of program execution).

[0085] For example, in some scenarios, the running process of the application's startup state in its lifecycle is as follows: Figure 2B As shown. Figure 2B This is a flowchart illustrating a program startup process according to an exemplary embodiment. The application startup process includes the following steps:

[0086] In step S23-1, in response to receiving a startup request, the application is woken up and started.

[0087] In step S23-2, during the application startup process, a target window is added.

[0088] In step S23-3, the type of the target window is obtained, and its display content and style are determined.

[0089] In step S23-4, the target window is drawn based on the type of the acquired target window.

[0090] In step S23-5, the application runtime interface is loaded in the background.

[0091] In step S23-6, in response to the completion of the running interface loading, the target window is removed and the running interface is displayed.

[0092] In some embodiments, step S23-1 may be achieved by the application starting to execute a startup thread (e.g., the Activity thread) to wake up and launch the application. It is understood that after step S23-1, the application can be considered to have entered the startup state. Therefore, if the terminal is detected to be performing the relevant action of step S23-1, the application is considered to be in the startup state.

[0093] For monitoring the actions related to step S23-1, corresponding monitoring points can be set up along this path. For example... Figure 2B In the case of step S23-1, "monitoring point 1" will mark the running state of the application (e.g., mark it as the startup state) and / or mark the current usage scenario of the terminal (e.g., mark it as the first scenario).

[0094] The detected startup request could be, for example, a user's startup request. Examples include detecting a user request made by interacting with a corresponding control on the terminal display interface, detecting a user request confirmed by voice, or detecting a user request for pre-set automatic triggering.

[0095] In some embodiments, for step S23-2, adding a target window can be done, for example, by adding the target window in the background. The target window can be, for example, a window that includes a loading animation of the application startup, or a loading screen corresponding to the application startup.

[0096] In some embodiments, for step S23-3, the type of the target window is determined, for example, it may be determined as at least one of the following types: application window, dialog box window, document window, floating window, or pop-up window, etc.

[0097] In some embodiments, for steps S23-4, drawing the target window may be, for example, adding a loading animation or text content for prompting the user that the current application is in the startup state.

[0098] In some embodiments, for steps S23-5, the running interface can be understood as the interface corresponding to the normal operation of the application. The user can interact with the application in this interface.

[0099] In some embodiments, it can be understood that after steps S23-6, the application startup state can be considered to have ended, and it is about to enter a non-startup state (e.g., running state, or reload scenario). Therefore, it can be considered that if the terminal is detected to be performing the relevant actions of steps S23-6, the application is about to enter a non-startup state. It should be noted that a reload scenario can be understood as, for example, a scenario where the application is closed and restarted after running for a period of time.

[0100] For monitoring the actions related to steps S23-6, corresponding monitoring points can be set up along this path. For example... Figure 2B"Monitoring Point 2" will mark the application's running state (e.g., marked as non-started state) and / or mark the terminal's current usage scenario (e.g., marked as second scenario) when it detects the occurrence of steps S23-6. This allows for timely determination of the corresponding capacity threshold after the application switches from the started state to the non-started state, reducing the possibility of mismatch between the usage scenario and the capacity threshold due to untimely determination.

[0101] Therefore, the running status of the application can be determined through the relevant steps S23-1 to S23-6 as described above.

[0102] Understandably, the memory reclamation process may involve multiple execution actions. Capacity thresholds, serving as triggering conditions for memory reclamation (e.g., triggering start, triggering termination, or triggering termination), can be used in some scenarios to set separate triggering conditions for each of the multiple execution actions in the memory reclamation process by setting multiple capacity thresholds.

[0103] In some embodiments, the capacity threshold includes multiple capacity thresholds. The method for determining the capacity threshold can be, for example, through... Figure 3 Related exemplary implementations are described below. Figure 3 This is a flowchart illustrating a method for determining a capacity threshold according to an exemplary embodiment. Figure 1 The method for determining the capacity threshold includes the following steps:

[0104] In step S31, the current usage scenario of the terminal is determined.

[0105] In step S32, based on the usage scenario and the mapping relationship, a first capacity threshold corresponding to the usage scenario and / or a second capacity threshold corresponding to the usage scenario are determined.

[0106] The first capacity threshold represents the capacity threshold that triggers memory reclamation, and the second capacity threshold represents the capacity threshold that triggers the cessation of memory reclamation. The mapping relationship is the mapping relationship between the preset use scenario and the first capacity threshold, and / or between the use scenario and the second capacity threshold.

[0107] In this embodiment, the mapping relationship is a preset mapping relationship between a usage scenario and a first capacity threshold, and / or between a usage scenario and a second capacity threshold. Therefore, given the current corresponding usage scenario, the first capacity threshold and / or the second capacity threshold corresponding to the usage scenario can be determined. Furthermore, the determined first capacity threshold can be used as the threshold for initiating memory reclamation, and / or the second capacity threshold can be used as the threshold for stopping memory reclamation, thereby improving the adjustability of the memory reclamation process and providing users with more diverse memory reclamation solutions based on different usage scenarios.

[0108] It is understood that, based on the above-described related embodiments, the terminal may correspond to multiple usage scenarios (such as the first and second scenarios mentioned above). When there are multiple usage scenarios and multiple capacity thresholds, for example, it can be achieved through the following... Figure 4A Related exemplary implementations are described below. Figure 4A This is a flowchart (2) illustrating a method for determining a capacity threshold according to an exemplary embodiment. The method for determining a capacity threshold includes the following steps:

[0109] In step S41, the current usage scenario of the terminal is determined.

[0110] In step S42-1, in response to the usage scenario being the first scenario, a first capacity threshold is determined to be M, and / or a second capacity threshold is determined to be N.

[0111] In step S42-2, in response to the usage scenario being the second scenario, a first capacity threshold is determined as P, and / or a second capacity threshold is determined as Q.

[0112] Where M is greater than or equal to 0, N is greater than or equal to 0, P is greater than or equal to 0, Q is greater than or equal to 0, M is greater than or equal to P, and N is greater than or equal to Q.

[0113] In this embodiment of the disclosure, by setting independent first capacity thresholds and second capacity thresholds for different scenarios, the adjustability of the memory reclamation process can be improved, and more diverse memory reclamation solutions can be provided to users based on different usage scenarios.

[0114] It is understood that determining the first capacity threshold and / or the second capacity threshold can be achieved, for example, through the aforementioned related embodiments, and will not be elaborated here.

[0115] It is understandable that the first scenario includes application startup, while the second scenario includes application runtime. Regarding the first capacity threshold, memory usage is lower during application runtime compared to application startup. In this case, the first capacity threshold (M) for the first scenario can be set higher than the first capacity threshold (P) for the second scenario to initiate memory reclamation processes earlier in the first scenario. Similarly, it is understandable that, regarding the second capacity threshold, the second capacity threshold (N) for the first scenario can be set higher than the second capacity threshold (Q) for the second scenario to terminate memory reclamation processes promptly in the first scenario.

[0116] To facilitate understanding, the following will be explained through... Figure 4B The above implementation methods are described with scenario-based examples. Figure 4B This is a schematic diagram illustrating a method for determining a capacity threshold according to an exemplary embodiment.

[0117] like Figure 4B As shown, the target thread can be understood as a thread used to perform memory reclamation (e.g., a KSWAPD thread). The target thread's sleep state can be understood as a state where memory reclamation is stopped, and its working state can be understood as a state where memory reclamation is performed. The target thread is in a memory reclamation state, for example, in response to the detection that the remaining memory capacity of the terminal (or by monitoring the capacity of free pages) meets a first capacity threshold (e.g., a first capacity threshold M in a first scenario, or a first capacity threshold P in a second scenario), thus controlling the target thread to be in a memory reclamation state. The target thread is in a stopped memory reclamation state, for example, in response to the detection that the remaining memory capacity of the terminal (or by monitoring the capacity of free pages) meets a second capacity threshold (e.g., a first capacity threshold N in a second scenario, or a second capacity threshold Q in a second scenario), thus controlling the target thread to be in a stopped memory reclamation state.

[0118] Therefore, by adjusting the first and second capacity thresholds for different usage scenarios, the target thread can be more likely to enter a dormant state (a state without memory reclamation) under high system load, and more likely to enter a running state (a state with memory reclamation) under low system load. On the one hand, this makes memory reclamation more likely to be triggered in low-load scenarios, reducing the possibility of insufficient memory due to delayed triggering. On the other hand, it makes memory reclamation less likely to be triggered in high-load scenarios, reducing the possibility of system performance degradation due to excessive reclamation of blank pages.

[0119] It should be noted that, Figure 4B The warning threshold in the system can be understood as a memory safety line set by the system, serving as a threshold for relating to other related memory processing mechanisms. Figure 4B The curve in the diagram can be understood as a blank page, and the vertical axis corresponding to the curve can be understood as the capacity corresponding to the blank page.

[0120] It should also be noted that the values ​​of M, N, P, or warning thresholds are usually determined based on the relevant hardware performance of the terminal (e.g., the chip), or the load, empty limits, and reserved memory of relevant components (e.g., the central processing unit).

[0121] In summary, different first and / or second capacity thresholds can be set for different scenarios to control the sleep or run of target threads, thereby enabling adaptive adjustment of memory reclamation strategies for different scenarios.

[0122] Understandably, based on the above Figure 4B As can be seen from the described scenario, the system can make certain predictions about future scenarios based on the current scenario during its operation. For example, ... Figure 4B As shown, if the usage scenario is in the first scenario, it will usually enter the second scenario (i.e., after the application starts, it will transition from the startup state to the running state). In this case, it can be done as follows: Figure 4C Perform appropriate memory reclamation. Figure 4C This is a schematic flowchart of a memory reclamation method according to an exemplary embodiment. The memory reclamation method includes the following steps:

[0123] In step S41-1, the current usage scenario is determined.

[0124] In step S41-2, in response to the current usage scenario being the first scenario, it is determined whether the current scenario is about to switch to the second scenario.

[0125] In step S41-3, if the current scene is about to switch to the second scene, the capacity threshold is determined to be the capacity threshold corresponding to the second scene.

[0126] In step S41-4, if the current scene is not switched to the second scene, the capacity threshold is determined to be the capacity threshold corresponding to the first scene.

[0127] In steps S41-5, memory reclamation is performed based on the determined capacity threshold.

[0128] Therefore, memory reclamation in this case can be achieved through the above steps S41-1 to S41-5.

[0129] It should be noted that, for step S41-1, for example, it can be done through... Figure 2B The relevant "monitoring points" are identified in the current usage scenario.

[0130] In some embodiments, it is understood that if the relevant information corresponding to "monitoring point 2" is determined in step S41-1, it can be determined that the current scene is about to switch to the second scene (then the relevant content of step S41-3 can be executed). If the relevant information corresponding to "monitoring point 2" is not determined in step S41-1, it can be determined that the current scene will not switch to the second scene (then the relevant content of step S41-4 can be executed).

[0131] In some embodiments, “the current scenario does not switch to the second scenario” can be understood as keeping the current scenario or switching the current scenario to another scenario (a use case with a different application running state than the second scenario, such as a use case where the application is in a “closed state” or “uninstalled state”).

[0132] In some embodiments, for step S41-5, for example, the threshold corresponding to memory reclamation can be modified based on the proc file system to the capacity threshold determined in step S41-3 or step S41-4, and memory reclamation can be performed based on the modified threshold.

[0133] Understandably, future usage scenario predictions can be achieved by combining user habits with relevant AI models, thereby improving the accuracy of future usage scenario predictions and enabling the terminal to adjust the corresponding capacity thresholds in a timely and accurate manner for precise dynamic memory reclamation.

[0134] For example, Figure 5 This is a flowchart illustrating a memory reclamation method according to an exemplary embodiment. Figure 3 Memory reclamation methods include the following steps.

[0135] In step S51, based on the current usage scenario of the terminal and the user's historical information on terminal usage, the usage scenario of the terminal at future moments is predicted.

[0136] In step S52, the future capacity threshold corresponding to the future time is determined based on the usage scenario and mapping relationship corresponding to the future time.

[0137] In step S53, in response to the detection that the terminal's remaining memory capacity at a future time meets the requirement of the future capacity threshold, memory reclamation is performed.

[0138] In this embodiment, by predicting future usage scenarios and determining the corresponding future capacity thresholds, the memory reclamation method for those future moments can be determined in advance, thereby improving the effectiveness of memory reclamation in the future (e.g., by determining the capacity thresholds for future scenarios in advance, corresponding memory reclamation strategies can be specified in advance, reducing the problem of untimely memory reclamation caused by sudden tasks). Furthermore, by combining the applicable scenarios of the terminal with corresponding historical information for prediction, the accuracy of predicting future usage scenarios can be improved.

[0139] It should be noted that the future capacity threshold, which can be understood as the capacity threshold corresponding to the terminal's usage scenario at a future time, can be determined based on the mapping relationship once the terminal confirms the corresponding usage scenario at a future time.

[0140] It is understandable that the remaining memory capacity at a future time can be understood as the remaining memory capacity of the terminal as monitored at a future time.

[0141] It should be noted that historical information can be information that characterizes a user's terminal usage habits. For example, information characterizing application usage habits (e.g., application wake-up time, application shutdown time, or application runtime), or information characterizing terminal usage location habits (e.g., frequency of terminal use in different locations), or information characterizing terminal operation habits (e.g., launch order information between different applications or touch order information for various controls in an application).

[0142] It should also be noted that future scenario predictions can be achieved, for example, through AI models pre-deployed in the terminal.

[0143] Therefore, the above embodiments can achieve accurate prediction of future scenarios, thereby enabling accurate prediction of future scenario reclamation strategies and improving the effectiveness of memory reclamation in future scenarios.

[0144] The memory reclamation method proposed in this disclosure can improve the effect of memory reclamation, thereby reducing the system memory allocation latency without affecting the operation of related applications.

[0145] Based on the same concept, embodiments of this disclosure also provide a memory reclamation device.

[0146] It is understood that the memory reclamation device provided in this disclosure includes hardware structures and / or software modules corresponding to each function in order to achieve the above-mentioned functions. In conjunction with the units and algorithm steps of the various examples disclosed in this disclosure, this disclosure can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed by hardware or by computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the technical solutions of this disclosure.

[0147] Figure 6 This is a block diagram of a memory reclamation device according to an exemplary embodiment. Figure 1 . Reference Figure 6 The device 100 includes a determination unit 101 and a memory reclamation unit 102.

[0148] The determining unit 101 is used to determine the current running state of the application in the terminal, and to determine the current usage scenario of the terminal based on the current running state. It is also used to determine the capacity threshold based on the current usage scenario of the terminal and the mapping relationship. The mapping relationship is the mapping relationship between the usage scenario corresponding to the terminal and the capacity threshold. Different usage scenarios correspond to different capacity thresholds, and different running states correspond to different usage scenarios of the terminal.

[0149] The memory reclamation unit 102 is used to reclaim memory when the terminal's memory capacity is detected to meet the capacity threshold.

[0150] In some embodiments, the determining unit 101 determines the capacity threshold based on the usage scenario and the mapping relationship in the following manner: based on the usage scenario and the mapping relationship, it determines a first capacity threshold corresponding to the usage scenario and / or a second capacity threshold corresponding to the usage scenario; wherein, the first capacity threshold represents the capacity threshold that triggers memory reclamation, and the second threshold represents the capacity threshold that triggers the cessation of memory reclamation.

[0151] In some embodiments, the usage scenarios include: a first scenario and a second scenario, wherein the first scenario is a scenario in which the application is in a running state, and the second scenario is a scenario other than the first scenario; the determining unit 101 determines the capacity threshold in the following manner: when the usage scenario includes the first scenario, the first capacity threshold is determined to be M, and / or the second capacity threshold is determined to be N; when the usage scenario includes the second scenario, the first capacity threshold is determined to be P, and / or the second capacity threshold is determined to be Q; wherein M is greater than or equal to 0, N is greater than or equal to 0, P is greater than or equal to 0, Q is greater than or equal to 0, M is greater than or equal to P, and N is greater than or equal to Q.

[0152] In some embodiments, after determining the current usage scenario of the terminal, the determining unit 101 is further configured to: predict the usage scenario of the terminal at a future time based on the current usage scenario of the terminal and the historical information of the user's use of the terminal; the determining unit 101 is further configured to: determine the future capacity threshold at a future time based on the usage scenario at a future time and the mapping relationship; the memory reclamation unit 102 is further configured to: perform memory reclamation processing when it is detected that the remaining memory capacity of the terminal at a future time meets the requirements of the future capacity threshold.

[0153] In some embodiments, the determining unit 101 determines the current running state of the application in the terminal in the following manner: when a startup request corresponding to the application is detected, the current running state of the application is determined to be a startup state, wherein the usage scenario corresponding to the startup state is a first scenario; when a target window is detected to be removed from the terminal display interface, the current running state of the application is determined to be a non-startup state, wherein the usage scenario corresponding to the non-startup state is a second scenario, and the target window is a window that exists in the startup state of the application.

[0154] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operation has been described in detail in the embodiments related to the method, and will not be elaborated upon here.

[0155] Figure 7 This is a block diagram illustrating an electronic device according to an exemplary embodiment. The electronic device 200 can be provided as a terminal for performing a memory reclamation method. For example, the electronic device 200 can be a mobile phone, computer, digital broadcasting terminal, messaging device, game console, tablet device, medical device, fitness equipment, personal digital assistant, etc.

[0156] Reference Figure 7 The electronic device 200 may include one or more of the following components: processing component 202, memory 204, power component 206, multimedia component 208, audio component 210, input / output (I / O) interface 212, sensor component 214, and communication component 216.

[0157] Processing component 202 typically controls the overall operation of electronic device 200, such as operations associated with display, telephone calls, data communication, camera operation, and recording. Processing component 202 may include one or more processors 220 to execute instructions to perform all or part of the steps of the methods described above. Furthermore, processing component 202 may include one or more modules to facilitate interaction between processing component 202 and other components. For example, processing component 202 may include a multimedia module to facilitate interaction between multimedia component 208 and processing component 202.

[0158] Memory 204 is configured to store various types of data to support the operation of electronic device 200. Examples of such data include instructions for any application or method operating on electronic device 200, contact data, phonebook data, messages, pictures, videos, etc. Memory 204 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.

[0159] Power component 206 provides power to various components of electronic device 200. Power component 206 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to electronic device 200.

[0160] Multimedia component 208 includes a screen that provides an output interface between the electronic device 200 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touchscreen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensors may sense not only the boundaries of the touch or swipe action but also the duration and pressure associated with the touch or swipe operation. In some embodiments, multimedia component 208 includes a front-facing camera and / or a rear-facing camera. When the electronic device 200 is in an operating mode, such as a shooting mode or a video mode, the front-facing camera and / or the rear-facing camera may receive external multimedia data. Each front-facing camera and rear-facing camera may be a fixed optical lens system or have focal length and optical zoom capabilities.

[0161] Audio component 210 is configured to output and / or input audio signals. For example, audio component 210 includes a microphone (MIC) configured to receive external audio signals when electronic device 200 is in an operating mode, such as call mode, recording mode, and voice recognition mode. The received audio signals may be further stored in memory 204 or transmitted via communication component 216. In some embodiments, audio component 210 also includes a speaker for outputting audio signals.

[0162] I / O interface 212 provides an interface between processing component 202 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include, but are not limited to, home buttons, volume buttons, power buttons, and lock buttons.

[0163] Sensor assembly 214 includes one or more sensors for providing state assessments of various aspects of electronic device 200. For example, sensor assembly 214 can detect the on / off state of electronic device 200, the relative positioning of components such as the display and keypad of electronic device 200, changes in position of electronic device 200 or a component of electronic device 200, the presence or absence of user contact with electronic device 200, orientation or acceleration / deceleration of electronic device 200, and temperature changes of electronic device 200. Sensor assembly 214 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. Sensor assembly 214 may also include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, sensor assembly 214 may also include an accelerometer, gyroscope, magnetometer, pressure sensor, or temperature sensor.

[0164] Communication component 216 is configured to facilitate wired or wireless communication between electronic device 200 and other devices. Electronic device 200 can access wireless networks based on communication standards, such as WiFi, 2G, or 3G, or combinations thereof. In one exemplary embodiment, communication component 216 receives broadcast signals or broadcast-related information from an external broadcast management system via a broadcast channel. In one exemplary embodiment, communication component 216 also includes a near-field communication (NFC) module to facilitate short-range communication. For example, the NFC module may be implemented based on radio frequency identification (RFID) technology, Infrared Data Association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.

[0165] In an exemplary embodiment, the electronic device 200 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the methods described above.

[0166] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 204 including instructions, which can be executed by a processor 220 of an electronic device 200 to perform the above-described method. For example, the non-transitory computer-readable storage medium may be a ROM, random access memory (RAM), CD-ROM, magnetic tape, floppy disk, and optical data storage device, etc.

[0167] Figure 8This is a block diagram two illustrating a memory reclamation apparatus according to an exemplary embodiment. For example, apparatus 300 may be provided as a server. (Refer to...) Figure 8 The device 300 includes a processing component 322, which further includes one or more processors, and a memory resource represented by a memory 332 for storing instructions, such as application programs, that can be executed by the processing component 322. The application programs stored in the memory 332 may include one or more modules, each corresponding to a set of instructions.

[0168] Device 300 may also include a power supply component 326 configured to perform power management of device 300, a wired or wireless network interface 350 configured to connect device 300 to a network, and an input / output (I / O) interface 358. Device 300 may operate on an operating system stored in memory 332, such as Windows Server™, MacOSX™, Unix™, Linux™, FreeBSD™, or similar.

[0169] It is understood that in this disclosure, "multiple" refers to two or more, and other quantifiers are similar. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, and B alone. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. The singular forms "a," "the," and "the" are also intended to include the plural forms unless the context clearly indicates otherwise.

[0170] It is further understood that the terms "first," "second," etc., are used to describe various types of information, but this information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another, and do not indicate a specific order or degree of importance. In fact, the expressions "first," "second," etc., are completely interchangeable. For example, without departing from the scope of this disclosure, first information can also be referred to as second information, and similarly, second information can also be referred to as first information.

[0171] It is further understood that the terms “center,” “longitudinal,” “lateral,” “front,” “rear,” “up,” “down,” “left,” “right,” “vertical,” “horizontal,” “top,” “bottom,” “inner,” and “outer,” etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are only for the convenience of describing this embodiment and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation.

[0172] It can be further understood that, unless otherwise specified, "connection" includes both direct connections where no other components exist between the two parties and indirect connections where other components exist between them.

[0173] It is further understood that although operations are described in a specific order in the accompanying drawings in the embodiments of this disclosure, this should not be construed as requiring these operations to be performed in the specific order or serial order shown, or requiring all of the shown operations to be performed to obtain the desired result. In certain environments, multitasking and parallel processing may be advantageous.

[0174] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of the invention that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein.

[0175] It should be understood that this disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this disclosure is limited only by the appended claims.

Claims

1. A memory reclamation method, characterized in that, include: Determine the current running state of the application in the terminal, and determine the current usage scenario of the terminal based on the current running state, wherein different running states correspond to different usage scenarios of the terminal; Based on the current usage scenario and mapping relationship of the terminal, a capacity threshold is determined, wherein the target mapping relationship is the mapping relationship between the usage scenario corresponding to the terminal and the capacity threshold, and different usage scenarios correspond to different capacity thresholds; In response to the detection that the remaining memory capacity of the terminal meets the capacity threshold, memory reclamation is performed.

2. The method according to claim 1, characterized in that, The process of determining the capacity threshold based on the usage scenario and mapping relationship includes: Based on the usage scenario and the mapping relationship, determine the first capacity threshold corresponding to the usage scenario and / or the second capacity threshold corresponding to the usage scenario; Wherein, the first capacity threshold represents the capacity threshold that triggers memory reclamation, and the second capacity threshold represents the capacity threshold that triggers the cessation of memory reclamation.

3. The method according to claim 1 or 2, characterized in that, The usage scenarios include: a first scenario and a second scenario. The first scenario includes a scenario where the application is in a running state, and the second scenario includes other scenarios besides the first scenario. The determination of the capacity threshold includes: In response to the usage scenario being a first scenario, a first capacity threshold is determined to be M, and / or a second capacity threshold is determined to be N; In response to the usage scenario being the second scenario, a first capacity threshold is determined to be P, and / or a second capacity threshold is determined to be Q; Wherein, M is greater than or equal to 0, N is greater than or equal to 0, P is greater than or equal to 0, Q is greater than or equal to 0, M is greater than or equal to P, and N is greater than or equal to Q.

4. The method according to claim 1, characterized in that, After determining the current usage scenario of the terminal, the method further includes: Based on the current usage scenario of the terminal and the user's historical information on the terminal, predict the usage scenario of the terminal in the future. Based on the usage scenarios corresponding to the future time and the mapping relationship, determine the future capacity threshold corresponding to the future time; In response to the detection that the remaining memory capacity of the terminal at the future time meets the requirement of the future capacity threshold, memory reclamation is performed.

5. The method according to claim 1, characterized in that, Determining the current running state of the application in the terminal includes: In response to the detection of a startup request corresponding to the application, the current running state of the application is determined to be a startup state, wherein the usage scenario corresponding to the startup state is the first scenario; In response to the detection that the target window has been removed from the terminal display interface, it is determined that the current running state of the application is a non-starting state, wherein the usage scenario corresponding to the non-starting state is the second scenario, and the target window is the window that exists in the corresponding starting state of the application.

6. A memory reclamation device, characterized in that, include: The determining unit is used to determine the current running state of the application in the terminal, and to determine the current usage scenario of the terminal based on the current running state, and to determine the capacity threshold based on the current usage scenario of the terminal and the mapping relationship, wherein the mapping relationship is the mapping relationship between the usage scenario corresponding to the terminal and the capacity threshold, different usage scenarios correspond to different capacity thresholds, and different running states correspond to different usage scenarios of the terminal. The memory reclamation unit is used to reclaim memory when it is detected that the remaining memory capacity of the terminal meets the capacity threshold.

7. The apparatus according to claim 6, characterized in that, The determining unit determines the capacity threshold based on the usage scenario and mapping relationship in the following manner: Based on the usage scenario and the mapping relationship, determine the first capacity threshold corresponding to the usage scenario and / or the second capacity threshold corresponding to the usage scenario; Wherein, the first capacity threshold represents the capacity threshold that triggers memory reclamation, and the second threshold represents the capacity threshold that triggers the cessation of memory reclamation.

8. The apparatus according to claim 6 or 7, characterized in that, The usage scenarios include: a first scenario and a second scenario. The first scenario includes a scenario where the application is in a running state, and the second scenario includes other scenarios besides the first scenario. The determining unit determines the capacity threshold in the following manner: In the case where the usage scenario is the first scenario, the first capacity threshold is determined to be M, and / or the second capacity threshold is determined to be N; In the case where the usage scenario is the second scenario, the first capacity threshold is determined to be P, and / or the second capacity threshold is determined to be Q; Wherein, M is greater than or equal to 0, N is greater than or equal to 0, P is greater than or equal to 0, Q is greater than or equal to 0, M is greater than or equal to P, and N is greater than or equal to Q.

9. The apparatus according to claim 6, characterized in that, After determining the current usage scenario of the terminal, the determining unit is further configured to: Based on the current usage scenario of the terminal and the user's historical information on the terminal, predict the usage scenario of the terminal in the future. The determining unit is further configured to: determine the future capacity threshold corresponding to the future time based on the usage scenario corresponding to the future time and the mapping relationship; The memory reclamation unit is also used to: perform memory reclamation processing when it is detected that the remaining memory capacity of the terminal at the future time meets the requirements of the future capacity threshold.

10. The apparatus according to claim 6, characterized in that, The determining unit determines the current running state of the application in the terminal in the following manner: Upon detecting a startup request for an application, the current running state of the application is determined to be a startup state, wherein the usage scenario corresponding to the startup state is the first scenario; If the target window is detected to be removed from the terminal display interface, the current running state of the application is determined to be non-starting state. The usage scenario corresponding to the non-starting state is the second scenario, and the target window is the window that exists in the corresponding starting state of the application.

11. An electronic device, characterized in that, include: processor: Memory used to store processor-executable instructions; The processor is configured to execute the memory reclamation method according to any one of claims 1 to 5.

12. A storage medium, characterized in that, The storage medium stores instructions that, when executed by a processor, enable the processor to perform the memory reclamation method according to any one of claims 1 to 5.