Memory optimization method and device for mobile application object pool and storage medium

By monitoring the memory usage and object types of mobile applications, the number of objects retained in the object pool is dynamically adjusted, solving the problem that a fixed-capacity object pool cannot adapt to changes in memory demand and improving memory utilization.

CN120909769APending Publication Date: 2025-11-07SHENZHEN ZHUXIN NETWORK TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510945117.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-09
Publication Date
2025-11-07

AI Technical Summary

Technical Problem

Fixed-capacity object pools cannot dynamically adapt to changes in memory requirements during mobile application runtime, resulting in low memory utilization.

Method used

By monitoring the memory usage of mobile applications, calculating memory consumption based on memory compression levels and object data types, detecting idle objects and compressing them, and dynamically adjusting the target retention number of objects in the object pool.

Benefits of technology

It enables dynamic adjustment of the object pool based on actual memory requirements, reducing unnecessary memory usage and improving memory utilization efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120909769A_ABST
    Figure CN120909769A_ABST
Patent Text Reader

Abstract

The invention discloses a memory optimization method and device for a mobile application object pool and a storage medium, relates to the technical field of memory management, and discloses a memory optimization method for the mobile application object pool, which comprises the following steps: acquiring a memory utilization rate of a mobile application, and determining a memory compression level according to the memory utilization rate; calculating the memory occupation amount of a single object in the to-be-compressed object pool according to the data type of the object in the to-be-compressed object pool; according to the memory occupation amount and the memory compression level, determining a target reservation number of objects in the to-be-compressed object pool; detecting idle states of objects in the to-be-compressed object pool, and determining idle objects in the to-be-compressed object pool; and compressing the idle objects in the to-be-compressed object pool according to the target reservation quantity. According to the method, the memory usage condition is monitored, the memory occupation amount is calculated according to the object data type, the object retention number is dynamically adjusted in combination with different compression strategies, the memory release amount difference of fixed proportion compression is reduced, and the memory optimization efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of memory management, in particular to a memory optimization method, device and storage medium for mobile application object pool. BACKGROUND

[0002] In the development of mobile applications, object pool technology usually uses a fixed-size object cache queue to realize object reuse, thereby reducing the performance overhead caused by frequent object creation and destruction, and further optimizing memory allocation efficiency. However, in the actual running process of mobile applications, memory requirements will dynamically change due to factors such as multi-task switching and changes in application scenarios. Since the fixed-size object pool cannot be dynamically adjusted according to the actual memory usage, when the memory requirements of the mobile application change, it is difficult to flexibly adjust the allocation of memory resources, resulting in low memory utilization.

[0003] The above content is only used to assist in understanding the technical solutions of the present application and does not represent the acknowledgement of the above content as prior art. SUMMARY

[0004] The main purpose of the present application is to provide a memory optimization method, device and storage medium for mobile application object pool, aiming to solve the technical problem that the object pool with fixed capacity cannot dynamically adapt to the change of memory requirements during the running of mobile applications.

[0005] To achieve the above purpose, the present application provides a memory optimization method for mobile application object pool, which comprises: Obtaining the memory usage of a mobile application, and determining a memory compression level according to the memory usage; According to the data type of the objects in the to-be-compressed object pool, calculating the memory occupancy of a single object in the to-be-compressed object pool; According to the memory occupancy and the memory compression level, determining the target number of objects in the to-be-compressed object pool; Detecting the idle state of the objects in the to-be-compressed object pool, and determining the idle objects in the to-be-compressed object pool; According to the target number of objects, performing compression processing on the idle objects in the to-be-compressed object pool.

[0006] In an embodiment, before the step of calculating the memory occupancy of a single object in the to-be-compressed object pool according to the data type of the objects in the to-be-compressed object pool, the memory optimization method for mobile application object pool further comprises: According to the calling frequency and / or the recent access time of each object pool in the mobile application, determining the current active state of each object pool; According to the current active state, determining the to-be-compressed object pool.

[0007] In an embodiment, the step of calculating the memory occupancy of each object in the object pool to be compressed according to the data type of the object in the object pool to be compressed comprises: obtaining the data type of the object in the object pool to be compressed, and determining the memory occupancy calculation rule corresponding to the data type; calculating the memory occupancy of each object in the object pool to be compressed according to the memory occupancy calculation rule.

[0008] In an embodiment, the step of calculating the memory occupancy of each object in the object pool to be compressed according to the memory occupancy calculation rule comprises: when the data type is an array type, obtaining the byte length of the array type, calculating the product of the byte length and the array length, and adding a preset byte head overhead as the memory occupancy of each object; when the data type is a set type, obtaining the number of elements contained in the set, and taking the product of the number of elements and a preset single-element byte number as the memory occupancy of each object; when the data type is a general type, taking a preset default object byte number as the memory occupancy of each object.

[0009] In an embodiment, the step of determining the target retention number of objects in the object pool to be compressed according to the memory occupancy and the memory compression level comprises: determining the memory compression ratio of the object pool to be compressed according to the memory compression level; calculating the amount of memory to be compressed of the object pool to be compressed according to the memory compression ratio and the current total memory occupancy of the object pool to be compressed; determining the target retention number of objects in the object pool to be compressed according to the amount of memory to be compressed and the memory occupancy of each object.

[0010] In an embodiment, the step of determining the target retention number of objects in the object pool to be compressed according to the amount of memory to be compressed and the memory occupancy of each object comprises: determining the basic retention number of objects in the object pool to be compressed, the basic retention number being a preset minimum object number of the object pool to be compressed; calculating the theoretically retainable number of objects in the object pool to be compressed according to the amount of memory to be compressed and the memory occupancy of each object; taking the larger value between the basic retention number and the theoretically retainable number as the target retention number.

