Garbage recycling method and device, equipment and storage medium
By introducing multiple preset GC policies into the terminal device and dynamically selecting policies based on the instructions of the target application, the problem of insufficient flexibility of GC in the prior art is solved, and smoother resource usage and more efficient memory management are achieved.
Patent Information
- Application Number
- CN202411987361.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-04-25
AI Technical Summary
In the prior art, the garbage collection mechanism of Android virtual machines is insufficient in flexibility, resulting in excessive resource utilization in high-load scenarios, and failure to fully utilize early recycling operations when resources are abundant.
By introducing multiple preset GC policies into the terminal device and dynamically selecting and executing corresponding garbage collection policies based on the target instructions sent by the target application, the flexibility of GCs in the terminal device is improved.
It improves the flexibility of GC in terminal devices, makes resource use smoother, can provide the best memory recovery effect in different scenarios, avoids memory leakage or over-allocation, and ensures system performance and stability.
Smart Images

Figure CN119883948A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the technical field of terminal equipment, and relate to but are not limited to a garbage collection method and apparatus, equipment, and storage medium. Background Art
[0002] In the current related technology, the current Android virtual machine garbage collection (GC) is an instruction operation or a class instruction issuance operation, which is a preset, fixed-path method, especially in the virtual machine (Android Runtime, ART), which mainly relies on the garbage collection algorithm.
[0003] However, the method of performing GC in a fixed mode has poor flexibility. Therefore, how to improve the flexibility of GC in terminal devices is an urgent problem to be solved. Summary of the invention
[0004] In view of this, the garbage collection method, device, equipment, and storage medium provided in the embodiments of the present application can improve the flexibility of GC in terminal devices. The garbage collection method, device, equipment, and storage medium provided in the embodiments of the present application are implemented as follows:
[0005] The garbage collection method provided in an embodiment of the present application is applied to a terminal device, and the method includes: obtaining a target instruction sent by a target application, the target instruction including a target identifier; in response to the target instruction, performing garbage collection on the memory of the terminal device according to a target garbage collection GC strategy corresponding to the target identifier, the terminal device including multiple preset GC strategies, different preset GC strategies corresponding to different identifiers, and the multiple preset GC strategies including the target GC strategy.
[0006] The garbage collection device provided in the embodiment of the present application is applied to a terminal device, and the device includes: an acquisition module, used to acquire a target instruction sent by a target application, and the target instruction includes a target identifier; a processing module, used to respond to the target instruction and perform garbage collection on the memory of the terminal device according to a target garbage collection GC strategy corresponding to the target identifier, and the terminal device includes multiple preset GC strategies, different preset GC strategies correspond to different identifiers, and the multiple preset GC strategies include the target GC strategy.
[0007] The computer device provided in the embodiment of the present application includes a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the processor executes the program, the method described in the embodiment of the present application is implemented.
[0008] The computer-readable storage medium provided in the embodiment of the present application stores a computer program thereon, and when the computer program is executed by a processor, the method provided in the embodiment of the present application is implemented.
[0009] The computer program product provided in the embodiment of the present application includes a computer program, and when the computer program is executed by a processor, the method provided in the embodiment of the present application is implemented.
[0010] In the garbage collection method, apparatus, device, and storage medium provided in the embodiments of the present application, the terminal device first obtains the target instruction sent by the target application, and the target instruction includes a target identifier; then, in response to the target instruction, the terminal device's memory is garbage collected according to the target garbage collection GC policy corresponding to the target identifier, and the terminal device includes multiple preset GC policies, different preset GC policies correspond to different identifiers, and the multiple preset GC policies include a target GC policy. In the garbage collection method, by obtaining the target instruction sent by the target application, and then garbage collecting the terminal device's memory according to the target GC policy corresponding to the target identifier in the target instruction, the flexibility of the GC in the terminal device can be improved, making resource usage relatively smooth. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present application and are used together with the specification to illustrate the technical solution of the present application.
[0012] Figure 1 A schematic diagram of the system architecture of a terminal device provided for one embodiment of the present application;
[0013] Figure 2 A schematic diagram of the implementation process of a garbage collection method provided in one embodiment of the present application;
[0014] Figure 3 A schematic diagram of the implementation flow of a garbage collection method provided in another embodiment of the present application;
[0015] Figure 4 A schematic diagram of a process framework for setting a target identifier provided in one embodiment of the present application;
[0016] Figure 5 A schematic diagram of a garbage collection method according to another embodiment of the present invention;
[0017] Figure 6 A schematic diagram of the structure of the interaction between the target application and the AMSC provided in one embodiment of the present application;
[0018] Figure 7 A schematic diagram of the structure of the interaction between AMSC and ART provided in one embodiment of the present application;
[0019] Figure 8 A schematic diagram of the overall architecture of garbage collection provided for one embodiment of the present application;
[0020] Fig. 9 A structural schematic diagram of a garbage collection device provided by an embodiment of the present application;
[0021] Fig.10 A structural schematic diagram of a computer device provided for one embodiment of the present application. DETAILED DESCRIPTION
[0022] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the specific technical solution of the present application will be further described in detail below in conjunction with the drawings in the embodiments of the present application. The following embodiments are used to illustrate the present application, but are not used to limit the scope of the present application.
[0023] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0024] In the following description, reference is made to “some embodiments”, which describe a subset of all possible embodiments, but it will be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0025] It should be pointed out that the terms "first\second\third" involved in the embodiments of the present application are used to distinguish similar or different objects, and do not represent a specific ordering of the objects. It can be understood that "first\second\third" can be interchanged in a specific order or sequence where permitted, so that the embodiments of the present application described here can be implemented in an order other than that illustrated or described here.
[0026] In the current related technologies, garbage collection GC is an automatic memory management mechanism in modern programming languages, which aims to automatically clean up objects that are no longer in use, thereby releasing memory resources, avoiding memory leaks and improving the stability and performance of the program. The current Android virtual machine garbage collection GC is an instruction operation or a class instruction issuance operation, which is a preset, fixed-path method, especially in the virtual machine ART, which mainly relies on garbage collection algorithms such as Mark-Sweep, Copying and Generational Garbage Collection. These GC strategies are activated when the system memory pressure of the terminal device is high, and may not be recycled in advance when the memory is sufficient. It is usually automatically performed by the system based on the memory usage.
[0027] The GC collection strategy of Android Runtime (ART) mainly includes generational garbage collection (Generational GC), parallel collection and incremental garbage collection (Incremental GC). Among them, generational garbage collection is based on the "generational" theory, dividing the memory into different generations, such as the young generation (Young Generation) and the old generation (Old Generation). Most objects live in the young generation, and the GC of the young generation is more frequent, mainly recycling short-lived objects in the young generation; the objects in the old generation are longer-lived and the recycling cycle is longer, but if the memory occupancy of the old generation is too large, it will also trigger full garbage collection (Full GC). ART supports multi-threaded parallel garbage collection, which can improve the recycling efficiency on devices with multi-core central processing units (Central Processing Unit, CPU) and reduce the occupation of a single core by recycling. Incremental garbage collection is usually to avoid long-term jamming caused by a single GC. ART can perform garbage collection in stages and reduce the pause time of each GC in an incremental way.
[0028] However, the GC method using a fixed mode has poor flexibility, and this fixed logic may cause GC to occupy a large amount of resources in some high-load scenarios, while not fully utilizing the early recycling operation in scenarios with abundant resources.
[0029] Therefore, how to improve the flexibility of GC in terminal devices is an urgent problem to be solved.
[0030] In view of this, an embodiment of the present application provides a garbage collection method, which is applied to a terminal device, and the method specifically includes: obtaining a target instruction sent by a target application, wherein the target instruction includes a target identifier; then, in response to the target instruction, garbage collection is performed on the memory of the terminal device according to a target garbage collection GC policy corresponding to the target identifier, wherein the terminal device includes multiple preset GC policies, different preset GC policies correspond to different identifiers, and the multiple preset GC policies include a target GC policy. In the garbage collection method of the present application, by obtaining the target instruction sent by the target application, and then garbage collection is performed on the memory of the terminal device according to the target GC policy corresponding to the target identifier in the target instruction, the flexibility of the GC in the terminal device can be improved, making resource usage relatively smooth.
[0031] It should be understood that the terminal device involved in the embodiments of the present application may be a mobile phone, a tablet computer, a laptop computer, a PDA, a mobile internet device (MID), a wearable device, a virtual reality (VR) device, an augmented reality (AR) device, a smart screen, an artificial intelligence (AI) speaker, a headset, a terminal in industrial control, a terminal in self driving, a terminal in remote medical surgery, a terminal in a smart grid, a terminal in transportation safety, a terminal in a smart city, a terminal in a smart home, a personal digital assistant (PDA), etc., and the embodiments of the present application are not limited to this.
[0032] For example, Figure 1 A schematic diagram of the system architecture of a terminal device provided in one embodiment of the present application. Figure 1 As shown, the terminal device includes components such as a processor 110, a memory 120, a transceiver 130, a display unit 140, an input unit 150, and a power module 160.
[0033] The processor 110 is the control center of the terminal device, and uses various interfaces and lines to connect various parts of the entire terminal device. By running or executing software programs and / or modules stored in the memory 120, and calling data stored in the memory 120, the processor 110 performs various functions of the terminal device and processes data, thereby monitoring the terminal device as a whole. Optionally, the processor 110 may include one or more processing units; optionally, the processor 110 may integrate an application processor, which mainly processes operating devices, user interfaces, and application programs, etc. Of course, other processors may also be included, which are not listed here one by one.
[0034] The memory 120 can be used to store software programs and modules. The processor 110 executes various functional applications and data processing of the terminal device by running the software programs and modules stored in the memory 120. The memory 120 mainly includes a program storage area and a data storage area, wherein the program storage area can store operating devices, at least one application required for a function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the terminal device (such as audio data, a phone book, etc.), etc. In addition, the memory 120 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0035] The transceiver 130 can provide wireless communication solutions for terminal devices, including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc. The transceiver 130 can be one or more devices integrating at least one communication processing module, for example, an antenna and a baseband processor are integrated into the transceiver 130, or an antenna and a modem processor are integrated into the transceiver 130, etc., which are not limited here.
[0036] The display unit 140 can be used to display information input by the user or information provided to the user and various menus of the terminal device. The display unit 140 can be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), etc., which is not limited here.
[0037] The input unit 150 can be used to receive input digital or character information, and to generate key signal input related to the user settings and function control of the terminal device. Specifically, the input unit 150 can collect the user's operations on or near it, and drive the corresponding connection device according to a pre-set program. In addition, the input unit 150 may include a touch panel, which can be implemented in various types such as resistive, capacitive, infrared, and surface acoustic wave. In addition to the touch panel, the input unit 150 may also include other input devices. Specifically, other input devices may include, but are not limited to, one or more of function keys (such as volume control keys, switch keys, etc.), trackballs, joysticks, etc.
[0038] The terminal device also includes a power module 160 for supplying power to various components. Optionally, the power module 160 can be logically connected to the processor 110 through a power management device, so that functions such as charging, discharging, and power consumption management can be managed through the power management device.
[0039] Although not shown, the terminal device may further include a camera. Optionally, the camera may be located at the front or rear of the terminal device, which is not limited in the embodiment of the present application.
[0040] It is to be understood that the structure illustrated in the embodiments of the present application does not constitute a specific limitation on the terminal device. In other embodiments of the present application, the terminal device may include more or fewer components than shown in the figure, or combine certain components, or split certain components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0041] In order to make the purpose and technical solution of this application clearer and more intuitive, the garbage collection method, device, equipment, and storage medium provided in the embodiments of this application will be described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described here are only used to explain this application and are not used to limit this application.
[0042] Please refer to Figure 2 , is a schematic diagram of the implementation flow of a garbage collection method provided by an embodiment of the present application. The method can be applied to Figure 1 The terminal equipment shown, such as Figure 2 As shown, the method may include the following steps 201 and 202:
[0043] Step 201: Obtain a target instruction sent by a target application, wherein the target instruction includes a target identifier.
[0044] In some embodiments, the target application may be a preset application, service, or related resource monitoring program, etc., or the target application may be any program that requires garbage collection, or a service that relies on memory management, etc., which is not specifically limited in this application.
[0045] In some embodiments, the target identifier is typically used to identify the target GC strategy, which may be an ID, such as GC1, GC2, etc.; different GC strategies may be suitable for different scenarios, so through the target identifier, the target application can select a suitable GC strategy to optimize performance.
[0046] Optionally, the GC policy is used to manage memory recycling. In different situations, the system may need different GC policies. For example, the GC policy may be adjusted according to the current resource usage ratio of the target application. If the target application currently occupies a high amount of memory resources, it may choose to delay the execution of GC to avoid the impact of GC operations on performance. Some policies may be suitable for memory-sensitive scenarios, while others may be suitable for scenarios with high performance requirements, and so on.
[0047] Step 202, in response to the target instruction, garbage collection is performed on the memory of the terminal device according to a target garbage collection GC strategy corresponding to the target identifier, the terminal device includes multiple preset GC strategies, different preset GC strategies correspond to different identifiers, and the multiple preset GC strategies include the target GC strategy.
[0048] In some embodiments, after receiving the target instruction, the terminal device first identifies the target identifier in the target instruction, where the target identifier is used to identify one of multiple preset GC strategies and indicate which GC strategy the terminal device should apply to garbage memory.
[0049] In some embodiments, a plurality of different GC strategies may have been preset on the terminal device, and each strategy can be accessed through a different identifier. For example, there may be the following strategies: serial GC strategy, parallel GC strategy, and concurrent GC strategy. The serial GC strategy may be suitable for scenarios with limited resources or low memory environments, and the system will recycle memory through a single thread; the parallel GC strategy may be suitable for scenarios with high throughput, and the system may use multiple threads to recycle memory in parallel; the concurrent GC strategy may be suitable for scenarios with low latency requirements, and the system will perform garbage collection while the application is executing to minimize the pause time. Different GC strategies correspond to different identifiers. According to the identified target identifier, the system will select the corresponding GC strategy. For example, if the target identifier is GC1, the system will select the recycling strategy related to GC1.
[0050] In some embodiments, when garbage collection is performed, the memory of the terminal device will be checked to mark and recycle objects or memory blocks that are no longer in use, such as identifying all objects that are no longer in use, then clearing the no longer in use objects, freeing up memory space, and compressing the remaining valid memory when necessary to avoid memory fragmentation.
[0051] Optionally, after performing a GC operation on the memory of the terminal device, the terminal device may feed back the results of the garbage collection, such as the amount of memory recovered, the execution time, etc., to the control system or the target application, so that the system can adjust future GC strategies based on the feedback to ensure that memory management remains efficient under different load and resource conditions.
[0052] In this embodiment, the terminal device first obtains the target instruction sent by the target application, and the target instruction includes a target identifier; then, in response to the target instruction, the terminal device performs garbage collection on the memory according to the target GC policy corresponding to the target identifier, and the terminal device includes multiple preset GC policies, different preset GC policies correspond to different identifiers, and the multiple preset GC policies include the target GC policy. In this garbage collection method, by obtaining the target instruction sent by the target application, and then selecting the corresponding garbage collection policy according to the target identifier in the target instruction to perform garbage collection on the memory of the terminal device, in order to cope with different memory occupancy and performance requirements, the flexibility of GC in the terminal device can be improved, and the best memory recovery effect can be provided in different scenarios, so that resource usage is relatively smooth.
[0053] Based on the above embodiments, Figure 3 A schematic diagram of the implementation flow of a garbage collection method provided in another embodiment of the present application is shown in FIG. Figure 3 As shown, the method may include the following steps 301 to 304:
[0054] Step 301: Obtain a target instruction sent by a target application, wherein the target instruction includes a target identifier.
[0055] In some embodiments, the target application may be a preset application, service, or related resource monitoring program, etc., or the target application may be any program that requires garbage collection, or a service that relies on memory management, etc., which is not specifically limited in this application.
[0056] In some embodiments, the target identifier is typically used to identify the target GC strategy, which may be an ID, such as GC1, GC2, etc.; different GC strategies may be suitable for different scenarios, so through the target identifier, the target application can select a suitable GC strategy to optimize performance.
[0057] Optionally, the GC policy is used to manage memory recycling. In different situations, the system may need different GC policies. For example, the GC policy may be adjusted according to the current resource usage ratio of the target application. If the target application currently occupies a high amount of memory resources, it may choose to delay the execution of GC to avoid the impact of GC operations on performance. Some policies may be suitable for memory-sensitive scenarios, while others may be suitable for scenarios with high performance requirements, and so on.
[0058] Step 302, parse the target instruction to obtain the target identifier.
[0059] In some embodiments, after receiving the target instruction, the terminal device parses the target instruction, and the purpose of the parsing is to extract key information from the target instruction, especially the identification related to the GC strategy. The parsing process can be based on pattern matching, regular expressions, protocol parsing and other technologies.
[0060] Optionally, the target identifier is a key part in the target instruction, and usually corresponds to one of a plurality of preset GC strategies, and each identifier has a specific meaning, and is used to indicate which GC strategy the terminal device should apply for garbage collection.
[0061] In one possible implementation, the target instruction may include not only a target identifier corresponding to the GC strategy, but also other control parameters. For example, the instruction may include a parameter indicating the priority of the GC task, or may include a parameter indicating whether the GC needs to be delayed, such as delay: 5s; or other control information, such as whether the GC needs to be executed immediately, whether the memory is compressed, whether to perform incremental GC, etc. The parsing process is not only about extracting the target identifier, but also about checking these additional parameters and adjusting the behavior of the GC strategy based on them. For example, if a high priority is marked in the instruction, the system may give priority to GC operations to avoid affecting the real-time performance of the system. In this step, by accurately parsing the target instruction, the system can flexibly select the appropriate GC strategy according to different needs and effectively manage memory resources.
[0062] Step 303: Set the GC strategy for performing garbage collection to the target GC strategy corresponding to the target identifier.
[0063] In some embodiments, after parsing the target GC policy corresponding to the target identifier, the GC policy for performing garbage collection is set to the target GC policy. For example, assuming that the garbage collection operation is performed in ART, the ART is preset with relevant global variables, and after the terminal device parses the target identifier and the target GC policy corresponding to the target identifier, the target identifier related information is set to the global variable.
[0064] In a possible implementation, a target parameter in the configuration parameters corresponding to the target interface may be set according to the target identifier, the target interface is used to perform the garbage collection operation, and the target parameter is used to indicate a strategy for performing garbage collection.
[0065] For example, for ART, the Run interface of GC in ART is used to execute GC, and then the RunPhase function in the code is executed. Assuming that there are three GC strategies preset in ART, the corresponding identifiers of the three GC strategies are GC1, GC2 and GC3, that is, the GC identifier (GC_flag) is GC1, GC2 and GC3. After ART resolves the target identifier, it sets the target identifier to the global variable, which is equivalent to a "switch". Please refer to Figure 4 , which is a schematic diagram of a process framework for setting a target identifier according to an embodiment of the present application, such as Figure 4 As shown, after ART parses the target identifier, it first determines whether the target identifier is GC1. If the target identifier is GC1, GC1 is set in ART, that is, GC1 is set to the global variable, and then subsequent operations are performed; if the target identifier is not GC1, it is determined whether the target identifier is GC2. If the target identifier is GC2, GC2 is set in ART, that is, GC2 is set to the global variable, and then subsequent operations are performed; if the target identifier is not GC2, it is determined whether the target identifier is GC3. If the target identifier is GC3, GC3 is set in ART, that is, GC3 is set to the global variable, and then subsequent operations are performed; if the target identifier is not GC3, the default GC strategy is executed, such as executing the preset function RunPhase.
[0066] Optionally, the target GC strategy includes a delayed GC strategy or an early GC strategy, the target parameter includes a parameter in the configuration parameter corresponding to the task processing stage, and the garbage collection includes the task processing stage.
[0067] Among them, the delayed GC strategy refers to postponing the execution of garbage collection to the later stage of task processing, and triggering the GC operation only when the memory pressure reaches a certain threshold. This can reduce the impact of frequent garbage collection on task processing performance, especially when the memory demand is high in the task processing stage, to avoid GC interrupting the execution process of the task. It is mainly suitable for long-running processing tasks and memory-intensive applications. When the execution time of a task is long, you can wait until the task is close to completion before performing garbage collection to reduce the impact of mid-term collection on execution efficiency; if the application consumes a lot of memory, the GC operation may cause a pause, affecting processing performance. Delayed GC can avoid performing garbage collection during the peak period of the task. Specific implementation methods, such as delayed GC, usually control the timing of collection by setting specific memory thresholds, such as when the heap memory usage reaches a certain proportion, or time limits; or may choose to perform GC in the middle and late stages of the task, or set a dynamic threshold for memory usage, and only recycle when too much memory is used in the task processing stage.
[0068] The strategy of early GC refers to actively triggering garbage collection in the early stage of task execution to avoid performance bottlenecks caused by insufficient memory in the subsequent stage; the main purpose is to ensure sufficient resources for subsequent task processing by releasing memory in advance, avoiding bottlenecks caused by memory leaks or insufficient memory. It is suitable for tasks with high real-time requirements and short-time tasks. For example, in real-time or low-latency applications, early garbage collection can reduce processing delays when memory is tight in the later stage; for tasks with shorter time, if garbage collection is performed in advance, it can ensure smooth execution of tasks and avoid memory problems before the end of the task. For example, the specific implementation method usually determines in advance whether garbage collection needs to be performed based on the prediction algorithm or the execution status of the task. It may use information such as heap memory usage and memory occupancy growth trend to decide to perform garbage collection in the early stage of the task. By introducing the strategy of delayed GC and the strategy of early GC, combined with the parameter configuration of the specific task processing stage, garbage collection operations can be managed more finely, and the system's memory utilization and task processing efficiency can be optimized. For task-intensive and memory-intensive applications, reasonable GC strategy settings can significantly improve system performance and stability.
[0069] Optionally, the target GC strategy includes a strategy for performing GC according to priority, the target parameter includes a parameter in the configuration parameter corresponding to the running stage, and the garbage collection includes the running stage.
[0070] Among them, the strategy of GC according to priority is to ensure that the system's memory management can adapt to the memory requirements of different tasks during operation, thereby optimizing system performance and responsiveness. The target GC strategy involves the priorities of different tasks and the timing of memory recycling, while the target parameters are configuration items closely related to the running stage of the task, which determine the triggering conditions and timing of garbage collection. The strategy of GC according to priority mainly determines whether and when to perform garbage collection based on the different priorities of tasks during operation. High-priority tasks usually require lower latency and higher responsiveness, so the triggering of garbage collection will be different; low-priority tasks can tolerate longer pause times, and garbage collection may be delayed to optimize the execution of high-priority tasks. Target parameters refer to configuration items related to the running stage of the task in the GC strategy. These configuration items define the behavior and strategy of garbage collection, including memory thresholds, recycling timing, pause duration, etc. Different task stages have different memory requirements, so the relevant GC parameters should also be adjusted according to the needs of the stage. The GC strategy according to priority can ensure that high-priority tasks will not be interrupted by garbage collection operations, while low-priority tasks can tolerate longer GC delays. At the same time, the memory usage threshold, GC pause time and priority configuration parameters corresponding to the task running stage can effectively adjust the GC behavior and improve the system performance and memory utilization. By properly configuring these parameters, optimal memory management can be achieved at different task processing stages to ensure smooth and efficient execution of tasks.
[0071] Optionally, the garbage collection further includes a timing phase, where the timing phase is used to indicate a time period for performing garbage collection, and the target parameters include parameters corresponding to the timing phase.
[0072] Among them, the (GC) strategy in the scheduled phase refers to triggering garbage collection within a specific time period or periodically to ensure the efficiency of system memory management and avoid affecting system performance due to insufficient or excessive memory allocation. Scheduled GC is usually combined with the system's resource scheduling, load management, etc., and can clean up unused memory objects without affecting task execution. The core idea of scheduled GC is to schedule garbage collection operations based on time, rather than simply relying on memory usage thresholds. This strategy can perform garbage collection during periods when the system is idle or has a low load, avoiding unnecessary impact on ongoing tasks. In addition, scheduled GC is particularly important for real-time systems or high-priority tasks because it can control garbage collection operations to a time period that will not interfere with the execution of critical tasks.
[0073] In the scheduled GC strategy, multiple target parameters can also be involved. These parameters determine the execution time of the scheduled GC, the recycling intensity and its impact on system performance. The execution of scheduled GC is not only controlled by the system time, but also should be combined with the different stages of the task. In different scenarios such as high-priority tasks, batch tasks, and real-time tasks, the strategy and parameter settings of scheduled GC are different. Scheduled GC can be combined with the running stage of the task to ensure the efficient operation of the system and the smooth execution of the task.
[0074] In this step, set the corresponding garbage collection strategy according to the target identifier and adjust the relevant GC configuration as needed. After the setting is completed, the system will use these strategies for garbage collection to ensure that memory management and recycling operations meet the expected requirements.
[0075] Step 304: perform garbage collection on the memory.
[0076] In some embodiments, after setting the target parameters in the configuration parameters corresponding to the target interface according to the target identifier, the target interface can be called to perform garbage collection on the memory. For example, the Run interface of the GC in ART is called to perform garbage collection on the memory to release system resources.
[0077] Optionally, GC strategies are some strategies similar to scheduling and execution. For example, the delayed GC strategy is suitable for corresponding processing in task_process; the priority-based GC strategy can be used to increase or decrease the scheduling priority in the GC Run; the timing phase strategy can be used to customize a timing phase to limit the collection execution of that phase.
[0078] In this step, as the application runs, many objects may no longer be needed. Timely recycling of these objects can effectively prevent memory leaks and avoid memory resource exhaustion. At the same time, timely garbage collection can keep the system memory healthy and avoid too many useless objects occupying memory, resulting in insufficient resources being allocated for new operations.
[0079] In this embodiment, the terminal device first obtains the target instruction sent by the target application, and the target instruction includes a target identifier; then the target instruction is parsed to obtain the target identifier, and further, the GC strategy for garbage collection is set to the target GC strategy corresponding to the target identifier, and finally the memory is garbage collected. In this garbage collection method, by obtaining the target instruction sent by the target application, and then garbage collecting the memory of the terminal device according to the target GC strategy corresponding to the target identifier in the target instruction, the flexibility of the GC in the terminal device can be improved, so that the resource usage is relatively smooth; different garbage collection strategies are set according to different application requirements or tasks, and the terminal device can use memory resources more efficiently and reduce the impact of the garbage collection process on application performance; through flexible memory recovery, memory leakage or over-allocation is avoided, ensuring that memory resources are reasonably allocated, and avoiding application crashes or performance bottlenecks caused by insufficient memory; the garbage collection process may consume certain computing resources, especially when processing complex objects, and dynamically adjusting the GC strategy can reduce unnecessary calculations and optimize energy consumption; in addition, when the terminal device dynamically selects the GC strategy according to different tasks, memory fragmentation and invalid memory occupation can be avoided. For example, in large-scale data processing or high-concurrency scenarios, selecting strategies such as generational collection or incremental GC can effectively reduce memory fragmentation and maintain a high memory utilization rate. In summary, by dynamically adjusting the garbage collection strategy according to the target identifier, the terminal device can optimize the memory management strategy according to the characteristics and needs of different applications, which can not only improve the system performance and response speed of the terminal device, but also save energy and enhance the adaptability and stability of the device, especially in scenarios with multi-tasking, high real-time requirements or limited memory resources.
[0080] Based on the above embodiments, Figure 5 A schematic diagram of the implementation flow of a garbage collection method provided in another embodiment of the present application is shown in FIG. Figure 5 As shown, the method may include the following steps 501 to 505:
[0081] Step 501: Acquire a target instruction sent by a target application, wherein the target instruction includes a target identifier.
[0082] In some embodiments, the target application may be a preset application, service, or related resource monitoring program, etc., or the target application may be any program that requires garbage collection, or a service that relies on memory management, etc., which is not specifically limited in this application.
[0083] In some embodiments, the target identifier is typically used to identify the target GC strategy, which may be an ID, such as GC1, GC2, etc.; different GC strategies may be suitable for different scenarios, so through the target identifier, the target application can select a suitable GC strategy to optimize performance.
[0084] Optionally, the GC policy is used to manage memory recycling. In different situations, the system may need different GC policies. For example, the GC policy may be adjusted according to the current resource usage ratio of the target application. If the target application currently occupies a high amount of memory resources, it may choose to delay the execution of GC to avoid the impact of GC operations on performance. Some policies may be suitable for memory-sensitive scenarios, while others may be suitable for scenarios with high performance requirements, and so on.
[0085] In a possible implementation, assuming that the GC operation is performed in the virtual machine ART of the terminal device, the target application can interact with the service (ActivityManagerShellCommand, AMSC) through shell instructions, and then send the target instruction to AMSC, and AMSC sends the target instruction to ART, and accordingly, ART receives the target instruction. Among them, AMSC is located in the framework (frameworks, FWK), which can be understood as a class in the Android system for processing command line operations related to Activity Manager. For example, please refer to Figure 6 , which is a schematic diagram of the structure of the target application and the AMSC interaction provided by an embodiment of the present application, such as Figure 6 As shown, the target application can send a target command to the AMSC in a shell command manner.
[0086] Step 502 , in response to the target instruction, garbage collection is performed on the target memory according to the target GC policy, where the target memory is the memory corresponding to the target application identifier.
[0087] It should be noted that the target instruction also includes a target application identifier.
[0088] In some embodiments, after receiving the target instruction, the terminal device parses the target instruction to obtain the target application identifier and the target identifier corresponding to the target GC policy. The target application identifier is a unique identifier used to distinguish different applications or tasks. The system will identify the application or task that currently needs garbage collection based on the identifier; the target identifier is the identifier corresponding to the target GC policy. Each application may require a different memory management strategy, and the GC strategy will be adjusted according to these requirements.
[0089] In some embodiments, the terminal device identifies the target memory based on the target application identifier. The target memory is the memory space associated with the target application, which is usually the memory area used by the application when it is running. Different applications may have different memory allocation methods or memory usage patterns. Further, the terminal device can start garbage collection in the target memory area according to the selected target GC strategy. For example, the following steps may be included: first, mark all active objects in the target memory to determine which objects are still referenced; then delete all unmarked objects, that is, objects without active references; for some GC strategies, such as the mark-and-compact method, the memory after cleaning will be compressed to avoid memory fragmentation; finally, perform post-recycling optimization, such as by moving surviving objects to a specific area to improve memory allocation efficiency.
[0090] For example, in the above Figure 6 On the basis of the illustrated embodiment, after receiving the target instruction sent by the target application, AMSC can parse the target instruction, for example, use the onCommand interface to parse the target instruction, obtain the target application identifier and the target identifier corresponding to the target GC policy, the target application identifier can also be called the process identifier (pid), and the target identifier is GC_flag; then call the customized interface of the component (ActivityManagerService, AMS) to send the target application identifier and the target identifier to the virtual machine ART, for example, it can be sent to VMRuntime first, VMRuntime is mainly related to the memory management and performance tuning of ART, and provides a garbage collection control interface, allowing developers to control memory recycling more finely in the application. Further, the target instruction is transmitted to Runtime through VMRuntime, and Runtime is located in the native layer and is mainly used to perform GC operations. The advantages of using this transmission method are high versatility, low environmental restrictions, and strong real-time performance.
[0091] For example, please refer to Figure 7 , which is a schematic diagram of the structure of the interaction between AMSC and ART provided in one embodiment of the present application, such as Figure 7 As shown, AMSC calls AMS to send the target application identifier and target identifier in the parsed target instruction to ART, and then sets the corresponding parameters to the global variables of Heap in ART, and finally executes the corresponding GC operation in ART.
[0092] In this step, the terminal device responds to the target instruction, determines and selects the corresponding target memory and the corresponding GC strategy according to the target application identifier, and then performs garbage collection on the memory. Through this mechanism, the garbage collection strategy can be dynamically adjusted according to the needs of different applications, thereby improving the efficiency of memory management, optimizing system performance, and avoiding problems such as memory leaks or fragmentation.
[0093] Step 503: Obtain result data corresponding to garbage collection according to different preset GC strategies within a preset time period.
[0094] It should be understood that the preset time period refers to the garbage collection operation within a fixed time range, which can be a specific time window, such as every hour, every day, or a specific application running cycle; this time period is usually set based on the workload of the terminal device and the memory requirements of the application, and this application does not limit this.
[0095] In some embodiments, the terminal device includes multiple preset GC strategies. Within a preset time period, the terminal device will perform garbage collection on the target memory according to different GC strategies. For each strategy, the system will start the corresponding GC process and record key performance indicators during the process, such as memory release amount, pause time, CPU utilization, memory fragmentation, etc.; at the same time, the mobile phone GC result data can be collected after each garbage collection or each time the application task is completed. The GC result data refers to the performance indicators collected when performing garbage collection operations, which usually include the size of memory released after each garbage collection, the time the application is paused during the garbage collection process, the CPU resources consumed by the garbage collection operation, the allocation of memory after garbage collection, and the effective workload after garbage collection within a certain period of time, such as the number of requests processed, the number of tasks executed, etc. Through the analysis of these result data, the effects of different GC strategies can be evaluated, helping the system to optimize memory management, reduce performance bottlenecks, and improve the response speed and stability of applications.
[0096] Step 504, based on different preset GC strategies, result data and target preset learning models, obtain multiple updated preset GC strategies. The target preset learning model is obtained by training the initial learning model with multiple sample GC strategies within the sample time period and the sample result data corresponding to garbage collection according to the multiple sample GC strategies.
[0097] In some embodiments, the terminal device first trains an initial learning model based on multiple sample GC strategies within a sample time period and sample result data corresponding to garbage collection according to the multiple sample GC strategies to obtain a target preset learning model, wherein each sample GC strategy is a garbage collection strategy executed within a specific time period, and has corresponding garbage collection result data, such as memory release amount, pause time, CPU utilization, etc. Through the training process, the initial learning model will learn which GC strategies perform better under specific scenarios or loads, thereby providing a basis for subsequent decision-making. Furthermore, based on different preset GC strategies, result data, and target preset learning models, multiple updated preset GC strategies are obtained.
[0098] Step 505: Update multiple preset GC strategies according to the updated multiple preset GC strategies.
[0099] In some embodiments, the updated multiple preset GC strategies may be dynamically adjusted according to specific workloads. For example, in a light load environment, the system may prioritize incremental garbage collection strategies, while in a heavy load environment, it may select full garbage collection strategies. After each GC execution, the system will adjust the new GC strategy through a feedback mechanism to ensure that it can adapt to the current load and resource conditions.
[0100] Furthermore, the updated GC strategy needs to be further optimized through a continuous learning process. The terminal device can collect data from each garbage collection result and feed it back into the learning model, so that the GC strategy will become more intelligent and adaptable over time. Through continuous improvement and optimization through real-time feedback, the terminal device can always select the most appropriate GC strategy under different load and resource conditions, maximize resource utilization and minimize performance loss.
[0101] In this embodiment, the terminal device first obtains the target instruction sent by the target application, the target instruction includes a target identifier, and then responds to the target instruction to perform garbage collection on the target memory according to the target GC strategy, the target memory is the memory corresponding to the target application identifier, and further obtains the result data corresponding to the garbage collection according to different preset GC strategies within the preset time period, and obtains multiple updated preset GC strategies according to different preset GC strategies, result data and target preset learning models, and finally updates multiple preset GC strategies in the terminal according to the updated multiple preset GC strategies. By dynamically adjusting the GC strategy according to real-time feedback, the system can manage memory resources more accurately, avoid excessive memory recovery or incomplete recovery, and optimize memory usage efficiency. By selecting an appropriate GC strategy, the impact on the system during the garbage collection process can be effectively reduced. In addition, the update mechanism of the learning model enables the system to self-adjust during continuous operation and improve its performance. For example, if a specific strategy performs poorly in certain scenarios, the system can learn from the data and update the strategy to avoid similar problems from happening again, thereby improving the memory management capabilities of terminal devices in different application scenarios; by dynamically adjusting the GC strategy, it can not only improve memory recovery efficiency and reduce pauses, but also optimize the use of system resources, ultimately improving the overall performance, stability and user experience of terminal devices.
[0102] In a possible implementation manner, based on the above embodiment, it is assumed that the GC operation is performed in the virtual machine ART of the terminal device. Please refer to Figure 8 , is a schematic diagram of the overall architecture of garbage collection provided by an embodiment of the present application, such as Figure 8 As shown, the target application sends a target instruction to the AMSC, and the AMSC parses the target instruction to obtain a target identifier in the target instruction, namely, GC_flag. Further, the AMSC sends the parsed target instruction to the ART, and the ART receives the target instruction and further parses it to convert the target identifier into a corresponding determination setting switch. In the GC stage, GC operations of different strategies are performed according to different switches, such as garbage collection according to the GC1 strategy, or garbage collection according to the GC2 strategy, etc.
[0103] In the garbage collection method of this embodiment, the target application can set its preferred customized memory recovery strategy according to the application running requirements and execute it in ART, which can avoid the additional pressure on the load environment due to the resource consumption of GC itself to a certain extent, so that resource usage can be relatively smooth; it can also use the resources in the idle stage for recycling, thereby reducing the consumption in the program running stage to a certain extent and achieving the effect of faster execution; it can also release resources urgently in some scenarios to process higher priority instructions, thereby improving the flexibility of GC in terminal devices.
[0104] It should be understood that, although the steps in the above-mentioned flowcharts are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the above-mentioned flowcharts may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these sub-steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0105] Based on the foregoing embodiments, an embodiment of the present application provides a garbage collection device, which includes the modules included and the units included in the modules, which can be implemented by a processor; of course, it can also be implemented by a specific logic circuit; in the implementation process, the processor can be a central processing unit, a microprocessor, a digital signal processor or a field programmable gate array, etc.
[0106] Fig. 9 A structural schematic diagram of a garbage collection device provided by an embodiment of the present application is shown as follows: Fig. 9 As shown, the device 900 includes an acquisition module 901 and a processing module 902, wherein:
[0107] An acquisition module 901 is used to acquire a target instruction sent by a target application, wherein the target instruction includes a target identifier; a processing module 902 is used to respond to the target instruction and perform garbage collection on the memory of the terminal device according to a target garbage collection GC strategy corresponding to the target identifier, wherein the terminal device includes multiple preset GC strategies, different preset GC strategies correspond to different identifiers, and the multiple preset GC strategies include the target GC strategy.
[0108] In some embodiments, the processing module 902 is specifically used to: parse the target instruction to obtain the target identifier; set the GC policy for garbage collection to the target GC policy corresponding to the target identifier; and perform garbage collection on the memory.
[0109] In some embodiments, the garbage collection device further includes: a setting module. The setting module is used to set a target parameter in the configuration parameters corresponding to the target interface according to the target identifier, the target interface is used to perform the garbage collection operation, and the target parameter is used to indicate a strategy for performing garbage collection; the processing module 902 is specifically used to call the target interface to perform garbage collection on the memory.
[0110] In some embodiments, the target GC strategy includes a delayed GC strategy or an early GC strategy, the target parameters include parameters in the configuration parameters corresponding to the task processing stage, and the garbage collection includes the task processing stage.
[0111] In some embodiments, the target GC strategy includes a strategy for performing GC according to priority, the target parameters include parameters in the configuration parameters corresponding to the operating stage, and the garbage collection includes the operating stage.
[0112] In some embodiments, the garbage collection further includes a timing phase, where the timing phase is used to indicate a time period for performing the garbage collection, and the target parameter includes a parameter corresponding to the timing phase.
[0113] In some embodiments, the target instruction also includes a target application identifier, and the processing module 902 is specifically used to: respond to the target instruction, perform garbage collection on the target memory according to the target GC policy, and the target memory is the memory corresponding to the target application identifier.
[0114] In some embodiments, the garbage collection device further includes: an update module. The acquisition module 901 is also used to obtain the result data corresponding to garbage collection according to the different preset GC strategies within a preset time period; the processing module 902 is also used to obtain multiple updated preset GC strategies according to the different preset GC strategies, the result data and the target preset learning model, and the target preset learning model is obtained by training the initial learning model with multiple sample GC strategies within a sample time period and the sample result data corresponding to garbage collection according to the multiple sample GC strategies; the update module is used to update the multiple preset GC strategies according to the updated multiple preset GC strategies.
[0115] The description of the above device embodiment is similar to the description of the above method embodiment, and has similar beneficial effects as the method embodiment. For technical details not disclosed in the device embodiment of the present application, please refer to the description of the method embodiment of the present application for understanding.
[0116] It should be noted that in the embodiments of this application Fig. 9 The division of modules in the garbage collection device shown is schematic and is only a logical functional division. There may be other division methods in actual implementation. In addition, each functional unit in each embodiment of the present application may be integrated into a processing unit, or may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of a software functional unit. It may also be implemented in the form of a combination of software and hardware.
[0117] It should be noted that in the embodiment of the present application, if the above method is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the embodiment of the present application can be essentially or partly embodied in the form of a software product that contributes to the relevant technology. The computer software product is stored in a storage medium, including several instructions to enable an electronic device to execute all or part of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a U disk, a mobile hard disk, a read-only memory (ROM), a magnetic disk or an optical disk. In this way, the embodiment of the present application is not limited to any specific combination of hardware and software.
[0118] The embodiment of the present application provides a computer device, which may be a server, and its internal structure diagram may be as follows: Fig.10 As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, the above method is implemented.
[0119] An embodiment of the present application provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps in the method provided in the above embodiment are implemented.
[0120] An embodiment of the present application provides a computer program product including instructions, which, when executed on a computer, enables the computer to execute the steps of the method provided in the above method embodiment.
[0121] Those skilled in the art will understand that Fig.10 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0122] In one embodiment, the garbage collection device provided by the present application can be implemented in the form of a computer program. The computer program can be Fig.10The computer device shown in the figure can be run. The memory of the computer device can store various program modules constituting the above-mentioned device. The computer program composed of various program modules enables the processor to execute the steps of the method of each embodiment of the present application described in this specification.
[0123] It should be noted here that the description of the above storage medium and device embodiments is similar to the description of the above method embodiments, and has similar beneficial effects as the method embodiments. For technical details not disclosed in the storage medium, storage medium and device embodiments of this application, please refer to the description of the method embodiments of this application for understanding.
[0124] It should be understood that "one embodiment" or "an embodiment" or "some embodiments" mentioned throughout the specification means that specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present application. Therefore, "in one embodiment" or "in one embodiment" or "in some embodiments" appearing throughout the specification may not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. It should be understood that in various embodiments of the present application, the size of the sequence number of the above-mentioned processes does not mean the order of execution, and the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present application. The above-mentioned sequence numbers of the embodiments of the present application are only for description and do not represent the advantages and disadvantages of the embodiments. The above description of each embodiment tends to emphasize the differences between the various embodiments, and the same or similar aspects can be referenced to each other. For the sake of brevity, this article will not repeat them.
[0125] The term "and / or" in this article is only a description of the association relationship of associated objects, indicating that there may be three relationships. For example, object A and / or object B can represent three situations: object A exists alone, object A and object B exist at the same time, and object B exists alone.
[0126] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0127] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The embodiments described above are only schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation, such as: multiple modules or components can be combined, or can be integrated into another system, or some features can be ignored, or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of devices or modules can be electrical, mechanical or other forms.
[0128] The modules described above as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules; they may be located in one place or distributed on multiple network units; some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment.
[0129] In addition, all functional modules in the embodiments of the present application may be integrated into one processing unit, or each module may be a separate unit, or two or more modules may be integrated into one unit; the above-mentioned integrated modules may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0130] A person skilled in the art can understand that all or part of the steps of implementing the above method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above method embodiment; and the aforementioned storage medium includes: mobile storage devices, read-only memories (ROM), magnetic disks or optical disks, etc., various media that can store program codes.
[0131] Alternatively, if the above-mentioned integrated unit of the present application is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application can essentially or in other words, the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for enabling an electronic device to execute all or part of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROMs, magnetic disks, or optical disks.
[0132] The methods disclosed in several method embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments.
[0133] The features disclosed in several product embodiments provided in this application can be arbitrarily combined without conflict to obtain new product embodiments.
[0134] The features disclosed in several method or device embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments or device embodiments.
[0135] The above is only an implementation method of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A garbage collection method, characterized in that: Applied to a terminal device, the method comprises: Acquire a target instruction sent by a target application, wherein the target instruction includes a target identifier; In response to the target instruction, garbage collection is performed on the memory of the terminal device according to a target garbage collection GC strategy corresponding to the target identifier, the terminal device includes multiple preset GC strategies, different preset GC strategies correspond to different identifiers, and the multiple preset GC strategies include the target GC strategy.
2. The method according to claim 1, characterized in that: The step of performing garbage collection on the memory of the terminal device according to a target garbage collection GC strategy corresponding to the target identifier in response to the target instruction includes: Parsing the target instruction to obtain the target identifier; Setting the GC strategy for performing garbage collection to the target GC strategy corresponding to the target identifier; The memory is garbage collected.
3. The method according to claim 2, characterized in that The setting of the GC strategy for performing garbage collection to the target GC strategy corresponding to the target identifier includes: According to the target identifier, setting a target parameter in the configuration parameters corresponding to the target interface, the target interface is used to perform a garbage collection operation, and the target parameter is used to indicate a strategy for performing garbage collection; The performing garbage collection on the memory includes: The target interface is called to perform garbage collection on the memory.
4. The method according to claim 3, characterized in that: The target GC strategy includes a delayed GC strategy or an early GC strategy, the target parameters include parameters in the configuration parameters corresponding to the task processing stage, and the garbage collection includes the task processing stage.
5. The method according to claim 3, characterized in that: The target GC strategy includes a strategy for performing GC according to priority, the target parameters include parameters in the configuration parameters corresponding to the running stage, and the garbage collection includes the running stage.
6. The method according to claim 3, characterized in that: The garbage collection further includes a timing phase, where the timing phase is used to indicate a time period for performing the garbage collection, and the target parameters include parameters corresponding to the timing phase.
7. The method according to claim 1, characterized in that The target instruction further includes a target application identifier, and in response to the target instruction, garbage collection is performed on the memory of the terminal device according to a target garbage collection GC strategy corresponding to the target identifier, including: In response to the target instruction, garbage collection is performed on a target memory according to the target GC policy, the target memory being the memory corresponding to the target application identifier.
8. The method according to claim 1, characterized in that The method further comprises: Obtaining result data corresponding to garbage collection according to the different preset GC strategies within a preset time period; According to the different preset GC strategies, the result data and the target preset learning model, a plurality of updated preset GC strategies are obtained, wherein the target preset learning model is obtained by training an initial learning model with a plurality of sample GC strategies within a sample time period and sample result data corresponding to garbage collection performed according to the plurality of sample GC strategies; The multiple preset GC strategies are updated according to the updated multiple preset GC strategies.
9. A garbage collection device, characterized in that: Applied to a terminal device, the device comprises: An acquisition module, used for acquiring a target instruction sent by a target application, wherein the target instruction includes a target identifier; A processing module is used to respond to the target instruction and perform garbage collection on the memory of the terminal device according to a target garbage collection GC strategy corresponding to the target identifier, the terminal device includes multiple preset GC strategies, different preset GC strategies correspond to different identifiers, and the multiple preset GC strategies include the target GC strategy.
10. A computer device comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, characterized in that: When the processor executes the program, the steps of the method according to any one of claims 1 to 8 are implemented.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.
Citation Information
Cited By
Garbage collection test method and device, electronic equipment and storage medium
CN120653205A
Memory chip testing method and device and electronic equipment
CN120932713A