Garbage collection method and system based on machine learning and related device

By using a machine learning-based garbage collection method, feature vectors are generated from real-time terminal data. The garbage collection parameters are dynamically adjusted using a predictive model, which solves the problem of inaccurate timing in traditional garbage collection strategies and improves the smoothness of the application and the user experience.

CN122086586APending Publication Date: 2026-05-26SHENZHEN XINGUODU TECH
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SHENZHEN XINGUODU TECH
Filing Date
2025-12-11
Publication Date
2026-05-26

AI Technical Summary

Technical Problem

Traditional reactive garbage collection strategies cannot flexibly adjust garbage collection trigger nodes in scenarios with increasing complexity and performance requirements, resulting in lag and response delays, which affect user experience.

Method used

A machine learning-based garbage collection method is adopted. By collecting terminal operation data to generate structured feature vectors, a preset machine learning model is used to predict the free window and memory pressure trend, the parameter configuration of the garbage collection mechanism is dynamically adjusted, and a preset garbage collection scheduler is used to trigger garbage collection within the free window.

Benefits of technology

It has enabled the transformation of garbage collection from passive response to proactive prediction, avoiding conflicts between garbage collection and user operations, optimizing memory reclamation intensity, and improving application smoothness and user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122086586A_ABST
    Figure CN122086586A_ABST
Patent Text Reader

Abstract

The invention discloses a garbage collection method and system based on machine learning and a related device, which are used for avoiding the problems of lagging and response delay caused by misalignment of time in traditional reactive garbage collection. The garbage collection method comprises the steps that multi-dimensional data generated when a terminal runs are collected, feature engineering processing is conducted on the multi-dimensional data, a structured feature vector is generated, and the multi-dimensional data comprise the memory allocation rate, object life cycle statistics, user interaction operation, the heap memory state and application context information; inputting the structured feature vector into a preset machine learning model, and predicting an idle window and a memory pressure trend of the terminal through the preset machine learning model; and based on the idle window and the memory pressure trend, utilizing a preset garbage collection scheduler to trigger a garbage collection mechanism in the idle window, and dynamically adjusting parameter configuration of the garbage collection mechanism.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of applied technology, and in particular to a machine learning-based garbage collection method, system, and related apparatus. Background Technology

[0002] With the acceleration of digitalization and the widespread adoption of smart terminals, applications are rapidly iterating towards multi-functionality and high interactivity. From complex mobile games and real-time video editing software to high-frequency interactive financial trading apps and cloud-based collaborative office platforms, users have increasingly stringent requirements for application responsiveness and smoothness. These applications frequently create and release a large number of memory objects during operation, such as scene models in games, frame data in video editing, and real-time data streams in financial trading. If memory management efficiency is low, it can easily lead to memory leaks or performance fluctuations. Garbage collection (GC), as the main means of automatic memory management, directly determines the stability of terminal operation and user experience.

[0003] In existing technologies, garbage collection (GC) is typically implemented using traditional reactive strategies. Specifically, the GC process is initiated through two main triggering mechanisms: one is based on static threshold triggering, which presets a fixed memory threshold based on historical memory usage data. Once the memory usage reaches the preset fixed memory threshold, some application threads are immediately paused, and garbage collection (GC) is initiated; the other is based on allocation failure triggering, which passively triggers garbage collection (GC) when the creation of a new object fails due to insufficient memory, forcibly reclaiming unused memory space.

[0004] However, using this traditional reactive strategy, whether based on static threshold triggering or allocation failure triggering, cannot flexibly adjust the garbage collection (GC) triggering node in scenarios with increased application complexity and performance requirements. This causes the timing of garbage collection (GC) execution to conflict with the critical path of user operations, resulting in perceptible lag and response delay, which seriously affects the user experience. Summary of the Invention

[0005] To address the aforementioned technical problems, this application provides a machine learning-based garbage collection method, system, and related apparatus.

[0006] The technical solution provided in this application is described below: The first aspect of this application provides a garbage collection method based on machine learning, the garbage collection method comprising: Collect multi-dimensional data during terminal operation and perform feature engineering processing on the multi-dimensional data to generate structured feature vectors. The multi-dimensional data includes memory allocation rate, object lifecycle statistics, user interaction operations, heap memory status, and application context information. The structured feature vector is input into a preset machine learning model, and the preset machine learning model is used to predict the idle window and memory pressure trend of the terminal. Based on the free window and the memory pressure trend, a preset garbage collection scheduler is used to trigger the garbage collection mechanism within the free window, and the parameter configuration of the garbage collection mechanism is dynamically adjusted.

[0007] Optionally, the preset machine learning model includes a preset time-series prediction model and a preset classification model; The step of predicting the terminal's idle window and memory pressure trends using the preset machine learning model includes: The memory pressure trend of the structured feature vector is predicted using the preset time-series prediction model. The idle window of the terminal is obtained by identifying the idle features in the structured feature vector through the preset classification model.

[0008] Optionally, the dynamic adjustment of the parameters of the waste collection mechanism includes: The target application scenario is identified from the structured feature vector by the preset machine learning model, wherein the target application scenario includes instantaneous high load scenario, stable interaction scenario, background task scenario and application startup scenario; The parameters of the waste recycling mechanism are dynamically adjusted based on the target application scenario.