[0011] In an embodiment, after the step of calculating the theoretical retainable quantity of objects in the object pool to be compressed according to the memory amount to be compressed and the memory occupancy of a single object, the memory optimization method of the mobile application object pool further comprises: calculating a memory pressure coefficient according to the maximum allowed memory of the object pool to be compressed and the current total memory occupancy, the memory pressure coefficient being a ratio of a difference between the maximum allowed memory and the current total memory occupancy to the maximum allowed memory; correcting the theoretical retainable quantity according to the memory pressure coefficient; taking a larger value between the basic retainable quantity and the corrected theoretical retainable quantity as the target retainable quantity.

[0012] In an embodiment, the step of detecting the idle state of the objects in the object pool to be compressed to determine the idle objects in the object pool to be compressed comprises: acquiring a last access time of each of the objects in the object pool to be compressed; determining, according to a preset idle time threshold, the objects whose interval between the current time and the last access time exceeds the idle time threshold as the idle objects; and / or acquiring an access time record corresponding to a preset access frequency of each of the objects in the object pool to be compressed; calculating, according to the access time record, an access interval of adjacent access times and a standard deviation of the access intervals; quantifying a call frequency weight of each of the objects in the object pool to be compressed based on the standard deviation; determining, when the call frequency weight is lower than a preset call frequency threshold, the object corresponding to the call frequency weight as the idle object.

[0013] Embodiments of the present application also provide a memory optimization device of a mobile application object pool, which comprises a memory, a processor and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the memory optimization method of the mobile application object pool as described above.

[0014] Embodiments of the present application also provide a storage medium, which is a computer readable storage medium, the storage medium storing a computer program, the computer program being executable on a processor to implement the steps of the memory optimization method of the mobile application object pool as described above.

[0015] The one or more technical solutions provided by the present application have at least the following technical effects: The application monitors the memory usage of a mobile application during running, adopts different memory compression strategies, calculates the memory occupation of a single object according to the data type of the object, and then determines the target reserved quantity of the object pool in combination with the memory compression level, thereby solving the problem of large difference in memory release quantity caused by compressing the object pool at a fixed ratio. The application can dynamically adjust the target reserved quantity of the objects in the object pool according to the actual memory occupation of different data type objects in the object pool and in combination with the memory compression strategy corresponding to the current memory usage, thereby more accurately releasing the memory, reducing unnecessary memory occupation, and improving the efficiency of memory usage. BRIEF DESCRIPTION OF DRAWINGS

[0016] Figure 1 A flowchart of a first embodiment of the memory optimization method for the object pool of a mobile application involved in the embodiment scheme of the application is shown. Figure 2 A flowchart of a second embodiment of the memory optimization method for the object pool of a mobile application involved in the embodiment scheme of the application is shown. Figure 3 A flowchart of a third embodiment of the memory optimization method for the object pool of a mobile application involved in the embodiment scheme of the application is shown. Figure 4 A flowchart of a fourth embodiment of the memory optimization method for the object pool of a mobile application involved in the embodiment scheme of the application is shown. Figure 5 A structural diagram of a memory optimization device for the object pool of a mobile application involved in the embodiment scheme of the application is shown.

[0017] The object implementation, functional features and advantages of the application will be further described with reference to the embodiments and the accompanying drawings. DETAILED DESCRIPTION

[0018] It should be understood that the specific embodiments described herein are only used to explain the application and not to limit the application.

[0019] In order to better understand the technical scheme of the application, the following will be described in detail in combination with the drawings and specific embodiments.

[0020] In mobile application development, the object pool technology usually adopts a fixed-size object cache queue to realize object reuse, thereby reducing the performance overhead caused by frequent object creation and destruction, and further optimizing the memory allocation efficiency. However, in the actual running process of a mobile application, the memory demand will dynamically change due to factors such as multi-task switching and application scenario changes. Since the fixed-size object pool cannot be dynamically adjusted according to the actual memory usage, when the memory demand of the mobile application changes, it is difficult to flexibly adjust the memory resource allocation, resulting in low memory utilization.

[0021] In view of the above problems, the present application provides a memory optimization method for mobile application object pool, which comprises the following steps: acquiring the memory usage of the mobile application, and determining the memory compression level according to the memory usage; calculating the memory occupation of a single object in the to-be-compressed object pool according to the data type of the object; determining the target retention quantity of the object in the to-be-compressed object pool according to the memory occupation and the memory compression level; detecting the idle state of the object in the to-be-compressed object pool, and determining the idle object in the to-be-compressed object pool; and performing compression processing on the idle object in the to-be-compressed object pool according to the target retention quantity.

[0022] The present application provides a solution, which monitors the memory usage of the mobile application during running, adopts different memory compression strategies, calculates the memory occupation of a single object according to the data type of the object, and then determines the target retention quantity of the object pool in combination with the memory compression level, thereby solving the problem of large difference in memory release amount caused by compressing the object pool at a fixed ratio. The present application can dynamically adjust the target retention quantity of the object in the object pool according to the actual memory occupation of the object of different data types in the object pool and in combination with the memory compression strategy corresponding to the current memory usage, so as to more accurately release the memory, reduce unnecessary memory occupation, and improve the efficiency of memory usage.

[0023] It should be noted that the execution subject of the present embodiment can be a computing service device having data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone and the like, or an electronic device, an object pool management system, a game engine and the like capable of realizing the above functions. Hereinafter, the present embodiment and each of the following embodiments will be described taking a mobile device as an example.

[0024] The memory optimization method for mobile application object pool of the first embodiment of the present application is described in detail with reference to Figure 1 , which comprises steps S10-S50. Step S10: acquiring the memory usage of the mobile application, and determining the memory compression level according to the memory usage.

[0025] It should be noted that the memory usage refers to the ratio of the currently used memory space of the mobile application to the total available memory space of the mobile application. The total available memory space of the mobile application is based on the memory management mechanism of the mobile application in the operating system, that is, each application will be allocated an independent memory resource upper limit when running, and the calculation of the memory usage is only for this part of the independently allocated memory range, and not for the total memory amount of the system as a whole. The memory compression level is a pre-set different compression strategy, which is used to indicate the intensity of the compression operation on the data object pool of the mobile application.

[0026] In the embodiment, the memory monitoring module calls a memory state query interface provided by a mobile device operating system to obtain the memory space currently used by the mobile application and the upper limit of the memory resource allocated thereto in real time, and then calculates the memory usage. Then, the memory usage obtained is compared with the memory threshold corresponding to each compression strategy set in advance to determine the corresponding memory compression level.

[0027] For example, three memory compression levels are set in advance, such as three compression strategies of light compression, moderate compression, and aggressive compression. The memory threshold set for light compression is 65%, the memory threshold set for moderate compression is 75%, and the memory threshold set for aggressive compression is 85%.

[0028] After obtaining the memory usage of the mobile application, the compression strategy to be adopted is determined according to the comparison result of the memory usage and the preset memory threshold, and the corresponding memory compression operation is performed on the data object pool of the mobile application according to the selected compression strategy. For example, when the memory usage of the mobile application reaches 65%, the light compression strategy is triggered; if the memory usage reaches 75%, the moderate compression strategy is enabled; and if the memory usage rises to 85% or above, the aggressive compression strategy is started.

[0029] Step S20: According to the data type of the objects in the to-be-compressed object pool, the memory occupancy of a single object in the to-be-compressed object pool is calculated.

[0030] It should be noted that the data type is used to distinguish the storage and processing manner of the object in the computer, and different data types occupy different sizes of spaces in the memory. The to-be-compressed object pool refers to a set of objects that need to be compressed in the memory optimization process. The memory occupancy refers to the actual number of bytes occupied by a single object instance in the heap memory.

[0031] In the embodiment, the objects can be different types of data structures in the mobile application. For example, there are GameObject, texture resource, configuration data, and other object types of different memory structures in the Unity engine.

[0032] For example, for the GameObject object of Unity, the memory occupancy of a single GameObject object is calculated by traversing all components thereof and counting the number of Mesh vertices x the number of bytes occupied by each vertex; for the texture object, the corresponding number of bytes can be calculated by width x height x pixel format, so as to take the number of bytes as the memory occupancy of a single texture object; and for the configuration object, the corresponding memory occupancy can be directly obtained according to the size of the data structure thereof.

[0033] As a feasible implementation manner, step S20 includes steps S210-S220: Step S210: Obtain the data type of the objects in the object pool to be compressed, and determine the memory occupation calculation rule corresponding to the data type.

[0034] It should be noted that the data type refers to the specific classification of the object in the programming language, including basic types (such as int, float), composite types (such as class instances, arrays), and special resource types (such as textures, sound effects, etc.). The memory occupation calculation rule refers to the differentiated memory estimation method developed for different types of objects.

[0035] In this embodiment, the fields and data types of each object in the object pool to be compressed can be obtained through the reflection mechanism, and then according to the mapping relationship table of the data type and the memory occupation calculation rule stored in advance, the memory occupation calculation rule corresponding to the data type is found and determined.

[0036] Step S220: Calculate the memory occupation of a single object in the object pool to be compressed according to the memory occupation calculation rule.

[0037] In this embodiment, according to the memory occupation calculation rule determined in step S210, the memory occupation of each object in the object pool to be compressed is calculated. Specifically, step S220 includes steps S2110-S2130: Step S2210: When the data type is an array type, obtain the byte length of the array type, calculate the product of the byte length and the array length, and add a preset byte head overhead as the memory occupation of a single object.

[0038] It should be noted that the array type refers to a data structure that stores a collection of elements of the same type. The byte length refers to the number of bytes occupied by a single element in the array, for example, an int type element usually occupies 4 bytes. The array length refers to the number of elements contained in the array. The preset byte head overhead refers to the fixed memory space that the array object itself needs to occupy in addition to the element data in the memory, which is used to store management data such as array length information and type information.

[0039] Step S2220: When the data type is a set type, obtain the number of elements contained in the set, and multiply the number of elements by the preset number of bytes of a single element to obtain the memory occupation of a single object.

[0040] It should be noted that the set type refers to a data structure that stores a group of non-repeating elements, such as Set. The number of elements contained in the set refers to the actual number of elements stored in the current set. The preset number of bytes of a single element refers to the average number of memory bytes occupied by a single element in the preset set, for example, using an approximate estimate of "number of elements x 16 bytes".

[0041] Step S2230: When the data type is a general type, a preset default object byte number is taken as the memory occupancy of a single object.

[0042] It should be noted that the general type refers to object types that cannot be classified and do not have specific memory occupancy calculation rules, including custom class instances and the like. The default object byte number refers to a fixed memory occupancy of a general type object, which is used to provide an estimated value when the memory occupancy cannot be accurately calculated.

[0043] In this embodiment, the preset default object byte number is directly used as the memory occupancy of a general type object. For example, 64 bytes of basic space are allocated by default for a general type object.