[0009] Optionally, the step of dynamically adjusting the parameter configuration of the garbage collection mechanism based on the target application scenario includes: When the target application scenario is the instantaneous high-load scenario, the capacity of the young generation memory of the terminal is increased, and the thread scheduling priority in the garbage collection mechanism is improved. When the target application scenario is the stable interaction scenario, the garbage collection mechanism is restricted to be executed during user interaction intervals, and the threshold of the old generation memory of the terminal is increased; When the target application scenario is the background task scenario, the execution interval of the garbage collection mechanism is extended and the CPU priority of the garbage collection mechanism is reduced; When the target application scenario is the application startup scenario, adjust the heap memory size in the terminal and perform garbage collection on the young generation memory.

[0010] Optionally, before triggering the garbage collection mechanism within the idle window using a preset garbage collection scheduler, the garbage collection method further includes: Detect whether there are high-priority temporary tasks in the terminal; If not, then execute the step of triggering the garbage collection mechanism within the idle window using the preset garbage collection scheduler; If so, the current free window is abandoned, and the remaining free window is recorded after the high-priority temporary task is completed.

[0011] Optionally, after recording the remaining free window, the garbage collection method further includes: Determine whether the garbage collection mechanism can be executed within the remaining free window; If not, the execution data of the high-priority temporary task is collected and sent to the preset machine learning model for learning, so as to optimize the next prediction of the preset machine learning model.

[0012] Optionally, after dynamically adjusting the parameter configuration of the garbage collection mechanism, the garbage collection method further includes: The preset machine learning model is optimized; The optimization of the preset machine learning model includes: Collect the effect data and status data of the terminal after the garbage collection mechanism is executed, and construct optimized training samples based on the effect data and status data; Based on the optimized training samples, the weight ratios and parameter configurations of the preset machine learning model are updated using an online gradient descent algorithm or a reinforcement learning algorithm.

[0013] A second aspect of this application provides a machine learning-based garbage collection system, the garbage collection system comprising: The generation unit is used to collect multi-dimensional data during terminal operation and perform feature engineering processing on the multi-dimensional data to generate structured feature vectors. The multi-dimensional data includes memory allocation rate, object lifecycle statistics, user interaction operations, heap memory status, and application context information. The prediction unit is used to input the structured feature vector into a preset machine learning model, and predict the idle window and memory pressure trend of the terminal through the preset machine learning model; The adjustment unit is used to trigger the garbage collection mechanism within the free window based on the free window and the memory pressure trend, using a preset garbage collection scheduler, and dynamically adjust the parameter configuration of the garbage collection mechanism.

[0014] Optionally, the preset machine learning model includes a preset time-series prediction model and a preset classification model; The step of predicting the terminal's idle window and memory pressure trends using the preset machine learning model includes: The memory pressure trend of the structured feature vector is predicted using the preset time-series prediction model. The idle window of the terminal is obtained by identifying the idle features in the structured feature vector through the preset classification model.

[0015] Optionally, the adjustment unit is specifically used for: The target application scenario is identified from the structured feature vector by the preset machine learning model, wherein the target application scenario includes instantaneous high load scenario, stable interaction scenario, background task scenario and application startup scenario; The parameters of the waste recycling mechanism are dynamically adjusted based on the target application scenario.

[0016] Optionally, the adjustment unit is specifically used for: When the target application scenario is the instantaneous high-load scenario, the capacity of the young generation memory of the terminal is increased, and the thread scheduling priority in the garbage collection mechanism is improved. When the target application scenario is the stable interaction scenario, the garbage collection mechanism is restricted to be executed during user interaction intervals, and the threshold of the old generation memory of the terminal is increased; When the target application scenario is the background task scenario, the execution interval of the garbage collection mechanism is extended and the CPU priority of the garbage collection mechanism is reduced; When the target application scenario is the application startup scenario, adjust the heap memory size in the terminal and perform garbage collection on the young generation memory.

[0017] Optionally, a detection unit may also be included, specifically for: Detect whether there are high-priority temporary tasks in the terminal; If not, then execute the step of triggering the garbage collection mechanism within the idle window using the preset garbage collection scheduler; If so, the current free window is abandoned, and the remaining free window is recorded after the high-priority temporary task is completed.

[0018] Optionally, a judgment unit may also be included, specifically used for: Determine whether the garbage collection mechanism can be executed within the remaining free window; If not, the execution data of the high-priority temporary task is collected and sent to the preset machine learning model for learning, so as to optimize the next prediction of the preset machine learning model.

[0019] Optionally, an optimization unit may also be included, specifically for: The preset machine learning model is optimized; The optimization of the preset machine learning model includes: Collect the effect data and status data of the terminal after the garbage collection mechanism is executed, and construct optimized training samples based on the effect data and status data; Based on the optimized training samples, the weight ratios and parameter configurations of the preset machine learning model are updated using an online gradient descent algorithm or a reinforcement learning algorithm.

[0020] A third aspect of this application provides a machine learning-based waste recycling device, the waste recycling device comprising: Processor, memory, input / output units, and bus; The processor is connected to the memory, the input / output unit, and the bus; The memory stores a program, which the processor invokes to execute the first aspect and any one of the optional garbage collection methods in the first aspect.

[0021] The fourth aspect of this application provides a computer-readable storage medium on which a program is stored, which, when executed on a computer, performs the first aspect and any optional garbage collection method of the first aspect.