[0044] Step S30: According to the memory occupancy and the memory compression level, a target reserved number of objects in the to-be-compressed object pool is determined.

[0045] It should be noted that the target reserved number refers to the number of objects that need to be finally reserved in the to-be-compressed object pool under the current memory compression level, so as to achieve the purpose of reasonably releasing memory without affecting the normal operation of the application.

[0046] In this embodiment, a differentiated compression strategy can be configured for different memory compression levels. Specifically, the compression strategy can be determined based on the memory compression ratio. First, according to the compression strategy corresponding to the memory compression level, the memory compression ratio in the to-be-compressed object pool is determined. Then, the product of the current total number of objects in the to-be-compressed object pool and the memory occupancy of a single object is calculated to determine the current total memory occupancy in the to-be-compressed object pool. Then, the current total memory occupancy in the to-be-compressed object pool is multiplied by the memory compression ratio to obtain the size of the memory space that needs to be released. Then, the memory space size corresponding to the target reserved number of objects is obtained. Finally, the target reserved number is calculated according to the memory occupancy of a single object.

[0047] It can be understood that the above compression method based on the memory compression ratio considers the actual memory occupation difference of the object. When facing different types of object pool compression, the amount of memory released may be quite different. For example, for a pool containing 100 4KB texture objects and a pool containing 100 64-byte configuration objects, if both are compressed by 50%, the texture pool will release 50x4KB=200KB of memory, while the configuration pool will only release 50x64B=3.2KB of memory. The actual memory release amount is too different. Therefore, the compression strategy based on the memory compression ratio can ensure that different object pools can release the expected amount of memory, avoiding the imbalance of resource release caused by "small object pool compression ineffective and large object pool compression insufficient", and significantly improving the pertinence and efficiency of memory optimization.

[0048] Optionally, the compression strategy can also be set based on the idle object retention ratio. For example, when in the light compression level, conservative compression is performed on the object pool marked as the inactive state (the object pool to be compressed), and 70% of the idle objects are retained; when in the moderate compression level, balanced compression is performed on the object pool to be compressed, and 50% of the idle objects are retained; and when in the aggressive compression level, all recyclable object pools (i.e., the object pool to be compressed) are forcibly emptied, and the complete garbage collection process is triggered.

[0049] It can be understood that the above compression method based on the idle object retention ratio is more suitable for scenarios where the object types are relatively uniform and the memory occupation difference is small. According to the current active state of the object pool, the inactive object pool is selected for compression to reduce the impact on system performance. At the same time, a gradual idle object retention mechanism is adopted, and the recycling intensity is gradually increased as the memory pressure increases, which not only guarantees the survival rate of key objects, but also realizes the step-by-step release of memory occupation.

[0050] It should be noted that the memory compression ratio and the idle object retention ratio in the embodiment can be adjusted according to actual application.

[0051] Step S40: detecting the idle state of the object in the object pool to be compressed, and determining the idle object in the object pool to be compressed.

[0052] It should be noted that the idle state is used to determine whether the object is accessed or used within a certain time period. The object in the idle state means that the object has less impact on the application running at the current stage and can be used as a target object for compression processing. In the embodiment, the idle state of the object can be determined by the access timestamp or the calling frequency of the object.

[0053] As a feasible implementation, an access timestamp is set for each object to record the time when the object is last accessed, and then the idle state of the object is determined by calculating the idle time between the current time and the access timestamp. For example, if the difference between the current time and the access timestamp exceeds a preset idle time threshold, such as 30 minutes, the object is considered to be in an idle state.

[0054] Step S50: According to the target reserved number, the idle objects in the to-be-compressed object pool are compressed.

[0055] It should be noted that the compression processing refers to releasing or recycling the determined idle objects to reduce the number of idle objects in the to-be-compressed object pool, thereby releasing the memory space and reducing the memory occupation. The target reserved number is to ensure that the number of objects after compression processing will not be lower than the number.

[0056] As a feasible implementation, the idle objects in the to-be-compressed object pool are sorted according to the idle time from long to short, and the idle objects that are not used for the longest time are removed first until the number of objects in the to-be-compressed object pool reaches the target reserved number.

[0057] As another feasible implementation, the idle objects are compressed in order according to the memory occupation from large to small until the target reserved number is reached. For example, the texture objects with large memory occupation are preferentially compressed, and the configuration objects with small memory occupation can be appropriately reserved.

[0058] Based on the above embodiments of the present application, in the second embodiment of the present application, the same or similar contents as the above first embodiment can be referred to the above introduction, and will not be described in detail. On this basis, please refer to Figure 2 , before step S20, the memory optimization method of the mobile application object pool includes steps S201-S202: Step S201: According to the call frequency and / or the latest access time of each object pool in the mobile application, the current active state of each object pool is determined.

[0059] Step S202: According to the current active state, the to-be-compressed object pool is determined.

[0060] It should be noted that the latest access time refers to the access timestamp of the object pool last accessed, which is used to measure the timeliness of the object pool.

[0061] In the embodiment, an access log is maintained for each object pool, recording the timestamp and access operation type of each access to the object pool. By analyzing the access log, the access timestamp corresponding to the preset number of accesses of each object pool is obtained, then the access interval between adjacent access timestamps is calculated, and the standard deviation of the access intervals is calculated to determine the call frequency weight of the object pool. Finally, the call frequency weight is compared with the preset frequency idle threshold, and if the call frequency weight is less than the preset frequency idle threshold, the object pool is determined to be frequency idle.

[0062] It should be noted that the lower the call frequency weight, the less regular the access of the object pool, and the lower the activity. The call frequency weight = 1 / (0.1+standard deviation).