[0022] As can be seen from the above technical solutions, the embodiments of this application have the following advantages: This application fundamentally transforms garbage collection from a passive response to an active prediction model by introducing a pre-defined machine learning prediction model and a garbage collection scheduler, effectively solving the stuttering and response delay problems caused by inaccurate timing in traditional reactive garbage collection. First, it collects multi-dimensional data in real time, including memory allocation processes, object lifecycle statistics, and user interactions during terminal runtime. This data is then processed through feature engineering to generate structured feature vectors, breaking away from the traditional strategy's reliance on a single memory threshold as a judgment dimension, and providing comprehensive data support for accurate prediction. Next, the structured feature vectors are input into the pre-defined machine learning model to predict the terminal's free window and memory pressure trends. Replacing the traditional passive mode, this model can predict memory needs and user operation rhythms in advance, accurately identifying garbage collection timings that will not interfere with the user's critical path. Finally, the pre-defined garbage collection scheduler triggers the garbage collection mechanism within the free window and dynamically adjusts garbage collection parameters. This avoids conflicts between garbage collection and user operations and optimizes the collection intensity based on memory pressure trends, preventing allocation failures due to insufficient memory. The entire solution optimizes passive garbage collection into active predictive garbage collection, significantly improving application smoothness and user experience, and meeting the performance requirements of highly complex and highly interactive scenarios. Attached Figure Description

[0023] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0024] Figure 1 A schematic flowchart of an embodiment of the machine learning-based garbage collection method provided in this application; Figure 2 A schematic flowchart of another embodiment of the machine learning-based garbage collection method provided in this application; Figure 3 A schematic flowchart illustrating an embodiment of the process by which the garbage collection mechanism's parameter configuration is dynamically adjusted according to different target application scenarios in the machine learning-based garbage collection method provided in this application; Figure 4 A schematic flowchart of an embodiment of the process for detecting the existence of high-priority temporary tasks in the machine learning-based garbage collection method provided in this application; Figure 5 A schematic diagram of an embodiment of the machine learning-based garbage collection system provided in this application; Figure 6 A schematic diagram of an embodiment of the machine learning-based waste recycling device provided in this application. Detailed Implementation

[0025] This application provides a machine learning-based garbage collection method that avoids the stuttering and response delays caused by inaccurate timing in traditional reactive garbage collection. It should be noted that this machine learning-based garbage collection method is applied to a terminal application.

[0026] It should be noted that the machine learning-based garbage collection method provided in this application can be applied to terminals, systems, and servers. For example, a terminal can be a smartphone, computer, tablet, smart TV, smartwatch, portable computer, or a desktop computer, etc. For ease of explanation, this application uses a terminal as the implementation subject for illustration.

[0027] Please see Figure 1 This application first provides an embodiment of a machine learning-based garbage collection method, which includes: S101. Collect multi-dimensional data during terminal operation and perform feature engineering processing on the multi-dimensional data to generate structured feature vectors. The multi-dimensional data includes memory allocation rate, object lifecycle statistics, user interaction operations, heap memory status, and application context information. In this embodiment, multi-dimensional data from the terminal runtime is collected and processed through feature engineering to generate structured feature vectors. This multi-dimensional data includes memory allocation rate, object lifecycle statistics, user interaction operations, heap memory status, and application context information. Specifically, the memory allocation rate is obtained by recording the frequency of memory requests, the size of a single allocation block, and the number of allocation failures per unit time in real time through the terminal interface, forming time-series data. Object lifecycle statistics are obtained by tracking the creation time, reference status, and destruction time of each memory object, calculating indicators such as the proportion of short-term temporary objects and the retention rate of long-term surviving objects. User interaction operations are generated by listening to user clicks, swipes, and inputs at the application layer, recording the operation time, operation type, and operation interval. Heap memory status is generated by collecting the total heap memory capacity, used capacity, free capacity, and memory fragmentation rate. Application context information is generated by recording the currently running modules, process priorities, and the number of other background applications.

[0028] To address the issues of inconsistent formats and redundancy in the collected multi-dimensional data, feature engineering was performed on the data simultaneously with data collection. For example, memory allocation rate was converted into a fixed-dimensional feature by calculating the average and maximum values ​​using a sliding window method; user operation types were converted into numerical features using one-hot encoding. Finally, the processed features were combined sequentially to generate a fixed-length structured feature vector, which provides standardized input for subsequent model predictions.

[0029] It is important to note that the collected multi-dimensional data will be cleaned before feature engineering, such as removing outliers and standardizing the data.

[0030] S102. Input the structured feature vector into the preset machine learning model, and predict the terminal's idle window and memory pressure trend through the preset machine learning model; In this embodiment, structured feature vectors are input into a pre-defined machine learning model to predict the terminal's idle window and memory pressure trends. First, the generated structured feature vectors are input according to the format required by the pre-defined machine learning model, which has been trained using historical operational data from a large number of different terminals and application scenarios. Then, the pre-defined machine learning model performs feature importance analysis on the structured feature vectors, selecting the features that have the greatest impact on the idle window and memory pressure trends for prediction. After prediction, the pre-defined machine learning model outputs the time information of the idle window and the memory pressure trend as the data basis for subsequent steps.

[0031] Specifically, for idle window prediction, the preset machine learning model analyzes the characteristics of user interaction operations and application context information to identify time periods of inactivity or low-frequency user operations. For example, if the user operation interval in the structured feature vector is greater than 3 seconds and the application is loading a module in the background, the preset machine learning model will determine this time period as an idle window and output the start time and duration of the idle window. For memory pressure trend prediction, the preset machine learning model combines the characteristics of memory allocation rate, heap memory status, and object lifecycle to predict memory changes over a future period. For example, if the memory allocation rate in the structured feature vector continues to rise, the heap memory utilization rate has reached 70%, and the proportion of long-term objects is low, the preset machine learning model will predict that the memory pressure will exceed the critical value after 3 minutes, indicating a high-pressure trend.

[0032] S103. Based on the free window and memory pressure trend, the garbage collection mechanism is triggered within the free window using a preset garbage collection scheduler, and the parameter configuration of the garbage collection mechanism is dynamically adjusted.

[0033] In this embodiment, a preset garbage collection scheduler dynamically adjusts the garbage collection mechanism's parameter configuration based on memory pressure trends within a predicted free window. If the pressure trend is high, high-intensity collection parameters are used, such as initiating multi-threaded parallel scanning of memory objects to increase the scan rate, prioritizing the collection of objects idle for more than 30 seconds, and compressing memory fragments to maximize memory space release. If the pressure trend is medium, medium-intensity parameters are used, such as initiating two-threaded scanning with a scan rate reduced to 50MB per second, only collecting objects idle for more than 1 minute. If the pressure trend is low, low-intensity parameters are used, such as single-threaded low-speed scanning, only collecting objects confirmed to be unreferenced, reducing system resource consumption.

[0034] During the recycling process, a pre-set garbage collection scheduler receives real-time feedback on memory status. If the actual memory pressure is found to be lower than the predicted memory pressure trend, for example, if the pressure is relieved after recycling 10% of the memory under a high pressure trend, the recycling intensity is dynamically reduced. If the actual memory pressure is found to be higher than the predicted memory pressure trend, the recycling intensity is appropriately increased.

[0035] This embodiment fundamentally transforms garbage collection from a passive response to an active prediction model by introducing a pre-set machine learning prediction model and a garbage collection scheduler. This effectively solves the stuttering and response delay problems caused by inaccurate timing in traditional reactive garbage collection. First, it collects multi-dimensional data in real time, including memory allocation processes, object lifecycle statistics, and user interactions during terminal operation. This data is then processed through feature engineering to generate structured feature vectors, breaking away from the traditional strategy's reliance on a single memory threshold and providing comprehensive data support for accurate prediction. Next, the structured feature vectors are input into the pre-set machine learning model to predict the terminal's free window and memory pressure trends. Replacing the traditional passive mode, this model can anticipate memory needs and user operation rhythms, accurately identifying garbage collection timings that will not interfere with the user's critical path. Finally, the pre-set garbage collection scheduler triggers the garbage collection mechanism within the free window and dynamically adjusts garbage collection parameters. This avoids conflicts between garbage collection and user operations and optimizes the collection intensity based on memory pressure trends, preventing allocation failures due to insufficient memory. The entire solution optimizes passive garbage collection into proactive predictive garbage collection, significantly improving application smoothness and user experience, and meeting the performance requirements of highly complex and interactive scenarios.

[0036] Please see Figure 2 This application also provides another embodiment of a machine learning-based garbage collection method, which includes: S201. Collect multi-dimensional data during terminal operation and perform feature engineering on the multi-dimensional data to generate structured feature vectors. The multi-dimensional data includes memory allocation rate, object lifecycle statistics, user interaction operations, heap memory status, and application context information. In this embodiment, step S201 is similar to step S101 in the previous embodiment, and will not be described again here.

[0037] S202. Input the structured feature vector into the preset machine learning model, which includes a preset time series prediction model and a preset classification model. In this embodiment, the structured feature vectors are input into a preset machine learning model, which includes a preset time-series prediction model and a preset classification model. Specifically, the preset time-series prediction model excels at analyzing time-series data and capturing memory change trends; the preset classification model is suitable for identifying scenes and states. This dual-model collaboration avoids the accuracy degradation that occurs when a single model simultaneously handles trend prediction and state recognition, and combining the two makes predictions more targeted.

[0038] Furthermore, the generated structured feature vectors are processed according to the input formats of the preset temporal prediction model and the preset classification model to ensure that the dimensions of the structured feature vectors match the input layers of the preset temporal prediction model and the preset classification model. Subsequently, the structured feature vectors flow to the preset temporal prediction model and the preset classification model, respectively. For example, time-related memory allocation rate and heap memory status time-series data are input to the preset temporal prediction model to predict memory pressure trends; status features related to user interaction operations and application context information are input to the preset classification model to identify idle windows and application scenarios. Both the preset temporal prediction model and the preset classification model prioritize feature selection, retaining key features that have a significant impact on the prediction results, reducing redundant data interference, and ensuring efficient and accurate prediction.

[0039] S203. Predict the memory pressure trend of structured feature vectors using a preset time-series prediction model; In this embodiment, predicting the memory pressure trend of the structured feature vector requires first calling pre-trained parameters through a preset time-series prediction model. This model has learned memory change patterns through a large amount of historical time-series data and can identify periodic, phased, and correlated patterns. Subsequently, time-related features from the structured feature vector are input into the preset time-series prediction model, such as the average memory allocation over the past 10 seconds, the rate of change in heap memory utilization, and the time distribution of short-term object proportions. The preset time-series prediction model analyzes the temporal correlation of these features through a multi-layer network structure. For example, when features show a continuously rising memory allocation rate, a heap memory utilization rate of 70% that is still increasing, and a short-term object proportion of 80%, the preset time-series prediction model, based on historical similar patterns, predicts a high-pressure trend in memory pressure within the next 500ms; when the structured feature vector shows a smooth memory allocation and sufficient free memory, it predicts a low-pressure trend.

[0040] By using a time-series prediction model, the memory pressure trend can be predicted in advance. Compared with the traditional solution that only reclaims memory when it is fully loaded, this embodiment can predict the pressure trend 300ms-500ms in advance. If high pressure is predicted, memory can be reclaimed in advance during the idle window to avoid application lag or crash due to insufficient memory.