[0063] Next, the latest access time of each object pool is obtained from the access log, and the difference between the latest access time and the current time is calculated. The difference is compared with the preset time window, and if the difference exceeds the preset time window, it means that the object pool has not been accessed for a long time and the activity is low, so it can be determined whether the object pool belongs to time idle.

[0064] Finally, when the object pool belongs to frequency idle and / or time idle, the current active state of the object pool is idle state, and the object pool is a compression object pool.

[0065] Based on the above embodiments of the present application, in the third embodiment of the present application, the same or similar contents as the above embodiments can be referred to the above introduction, and will not be described in detail. On this basis, please refer to Figure 3 , in the memory optimization method of the mobile application object pool, step S30 includes steps S310-S330: Step S310: determining the memory compression ratio of the compression object pool according to the memory compression level.

[0066] It should be noted that the memory compression level refers to different compression strategies preset according to the memory usage rate, which is used to indicate the intensity of the compression operation on the object pool of the mobile application. The memory compression ratio refers to the proportion of the memory part of the object pool in the total memory of the object pool that needs to be compressed in the corresponding memory compression level.

[0067] In the embodiment, a corresponding memory compression ratio is set for each memory compression level in advance. For example, for the light compression level, the memory compression ratio is set to 30%; for the moderate compression level, the memory compression ratio is set to 50%, and for the aggressive compression level, the memory compression ratio is set to 100%.

[0068] Step S320: calculating the to-be-compressed memory amount of the to-be-compressed object pool according to the memory compression ratio and the current total memory occupancy of the to-be-compressed object pool.

[0069] It should be noted that the current total memory occupancy refers to the total memory size occupied by the to-be-compressed object pool at the current time, and the calculation method is the total number of current objects in the to-be-compressed object pool and the memory occupancy amount of a single object. The to-be-compressed memory amount refers to the memory amount that needs to be compressed and released from the to-be-compressed object pool according to the memory compression ratio.

[0070] Exemplarily, if the current total memory occupancy of the to-be-compressed object pool is 1000KB, and moderate compression needs to be performed on the to-be-compressed object pool, the memory compression ratio is 50%, and the to-be-compressed memory amount is 500KB.

[0071] Step S330: determining the target reserved number of objects in the to-be-compressed object pool according to the to-be-compressed memory amount and the memory occupancy amount of a single object.

[0072] It should be noted that the target reserved number refers to the number of objects that need to be reserved to ensure that the object pool can still maintain a certain number of objects after releasing a specified memory amount, according to the to-be-compressed memory amount and the memory occupancy amount of a single object in the memory optimization process.

[0073] As a feasible implementation, step S330 includes steps S3310-S3330: Step S3310: determining the basic reserved number of objects in the to-be-compressed object pool, the basic reserved number being a preset minimum object number of the to-be-compressed object pool.

[0074] It should be noted that the basic reserved number refers to the minimum number of objects that must be reserved in the to-be-compressed object pool in order to ensure that the basic functions of the mobile application are not affected. The basic reserved number is set according to the basic running requirements of the mobile application, to ensure that the application can still run normally even in an extreme compression case.

[0075] As a feasible implementation, the basic reserved number of each to-be-compressed object pool can be preset through a configuration file or a constant in the code. For example, for a texture object pool, the basic reserved number can be set to 10 to ensure that the application can still display a basic graphical interface in a low memory situation.

[0076] Step S3320: calculating the theoretically reserved number of objects in the to-be-compressed object pool according to the to-be-compressed memory amount and the memory occupancy amount of a single object.

[0077] It should be noted that the to-be-compressed memory amount refers to the memory space to be released calculated according to the memory compression level and the total memory occupancy of the object pool. The theoretical retainable quantity refers to the ideal retainable quantity of objects in the to-be-compressed object pool calculated based on the memory space to be released and the memory occupancy of a single object. The calculation formula is: theoretical retainable quantity = current object quantity - (to-be-compressed memory amount / memory occupancy of a single object), or: theoretical retainable quantity = (total memory occupancy of the to-be-compressed object pool - to-be-compressed memory amount) / memory occupancy of a single object.

[0078] Step S3330: Taking the larger value between the base retainable quantity and the theoretical retainable quantity as the target retainable quantity.

[0079] In this embodiment, the larger value between the base retainable quantity and the theoretical retainable quantity is taken as the target retainable quantity, so as to ensure that the number of objects retained in the to-be-compressed object pool is not lower than the minimum safety threshold for guaranteeing the normal operation of the mobile application while meeting the memory compression requirement.

[0080] Optionally, after step S3320, the method further includes: Step S3321: Calculating a memory pressure coefficient according to the maximum allowed memory of the to-be-compressed object pool and the current total memory occupancy, the memory pressure coefficient being the ratio of the difference between the maximum allowed memory and the current total memory occupancy to the maximum allowed memory.

[0081] Step S3322: Correcting the theoretical retainable quantity according to the memory pressure coefficient.

[0082] Step S3323: Taking the larger value between the base retainable quantity and the corrected theoretical retainable quantity as the target retainable quantity.

[0083] It should be noted that the maximum allowed memory refers to the upper limit of memory usage configured for the to-be-compressed object pool, which is used to limit the memory occupancy of the to-be-compressed object pool and prevent it from excessively consuming system resources. The memory pressure coefficient reflects the urgency of current memory usage, and the value range is 0 to 1. The smaller the value, the greater the memory pressure, that is, the closer the memory usage to the upper limit. The calculation formula of the pressure coefficient is: (memory usage upper limit - current total memory occupancy) / memory usage upper limit.