[0041] S204. Identify the idle features in the structured feature vector using a preset classification model to obtain the idle window of the terminal.

[0042] In this embodiment, the preset classification model has learned the correspondence between idle features and idle windows through historical data. For example, when the idle feature is that the user operation interval is >3 seconds and the application is loading in the background, it is an idle window.

[0043] The idle features from the structured feature vector are input into a pre-defined classification model. These features include user touch idle duration, whether the application is in a non-interactive module, and the current operation type encoding. The pre-defined classification model then compares these idle features with its own idle feature pattern library. For example, if the features indicate a 5-second user operation interval, the application being in a non-interactive video loading module, or no high-frequency operations, the pre-defined classification model defines this time period as an idle window and outputs its start time and duration. If the idle features indicate that the user clicks twice per second or the application is in a high-frequency game / battle module, then there is no idle window. This solves the problem of not being able to predict the user's operation rhythm and avoids interference caused by random triggering of the idle window.

[0044] S205. Based on the free window and memory pressure trend, the garbage collection mechanism is triggered within the free window using a preset garbage collection scheduler. In this embodiment, step S205 is similar to step S103 in the previous embodiment, and will not be described again here.

[0045] S206. Identify target application scenarios from structured feature vectors using a preset machine learning model, where target application scenarios include instantaneous high load scenarios, stable interaction scenarios, background task scenarios, and application startup scenarios. Since different application scenarios have different performance requirements, this embodiment will identify the target application scenario to provide a basis for subsequent dynamic adjustment of parameters.

[0046] Specifically, the system primarily identifies target application scenarios from structured feature vectors using a pre-defined machine learning model. These scenarios include instantaneous high-load scenarios, stable interaction scenarios, background task scenarios, and application startup scenarios. First, the pre-defined machine learning model invokes a scenario recognition module, which has been trained on a large amount of scenario data to establish a scenario feature pattern library. Then, scenario-related features from the structured feature vectors are input into the pre-defined machine learning model. This model compares these scenario-related features with the scenario features in the scenario feature pattern library. For example, if scenario-related features indicate a sudden increase in memory allocation rate, no user operation, and the application is in a file decompression module, it is identified as an instantaneous high-load scenario; if user operation frequency is stable and the application is in a video playback module, it is identified as a stable interaction scenario; if the application process has a low priority and memory allocation is gradual, it is identified as a background task scenario; and if the application has just started and memory is rapidly allocated, it is identified as an application startup scenario.

[0047] S207. Dynamically adjust the parameter configuration of the garbage collection mechanism based on the target application scenario.

[0048] In this embodiment, based on the identified target application scenarios, a scenario mapping table, validated through extensive experiments and historical data, is invoked. This table stores the optimal GC parameters for different scenarios. Subsequently, the garbage collection mechanism's parameter configuration is dynamically adjusted according to the target application scenario and the corresponding optimal GC parameters in the scenario mapping table. This scenario-based parameter adjustment solves the problem of resource waste or incomplete collection caused by fixed parameters. This dynamic adjustment mode ensures efficient GC collection in different scenarios without affecting application performance, thus improving user experience.

[0049] S208. Collect the effect data and status data of the terminal after the garbage collection mechanism is executed, and construct optimized training samples based on the effect data and status data; In this embodiment, performance data and status data after the garbage collection mechanism is executed are collected. Performance data includes the amount of memory released after collection, collection time, user experience feedback, and memory allocation failure rate. Status data includes the heap memory status after collection, changes in object lifecycles, subsequent application modules, and intervals between subsequent user operations. Subsequently, optimized training samples are constructed based on the performance data and status data according to a standard training format. The resulting optimized training samples serve as the data foundation for subsequent model updates, enabling the model to be personalized and optimized according to the actual situation of the terminal.

[0050] It should be noted that the standard training format can be "input features - prediction results - execution parameters - performance data - state data", and there is no limitation here.

[0051] S209. Based on optimized training samples, update the weight ratios and parameter configurations of the preset machine learning model using an online gradient descent algorithm or a reinforcement learning algorithm.

[0052] In this embodiment, based on the optimized training samples obtained, the weight ratios and parameter configurations of the preset machine learning model are updated using an online gradient descent algorithm or a reinforcement learning algorithm. The online gradient descent algorithm is suitable for rapid iteration and fine-tuning based on a single sample; the reinforcement learning algorithm is suitable for optimizing long-term strategies through reward mechanisms.

[0053] Specifically, if an online gradient descent algorithm is used, the constructed optimized training samples are input as single training data into the preset machine learning model. The loss value between the prediction result of the preset machine learning model and the actual effect in the optimized training samples is calculated. The weight parameters of the preset machine learning model are adjusted according to the gradient direction of the loss value. For example, the weight of the "user operation interval" feature is increased, so that the preset machine learning model pays more attention to the impact of this feature on the idle window. If a reinforcement learning algorithm is used, the prediction result of the preset machine learning model is calculated according to the reward mechanism. The preset machine learning model adjusts the weights according to the reward value, so that the probability of making decisions that can obtain high rewards in the future is increased.