[0084] In this embodiment, the corrected theoretical retainable quantity = theoretical retainable quantity x (1 + pressure coefficient), and the target retainable quantity = max (base retainable quantity, corrected theoretical retainable quantity), so as to ensure that the number of objects retained in the to-be-compressed object pool is not lower than the minimum safety threshold for guaranteeing the normal operation of the mobile application.

[0085] Therefore, by setting the memory pressure coefficient, the embodiment can ensure that the reserved number of objects in the to-be-compressed object pool is appropriately increased when the memory pressure is small, so as to ensure the performance of the mobile application. When the memory pressure is large, the reserved number of objects in the to-be-compressed object pool is still increased, but the increase is small, so as to avoid excessive compression and reduce the performance of the mobile application.

[0086] Optionally, a memory pressure coefficient threshold value can also be set in advance. Only when the memory pressure coefficient exceeds the memory pressure coefficient threshold value, the theoretical reserved number is corrected. In this way, the reserved number of objects in the to-be-compressed object pool can be appropriately increased when the memory pressure is small, so as to ensure the performance of the mobile application. The theoretical reserved number can also be prevented from increasing when the memory pressure is too large, so as to ensure that the memory release demand is met in priority.

[0087] Based on the above embodiments, in the fourth embodiment of the present application, the same or similar contents as the above embodiments can be referred to the above description, and will not be described in detail. On this basis, please refer to Figure 4 , the memory optimization method of the mobile application object pool, step S40 includes steps S410-S460: Step S410: obtaining the last access time of each object in the to-be-compressed object pool.

[0088] It should be noted that the last access time refers to the specific time point when the object is last accessed, which is usually recorded in the form of a timestamp.

[0089] Step S420: determining the object whose interval between the current time and the last access time exceeds the idle time threshold value as the idle object according to the preset idle time threshold value.

[0090] It should be noted that the idle time threshold value refers to a preset time length, which is used to determine whether the object has been accessed for a long time. If the interval between the last access time of the object and the current time exceeds the idle time threshold value, the object is considered to be in an idle state.

[0091] For example, a 300-second sliding window is set to record object access events. When there is no object access record in the sliding window, that is, the interval between the last access time of the object and the current time exceeds 300 seconds, the object is considered to be idle, and the object is determined to be an idle object. This mechanism can identify objects that are no longer frequently used in time, so as to provide accurate target objects for subsequent memory optimization operations, ensure that memory resources can be reasonably released and reallocated, and improve the overall performance and resource utilization of the system.

[0092] Step S430: And / or, obtaining the access time record corresponding to the latest preset access number of each object in the object pool to be compressed.

[0093] It should be noted that the preset access number refers to the access number range set for evaluating the call frequency of the object, and the access time record refers to the specific access time point of the object at these access numbers.

[0094] As a feasible implementation, an access time record list is maintained for each object in the object pool, and each time the object is accessed, the current timestamp is added to the list. For example, the preset access number is set to 10, and when the object is accessed, the current timestamp is recorded, and it is ensured that only the latest 10 access timestamps are retained in the access time record list.

[0095] Step S440: According to the access time record, calculate the access interval of adjacent access times, and the standard deviation of the access interval.

[0096] It should be noted that the access interval refers to the difference between the access times of two adjacent accesses, and the standard deviation is a statistical quantity that measures the fluctuation degree of the access interval. The smaller the standard deviation, the more stable the access interval, and the more regular the call frequency.

[0097] As a feasible implementation, first traverse the access time record list of each object, calculate the difference between adjacent access times, and obtain the access interval list. Then, use statistical methods to calculate the standard deviation of the access interval list. For example, use the statistical library function in the programming language to calculate the standard deviation.

[0098] Step S450: Based on the standard deviation, quantize the call frequency weight of each object in the object pool to be compressed.

[0099] It should be noted that the call frequency weight is a quantitative value for measuring the regularity and frequency of object calls. The smaller the standard deviation, the higher the call frequency weight, indicating that the object is called more regularly; the larger the standard deviation, the lower the call frequency weight, indicating that the object is called less regularly.

[0100] In this embodiment, the call frequency weight = 1 / (0.1+standard deviation). In this way, the smaller the standard deviation, the higher the call frequency weight; the larger the standard deviation, the lower the call frequency weight.

[0101] Step S460: When the call frequency weight is lower than the preset call frequency threshold, the corresponding object is determined as the idle object.

[0102] It should be noted that the call frequency threshold is a preset quantitative value for determining whether the call frequency of the object is regular enough. If the call frequency weight is lower than the call frequency threshold, it means that the call of the object is irregular, and the object is a frequency idle object, which can be determined as an idle object to be compressed in memory optimization.

[0103] As a feasible implementation, the call frequency threshold can be preset, for example, 0.2. Then, the call frequency weight of each object is compared with the call frequency threshold. If the call frequency weight is lower than the call frequency threshold, the object is marked as an idle object. For example, if the call frequency weight of an object is 0.091, which is lower than the preset call frequency threshold 0.2, the object is determined as an idle object.

[0104] It can be understood that the idle state of the object and the idle state of the object pool can be determined by time idle and / or frequency idle.

[0105] The embodiment of the application provides a memory optimization device of a mobile application object pool, which comprises at least one processor and a memory connected with the at least one processor in communication; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the memory optimization method of the mobile application object pool in the above embodiment one.