[0054] In step S207 above, during the process of dynamically adjusting the parameter configuration of the garbage collection mechanism, it is necessary to determine whether to make dynamic adjustments based on different target application scenarios. Please refer to [link / reference needed]. Figure 3 , Figure 3 An embodiment of the machine learning-based garbage collection method provided in this application, which dynamically adjusts the parameter configuration of the garbage collection mechanism according to different target application scenarios, includes: S301. When the target application scenario is a momentary high-load scenario, increase the capacity of the terminal's young generation memory and increase the thread scheduling priority in the garbage collection mechanism. In this embodiment, when the target application scenario is a momentary high-load scenario, the configuration rules corresponding to momentary high-load scenarios in the scenario mapping table are invoked to expand the capacity of the terminal's young generation memory. When expanding the young generation memory capacity, the capacity of the young generation is increased according to the memory demand characteristics of momentary high-load scenarios to accommodate more short-lived objects and reduce the number of times young generation garbage collection is frequently triggered.

[0055] At the same time, the thread scheduling priority in the garbage collection mechanism is increased, for example, by adjusting the thread scheduling priority from medium priority to high priority, to ensure that the threads in the garbage collection mechanism can occupy CPU resources first and complete the collection operation quickly in a short time, so as to avoid the collection process being interrupted due to insufficient resources.

[0056] S302. When the target application scenario is a stable interaction scenario, the garbage collection mechanism is restricted to be executed during the intervals between user interactions, and the threshold of the terminal's old generation memory is increased. In this embodiment, when the target application scenario is a stable interaction scenario, the garbage collection mechanism is triggered during the user interaction intervals of the idle window, avoiding triggering collection during user swiping, clicking, or other operations. Simultaneously, the usage threshold for triggering garbage collection in the old generation memory is increased, extending the trigger cycle of old generation memory garbage collection. At the same time, the conditions for young generation objects to be promoted to the old generation are made more stringent, ensuring that temporary objects generated during swiping are collected in the young generation and do not occupy old generation space. For example, in a short video app, temporary cached objects generated each time the user swipes are released during young generation memory reclamation and do not enter old generation memory.

[0057] S303. When the target application scenario is a background task scenario, extend the execution interval of the garbage collection mechanism and reduce the CPU priority of the garbage collection mechanism. In this embodiment, when the target application scenario is a background task scenario, the execution interval of the garbage collection mechanism is extended. For example, the execution interval of the garbage collection mechanism is adjusted from once every 30 seconds to once every 2 minutes to reduce the triggering frequency of the garbage collection mechanism and avoid frequent recycling that occupies resources.

[0058] At the same time, when reducing the CPU priority of the garbage collection mechanism, for example, by lowering the CPU priority of the garbage collection mechanism thread from medium priority to low priority, it is ensured that the foreground application can occupy CPU resources first, and the background garbage collection mechanism is only executed when the CPU is idle.

[0059] S304. When the target application scenario is the application startup scenario, adjust the heap memory size in the terminal and perform garbage collection on the young generation memory.

[0060] In this embodiment, when the target application scenario is an application startup scenario, the heap memory size is adjusted according to the memory requirement characteristics during the application startup period. For example, the heap memory size is increased from 500MB to 600MB. This provides sufficient space for memory allocation during the startup process and avoids allocation failure due to insufficient heap memory.

[0061] Since a large number of temporary initialization objects generated during application startup are concentrated in the young generation memory, garbage collection is performed on the young generation while adjusting the heap memory size. This can quickly release the memory occupied by these useless objects, freeing up space for the subsequent loading of the main functional modules of the application. For example, when office software starts, while adjusting the heap memory size to 600MB, garbage collection is performed on the young generation to release the 80MB of memory occupied by the temporary objects on the startup page, ensuring that the main editing module loads smoothly.

[0062] Before triggering the garbage collection mechanism within the idle window using the preset garbage collection scheduler in step S103 above, it is also necessary to check whether there are high-priority temporary tasks in the terminal. Please refer to [link to relevant documentation]. Figure 4 , Figure 4 An embodiment of the machine learning-based garbage collection method provided in this application for detecting the existence of high-priority temporary tasks in the terminal includes: S401. Detect whether there are high-priority temporary tasks in the terminal; Before triggering the garbage collection mechanism using the preset garbage collection scheduler, the system checks for high-priority temporary tasks on the terminal. High-priority temporary tasks are strongly related to system stability and critical user operations, such as processing system notification pushes, receiving emergency messages, and loading core functional modules of foreground applications.

[0063] During the detection process, the pre-defined garbage collection scheduler calls the terminal's task management interface to obtain a list of currently queued or executed temporary tasks, extracts the priority identifier of each task, and makes a judgment based on the priority identifier. When a temporary task with a priority identifier of "high" is detected, it is determined that a high-priority temporary task exists; if only a temporary task with a priority identifier of "low" is detected, it is determined that no high-priority temporary task exists.

[0064] If a high-priority temporary task exists, proceed to step S403; if no high-priority temporary task exists, proceed to step S402.

[0065] S402, Perform the step of triggering the garbage collection mechanism within the idle window using the preset garbage collection scheduler; When it is detected that there are no high-priority temporary tasks on the terminal, the step of triggering the garbage collection mechanism within the idle window using the preset garbage collection scheduler is executed.

[0066] In this embodiment, step S402 is similar to step S103 in the previous embodiment, and will not be described again here.

[0067] S403. Discard the current free window and record the remaining free windows after completing the high-priority temporary task.

[0068] When a high-priority temporary task is detected, the current free window is abandoned, and the remaining free window is recorded after the high-priority temporary task is completed.

[0069] Specifically, when the preset garbage collection scheduler confirms the existence of a high-priority temporary task, it will immediately terminate the current process that is preparing to trigger the garbage collection mechanism, abandon the identified free window, and prioritize the release of resources for the high-priority temporary task to execute. At the same time, the preset garbage collection scheduler starts a timer to record the start time and estimated completion time of the high-priority temporary task, and calculates the remaining window duration after the task is completed by combining it with the original total duration of the free window. For example, if the original free window is 3 seconds, and the high-priority temporary task starts execution at 0.5 seconds and completes at 1.5 seconds, the task execution takes 1 second. The preset garbage collection scheduler records the remaining free window as 1.5 seconds and stores the time range information of the remaining free window.

[0070] S404. Determine whether the garbage collection mechanism can be executed within the remaining free window. In this embodiment, the preset garbage collection scheduler first calculates the execution time of the garbage collection mechanism based on the recorded remaining free windows and the amount of memory to be reclaimed. Then, the preset garbage collection scheduler compares the calculated execution time with the duration of the remaining free windows.

[0071] If the calculated execution time is less than or equal to the remaining free window duration, garbage collection is deemed feasible. If the calculated execution time is greater than the remaining free window duration, garbage collection is not feasible. For example, if the remaining free window duration is 1.5 seconds, 80MB is to be reclaimed, and the calculated execution time is 0.8 seconds, then garbage collection is deemed feasible. However, if the remaining free window duration is 1.5 seconds, 150MB is to be reclaimed, and the estimated execution time is 2 seconds, then garbage collection is deemed not feasible.

[0072] If it is determined that the garbage collection mechanism can be executed, then the garbage collection mechanism is executed directly; if it is determined that the garbage collection mechanism cannot be executed, then step S405 is executed.

[0073] S405. Collect execution data of high-priority temporary tasks and send the execution data to the preset machine learning model for learning, so as to optimize the next prediction of the preset machine learning model.

[0074] In this embodiment, when it is determined that the remaining free window cannot execute the garbage collection mechanism, execution data of high-priority temporary tasks is collected and sent to a preset machine learning model for learning, in order to optimize the model's next prediction. Specifically, execution data including the type of high-priority temporary tasks, execution duration, changes in memory usage during execution, and impact on the original free window are first collected. After collection, this execution data is organized into structured data and associated with the original free window. Subsequently, the structured data is sent to the preset machine learning model through a preset garbage collection scheduler. The preset machine learning model adjusts its parameters through a learning algorithm, which can be an online gradient descent algorithm, to optimize the next free window prediction. By collecting execution data of high-priority temporary tasks and feeding it back to the preset machine learning model for learning, continuous optimization of the preset machine learning model is achieved, improving the prediction accuracy of the subsequent free window.

[0075] The following provides a detailed description of the machine learning-based garbage collection system provided in this application. Please refer to [link / reference]. Figure 5 , Figure 5 An embodiment of the machine learning-based garbage collection system provided in this application includes: The generation unit 501 is used to collect multi-dimensional data during terminal operation and perform feature engineering processing on the multi-dimensional data to generate structured feature vectors. The multi-dimensional data includes memory allocation rate, object lifecycle statistics, user interaction operations, heap memory status and application context information. The prediction unit 502 is used to input the structured feature vector into the preset machine learning model, and predict the terminal's idle window and memory pressure trend through the preset machine learning model; The adjustment unit 503 is used to trigger the garbage collection mechanism within the free window based on the free window and memory pressure trend, using a preset garbage collection scheduler, and dynamically adjust the parameter configuration of the garbage collection mechanism.

[0076] Optionally, the preset machine learning models include preset time series prediction models and preset classification models; Predict terminal idle window and memory pressure trends using a pre-set machine learning model, including: Predict the memory pressure trend of structured feature vectors using a pre-set time-series prediction model; The idle window of the terminal is obtained by identifying the idle features in the structured feature vector through a preset classification model.

[0077] Optionally, the adjustment unit 503 is specifically used for: The target application scenarios are identified from the structured feature vectors by a pre-set machine learning model. The target application scenarios include instantaneous high load scenarios, stable interaction scenarios, background task scenarios, and application startup scenarios. The parameters of the waste recycling mechanism are dynamically adjusted based on the target application scenario.

[0078] Optionally, the adjustment unit 503 is specifically used for: When the target application scenario is a momentary high-load scenario, increase the capacity of the terminal's young generation memory and increase the thread scheduling priority in the garbage collection mechanism; When the target application scenario is a stable interaction scenario, the garbage collection mechanism is restricted to be executed during the intervals between user interactions, and the threshold of the terminal's old generation memory is increased; When the target application scenario is a background task scenario, extend the execution interval of the garbage collection mechanism and reduce the CPU priority of the garbage collection mechanism; When the target application scenario is application startup, adjust the heap memory size in the terminal and perform garbage collection on the young generation memory.

[0079] Optionally, a detection unit 504 is also included, specifically for: Detect whether there are high-priority temporary tasks in the terminal; If not, then proceed with the step of triggering the garbage collection mechanism within the idle window using the preset garbage collection scheduler; If so, discard the current free window and record the remaining free window after completing the high-priority temporary task.

[0080] Optionally, a judgment unit 505 is also included, specifically used for: Determine whether garbage collection can be performed within the remaining free window; If not, the execution data of high-priority temporary tasks are collected and sent to the preset machine learning model for learning, so as to optimize the preset machine learning model's prediction for the next time.

[0081] Optionally, an optimization unit 506 is also included, specifically for: Optimize the preset machine learning model; Optimize the pre-defined machine learning model, including: Collect the effect data and status data of the terminal after the garbage collection mechanism is implemented, and construct optimized training samples based on the effect data and status data; Based on optimized training samples, the weight ratios and parameter configurations of the preset machine learning model are updated using online gradient descent or reinforcement learning algorithms.