[0106] Reference will be made to the accompanying drawings Figure 5 which shows a structural schematic diagram of the memory optimization device of the mobile application object pool suitable for implementing the embodiment of the application. The memory optimization device of the mobile application object pool in the embodiment of the application can comprise various hardware and software components for implementing the memory optimization method of the mobile application object pool. Figure 5 The shown memory optimization device of the mobile application object pool is only an example, and should not bring any limitation to the function and use range of the embodiment of the application.

[0107] As Figure 5As shown, the mobile application object pool memory optimization device can include a processing device 1001 (e.g., a central processor, a graphics processor, etc.) that can perform various appropriate actions and processes according to programs stored in a read-only memory (ROM) 1002 or programs loaded from a storage device 1003 into a random access memory (RAM) 1004. Various programs and data required for the operation of the mobile application object pool memory optimization device are also stored in the random access memory 1004. The processing device 1001, the read-only memory 1002, and the random access memory 1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, etc.; an output device 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; the storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the mobile application object pool memory optimization device to communicate with other devices wirelessly or by wire to exchange data. Although the mobile application object pool memory optimization device with various systems is shown in the figure, it should be understood that all the systems shown are not required to be implemented or possessed. More or fewer systems can be alternatively implemented or possessed.

[0108] In particular, the processes described above with reference to the flowcharts can be implemented as a computer software program according to embodiments of the present disclosure. For example, embodiments of the present disclosure include a computer program product comprising a computer program carried on a computer readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network through the communication device, or installed from the storage device 1003, or installed from the read-only memory 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the methods of embodiments of the present disclosure are performed.

[0109] The mobile application object pool memory optimization device provided by the present disclosure adopts the mobile application object pool memory optimization method in the above-mentioned embodiments, and can solve the technical problem that the object pool with a fixed capacity cannot dynamically adapt to the change of the memory requirement of the mobile application runtime. Compared with the prior art, the mobile application object pool memory optimization device provided by the present disclosure has the same beneficial effects as the mobile application object pool memory optimization method provided by the above-mentioned embodiments, and other technical features in the mobile application object pool memory optimization device are the same as the features disclosed in the previous embodiment method, which will not be described here.

[0110] It should be understood that various aspects of the disclosure can be implemented in hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any appropriate manner in any one or more embodiments or examples.

[0111] The above description is merely illustrative of the application and not restrictive.

[0112] The embodiments of the present application provide a computer readable storage medium having stored thereon computer readable program instructions (i.e., computer programs) for performing the memory optimization method of the mobile application object pool in the above embodiments.

[0113] The computer readable storage medium provided by the embodiments of the present application may, for example, be a U disk, but is not limited to an electric, magnetic, optical, electromagnetic, infrared, or semiconductor system, system, or device, or any combination thereof. More specific examples of the computer readable storage medium can include, but are not limited to, an electric connection with one or more conductive wires, a portable computer disk, a hard disk, a random access memory (RAM), a read only memory (ROM), an erasable programmable read only memory (EPROM or flash memory), an optical fiber, a portable compact disk read only memory (CD-ROM), an optical storage device, a magnetic storage device, or any appropriate combination thereof. In the embodiments, the computer readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, system, or device. The program code contained on the computer readable storage medium can be transmitted by any appropriate medium, including but not limited to an electric wire, an optical cable, a radio frequency (RF), or the like, or any appropriate combination thereof.

[0114] The above computer readable storage medium can be included in the memory optimization device of the mobile application object pool, or can exist separately and not be assembled into the memory optimization device of the mobile application object pool.

[0115] The computer readable storage medium stores one or more programs, which, when executed by the memory optimization device of the mobile application object pool, cause the memory optimization device of the mobile application object pool to: acquire a memory usage rate of a mobile application, and determine a memory compression level according to the memory usage rate; calculate a memory occupancy of a single object in a to-be-compressed object pool according to a data type of the object in the to-be-compressed object pool; determine a target reserved quantity of the object in the to-be-compressed object pool according to the memory occupancy and the memory compression level; detect an idle state of the object in the to-be-compressed object pool, and determine an idle object in the to-be-compressed object pool; and perform compression processing on the idle object in the to-be-compressed object pool according to the target reserved quantity.

[0116] Computer program code for carrying out operations of the present application can be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C++ or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code can execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or the connection can be made to an external computer (for example, through the Internet using an Internet Service Provider).

[0117] The computer program code can also be implemented more typically as one or more programs that are executed by one or more computers in the network. Each such program can be implemented in a high level procedural or object oriented programming language to

[0118] The modules described in the embodiments of the present application can be implemented in the form of software or in the form of hardware. In some cases, the names of the modules do not constitute a limitation on the modules themselves.

[0119] The computer readable storage medium provided in the present application is a computer readable storage medium, which stores computer readable program instructions (i.e., a computer program) for executing the memory optimization method of the mobile application object pool, and can solve the technical problem that the object pool with a fixed capacity cannot dynamically adapt to the memory requirement changes of the mobile application runtime. Compared with the prior art, the computer readable storage medium provided in the present application has the same beneficial effects as the memory optimization method of the mobile application object pool provided in the above embodiments, and will not be described here.

[0120] The computer program product provided in the embodiments of the present application comprises a computer program, which, when executed by a processor, implements the steps of the memory optimization method of the mobile application object pool as described above.

[0121] The computer program product provided in the present application can solve the technical problem that the object pool with a fixed capacity cannot dynamically adapt to the memory requirement changes of the mobile application runtime. Compared with the prior art, the computer program product provided in the embodiments of the present application has the same beneficial effects as the memory optimization method of the mobile application object pool provided in the above embodiments, and will not be described here.

[0122] The above is only the preferred embodiments of the present application, and does not limit the patent scope of the present application, and any equivalent structure or equivalent process transformation using the contents of the specification and drawings of the present application, or direct or indirect application in other related technical fields, are also included in the patent processing scope of the present application.