[0082] For details on the implementation method, please refer to [link / reference]. Figures 1-4Examples will not be described in detail here.

[0083] This application also provides a machine learning-based waste recycling device; please refer to [link / reference]. Figure 6 , Figure 6 One embodiment of the waste recycling device provided in this application includes: Processor 601, memory 602, input / output unit 603, bus 604; The processor 601 is connected to the memory 602, the input / output unit 603, and the bus 604; The memory 602 stores a program, and the processor 601 calls the program to execute any of the garbage collection methods described above.

[0084] This application also relates to a computer-readable storage medium on which a program is stored, characterized in that when the program is run on a computer, it causes the computer to perform any of the garbage collection methods described above.

[0085] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0086] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection between apparatuses or units through some interfaces, and may be electrical, mechanical, or other forms.

[0087] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0088] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0089] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

Claims

1. A garbage collection method based on machine learning, characterized in that, include: Collect multi-dimensional data during terminal operation and perform feature engineering processing on the multi-dimensional data to generate structured feature vectors. The multi-dimensional data includes memory allocation rate, object lifecycle statistics, user interaction operations, heap memory status, and application context information. The structured feature vector is input into a preset machine learning model, and the preset machine learning model is used to predict the idle window and memory pressure trend of the terminal. Based on the free window and the memory pressure trend, a preset garbage collection scheduler is used to trigger the garbage collection mechanism within the free window, and the parameter configuration of the garbage collection mechanism is dynamically adjusted.

2. The waste recycling method according to claim 1, characterized in that, The preset machine learning model includes a preset time-series prediction model and a preset classification model; The step of predicting the terminal's idle window and memory pressure trends using the preset machine learning model includes: The memory pressure trend of the structured feature vector is predicted using the preset time-series prediction model. The idle window of the terminal is obtained by identifying the idle features in the structured feature vector through the preset classification model.

3. The waste recycling method according to claim 1, characterized in that, The dynamic adjustment of the parameters of the waste recycling mechanism includes: The target application scenario is identified from the structured feature vector by the preset machine learning model, wherein the target application scenario includes instantaneous high load scenario, stable interaction scenario, background task scenario and application startup scenario; The parameters of the waste recycling mechanism are dynamically adjusted based on the target application scenario.

4. The waste recycling method according to claim 3, characterized in that, The parameter configuration for dynamically adjusting the garbage collection mechanism based on the target application scenario includes: When the target application scenario is the instantaneous high-load scenario, the capacity of the young generation memory of the terminal is increased, and the thread scheduling priority in the garbage collection mechanism is improved. When the target application scenario is the stable interaction scenario, the garbage collection mechanism is restricted to be executed during user interaction intervals, and the threshold of the old generation memory of the terminal is increased; When the target application scenario is the background task scenario, the execution interval of the garbage collection mechanism is extended and the CPU priority of the garbage collection mechanism is reduced; When the target application scenario is the application startup scenario, adjust the heap memory size in the terminal and perform garbage collection on the young generation memory.

5. The waste recycling method according to claim 1, characterized in that, Before triggering the garbage collection mechanism within the idle window using a preset garbage collection scheduler, the garbage collection method further includes: Detect whether there are high-priority temporary tasks in the terminal; If not, then execute the step of triggering the garbage collection mechanism within the idle window using the preset garbage collection scheduler; If so, the current free window is abandoned, and the remaining free window is recorded after the high-priority temporary task is completed.

6. The waste recycling method according to claim 5, characterized in that, After recording the remaining free window, the garbage collection method further includes: Determine whether the garbage collection mechanism can be executed within the remaining free window; If not, the execution data of the high-priority temporary task is collected and sent to the preset machine learning model for learning, so as to optimize the next prediction of the preset machine learning model.

7. The waste recycling method according to any one of claims 1 to 6, characterized in that, After dynamically adjusting the parameter configuration of the garbage collection mechanism, the garbage collection method further includes: The preset machine learning model is optimized; The optimization of the preset machine learning model includes: Collect the effect data and status data of the terminal after the garbage collection mechanism is executed, and construct optimized training samples based on the effect data and status data; Based on the optimized training samples, the weight ratios and parameter configurations of the preset machine learning model are updated using an online gradient descent algorithm or a reinforcement learning algorithm.

8. A machine learning-based waste recycling system, characterized in that, include: The generation unit is used to collect multi-dimensional data during terminal operation and perform feature engineering processing on the multi-dimensional data to generate structured feature vectors. The multi-dimensional data includes memory allocation rate, object lifecycle statistics, user interaction operations, heap memory status, and application context information. The prediction unit is used to input the structured feature vector into a preset machine learning model, and predict the idle window and memory pressure trend of the terminal through the preset machine learning model; The adjustment unit is used to trigger the garbage collection mechanism within the free window based on the free window and the memory pressure trend, using a preset garbage collection scheduler, and dynamically adjust the parameter configuration of the garbage collection mechanism.

9. A waste recycling device based on machine learning, characterized in that, include: Processor, memory, input / output units, and bus; The processor is connected to the memory, the input / output unit, and the bus; The memory stores a program, which the processor invokes to perform the garbage collection method as described in any one of claims 1 to 7.

10. A computer-readable storage medium having a program stored thereon, the program performing the garbage collection method as described in any one of claims 1 to 7 when executed on a computer.