[0123] It should be noted that in this paper, the term "includes", "contains" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, article or system including a series of elements not only includes those elements, but also includes other elements not explicitly listed, or includes elements inherent to such process, method, article or system. Without more limitations, the element defined by the sentence "includes a" does not exclude the presence of other identical elements in the process, method, article or system including the element.

[0124] From the above description of the embodiments, those skilled in the art can clearly understand that the above embodiment method can be realized by means of software and a general hardware platform, of course, it can also be realized by hardware, but in many cases, the former is a better embodiment.

[0125] The above merely preferred embodiments of the present application and are not intended to limit the patent scope of the present application, any equivalent structure or equivalent process transformation made by using the content of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.

Claims

1. A method for memory optimization of mobile application object pooling, comprising: The memory optimization method of the mobile application object pool comprises: acquiring the memory usage of the mobile application, and determining a memory compression level according to the memory usage; calculating the memory occupation of a single object in the to-be-compressed object pool according to the data type of the object in the to-be-compressed object pool; determining the target reserved quantity of the object in the to-be-compressed object pool according to the memory occupation and the memory compression level; detecting the idle state of the object in the to-be-compressed object pool, and determining the idle object in the to-be-compressed object pool; performing compression processing on the idle object in the to-be-compressed object pool according to the target reserved quantity.

2. The method of Claim 1, wherein, Before the step of calculating the memory occupation of a single object in the to-be-compressed object pool according to the data type of the object in the to-be-compressed object pool, the memory optimization method of the mobile application object pool further comprises: determining the current active state of each object pool in the mobile application according to the calling frequency and / or the recent access time of each object pool; determining the to-be-compressed object pool according to the current active state.

3. The method of Claim 1, wherein, The step of calculating the memory occupation of a single object in the to-be-compressed object pool according to the data type of the object in the to-be-compressed object pool comprises: acquiring the data type of the object in the to-be-compressed object pool, and determining the memory occupation calculation rule corresponding to the data type; calculating the memory occupation of a single object in the to-be-compressed object pool according to the memory occupation calculation rule.

4. The method of Claim 3, wherein, The step of calculating the memory occupation of a single object in the to-be-compressed object pool according to the memory occupation calculation rule comprises: when the data type is an array type, acquiring the byte length of the array type, calculating the product of the byte length and the array length, and adding a preset byte head overhead as the memory occupation of a single object; when the data type is a set type, acquiring the element quantity contained in the set, and taking the product of the element quantity and a preset single-element byte number as the memory occupation of a single object; when the data type is a general type, taking a preset default object byte number as the memory occupation of a single object.

5. The method of Claim 1, wherein, The step of determining the target reserved quantity of the object in the to-be-compressed object pool according to the memory occupation and the memory compression level comprises: determining the memory compression ratio of the to-be-compressed object pool according to the memory compression level; calculating the to-be-compressed memory quantity of the to-be-compressed object pool according to the memory compression ratio and the current total memory occupation of the to-be-compressed object pool; determining the target reserved quantity of the object in the to-be-compressed object pool according to the to-be-compressed memory quantity and the memory occupation of a single object.

6. The method of Claim 5, wherein, The step of determining the target reserved quantity of the object in the to-be-compressed object pool according to the to-be-compressed memory quantity and the memory occupation of a single object comprises: determining the basic reserved quantity of the object in the to-be-compressed object pool, the basic reserved quantity being a preset minimum object quantity of the to-be-compressed object pool; calculating the theoretically reservable quantity of the object in the to-be-compressed object pool according to the to-be-compressed memory quantity and the memory occupation of a single object; The greater value between the basic reserved quantity and the theoretical reserved quantity is taken as the target reserved quantity.

7. The method of Claim 6, wherein, After the step of calculating the theoretical reserved quantity of objects in the object pool to be compressed according to the memory occupation of each object and the memory amount to be compressed, the memory optimization method of the mobile application object pool further comprises: calculating a memory pressure coefficient according to the maximum allowed memory of the object pool to be compressed and the current total memory occupation, the memory pressure coefficient being a ratio of a difference between the maximum allowed memory and the current total memory occupation to the maximum allowed memory; modifying the theoretical reserved quantity according to the memory pressure coefficient; the greater value between the basic reserved quantity and the modified theoretical reserved quantity is taken as the target reserved quantity.

8. The method of Claim 1, wherein, The step of detecting the idle state of the objects in the object pool to be compressed to determine the idle objects in the object pool to be compressed comprises: acquiring the last access time of each object in the object pool to be compressed; determining the object whose interval between the current time and the last access time exceeds the idle time threshold as the idle object according to a preset idle time threshold; and / or acquiring the access time record corresponding to the preset access frequency of each object in the object pool to be compressed; calculating the access interval of adjacent access times and the standard deviation of the access interval according to the access time record; quantifying the calling frequency weight of each object in the object pool to be compressed based on the standard deviation; determining the object corresponding to the calling frequency weight lower than the preset calling frequency threshold as the idle object.

9. A mobile application object pool memory optimization device, comprising: The memory optimization device of the mobile application object pool comprises a memory, a processor and a computer program stored on the memory and executable on the processor, the computer program being configured to implement the steps of the memory optimization method of the mobile application object pool according to any one of claims 1 to 8.

10. A storage medium, characterized by The storage medium is a computer readable storage medium, and the storage medium stores a computer program, the computer program being executed by the processor to implement the steps of the memory optimization method of the mobile application object pool according to any one of claims 1 to 8.