Method and device for reclaiming memory

Customized recycling time intervals and thresholds for memory blocks improve memory recycling efficiency by reducing cached memory and optimizing memory utilization.

CN117707988BActive Publication Date: 2024-12-03HONOR DEVICE CO LTD
View PDF 9 Cites 0 Cited by

Patent Information

Application Number
CN202310998357.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-08-08
Publication Date
2024-12-03
Estimated Expiration
2043-08-08

AI Technical Summary

Technical Problem

Existing memory recycling mechanisms, such as Scudo, suffer from untimely and inappropriate memory recycling, leading to inefficient memory utilization and performance loss due to caching of unused memory.

Method used

Implementing a method that sets customized recycling time intervals for different memory block classes based on their size, combined with periodic checks and thresholds, to optimize memory release to the operating system.

Benefits of technology

This approach enhances memory recycling efficiency by reducing cached memory and minimizing performance impact, ensuring timely release of memory blocks according to their usage patterns.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117707988B_ABST
    Figure CN117707988B_ABST
Patent Text Reader

Abstract

The present application provides a method and device for reclaiming memory, the method comprising: setting a reclaiming time interval for each class in a plurality of classes according to the size of a memory block type (class), wherein the reclaiming time intervals of at least two classes in the plurality of classes are different; and performing periodic memory inspection and reclaiming on the plurality of classes according to the reclaiming time intervals of the plurality of classes. The scheme mainly sets a suitable reclaiming time interval for each class at the class granularity, so that classes of different sizes have more suitable reclaiming time intervals, thereby effectively improving the technical problem of untimely reclaiming caused by the traditional unified fixed time interval for all classes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of memory recycling technology, and in particular to a method and device for recycling memory. Background Art

[0002] Scudo is a widely used native memory allocator. Each application needs to apply for and release memory through scudo to execute business. From the perspective of the operating system, the memory held by scudo is exclusively occupied by the process executing the business and cannot be reused by other processes. When the process no longer uses the memory, the less native memory the process holds, the better, so as to free up more memory space for other processes to use. However, as a native memory allocator, scudo does not release all the memory released by the business to the operating system, but reserves a part as cache. Scudo recycles memory through two methods: daily memory recycling (garbage collection, GC) and forced GC, and releases the memory recycling to the operating system. Daily GC is recycled at a default fixed time interval, but this recycling method does not take into account the different recycling requirements of different businesses of different applications, resulting in unsatisfactory recycling results. Forced GC triggers recycling by actively calling the forced GC interface, but this method may cause the recycling timing to be inappropriate. For example, for a foreground application, it is likely that it will need to reapply for memory just after the forced GC is completed, resulting in a large performance loss.

[0003] In short, the existing memory recycling mechanism has the problem of untimely memory recycling or inappropriate recycling timing, resulting in poor recycling effect. Summary of the invention

[0004] The present application provides a method and device for reclaiming memory, which can improve the memory recycling effect.

[0005] In a first aspect, a method for reclaiming memory is provided, the method comprising: setting a reclaiming time interval for each of a plurality of classes according to a size of a memory block type (class), wherein at least two of the plurality of classes have different reclaiming time intervals; and performing periodic memory checking and reclaiming on the plurality of classes according to the reclaiming time intervals of the plurality of classes.

[0006] In the technical solution of this application, the appropriate recycling time interval is set for each class at the class granularity, so that classes of different sizes have more appropriate recycling time intervals, thereby effectively improving the technical problem of untimely recycling caused by the traditional unified fixed time interval for all classes. In addition, compared with the traditional forced recycling mechanism, recycling according to the recycling time interval can also avoid the technical problem of inappropriate recycling timing caused by forced recycling.

[0007] In combination with the first aspect, in certain implementations of the first aspect, the multiple classes include a first class and a second class; the recycling time interval of the first class is greater than the recycling time interval of the second class; and the size of the first class is smaller than the size of the second class. That is, the larger the size of the class, the shorter the recycling time interval is set, and conversely, the smaller the size of the class, the longer the recycling time interval is set. It should be understood that the above-mentioned first class and second class are any classes among the multiple classes, as long as the above-mentioned relative relationship between the recycling time interval and the class size is satisfied.

[0008] Compared with large memory blocks (memory size, that is, classes with a larger number of bytes), small memory blocks (memory size, that is, classes with a larger number of bytes) are applicable to more businesses and are used more frequently. Therefore, setting a smaller recycling interval for larger classes can increase the probability of memory release and avoid cached memory not being released because it has not been used for a long time. For smaller classes, due to frequent use, they will be frequently checked and released after use, and there is no need to set a shorter recycling interval. In addition, the cache volume of larger classes will be higher, so setting a shorter recycling interval can ensure that memory can be released as much as possible.

[0009] In combination with the first aspect, in certain implementations of the first aspect, when performing periodic memory check and recycling on multiple classes according to the recycling time intervals of multiple classes, it may include: for any one of the multiple classes, performing a memory check on the class every recycling time interval of the any one of the classes; when the check result is that the number of free memory blocks meets the preset condition, the free memory is recycled and released to the operating system. In other words, for each class, a memory check may be performed every recycling time interval. Not every release will be checked and recycled, but a memory check is performed at the time of release every recycling time interval. Each release will generate some free memory blocks, and when these free memory blocks reach a certain number, they will become free pages. When the number of free pages reaches the tree age set by the preset condition, recycling can be triggered. Therefore, for each class, a memory check is performed every recycling time interval of the class. When it is found that the number of free memory blocks meets the preset condition, the free memory can be released to the operating system as free pages.

[0010] In combination with the first aspect, in certain implementations of the first aspect, the above method also includes: setting a recycling threshold for each class in multiple classes, and the recycling thresholds of at least two classes in the multiple classes are different; for any class in the multiple classes, when the capacity of the memory to be released of any class is greater than or equal to the recycling threshold of the class, the memory to be released of the class is recycled and released to the operating system.

[0011] The recycling threshold is set at the class granularity. For each class, when the capacity of unreleased memory (that is, free memory blocks) is greater than or equal to the recycling threshold of the class, memory recycling can be triggered even if the recycling interval is not reached. It should be understood that this method adds an additional threshold to trigger the recycling mechanism on the basis of recycling according to the customized recycling interval, so the number of recycling times triggered will increase and the memory cache will be reduced.

[0012] In combination with the first aspect, in certain implementations of the first aspect, the multiple classes include a third class and a fourth class, and the method further includes: during periodic memory check and recovery of the third class, periodically triggering memory check and recovery of the fourth class according to a horizontal check time interval, and the horizontal check time interval is a positive integer multiple of the recovery time interval of the third class.

[0013] The addition of a horizontal check mechanism can increase the frequency of class checks, thereby further increasing the chance of memory being released to the operating system and reducing cached memory. It should be understood that the third class and the fourth class can be at least one of the multiple classes mentioned above, and there is no other limitation, that is, the third class can be the same class as the first class or the second class, and the fourth class can be the same class as the first class or the second class. It should be understood that this method adds a horizontal check mechanism on the basis of recycling according to a personalized recycling time interval, so it will increase the number of additional triggered recycling times and reduce memory cache.

[0014] In one example, the size of the third class is smaller than that of the fourth class. Considering that smaller classes are used more frequently, free is triggered more frequently, so one or more larger classes can be checked horizontally in the smaller class.

[0015] In another example, each third class corresponds to one or two fourth classes. In order to make the horizontal check mechanism more reasonable, each third class can correspond to one or two fourth classes, that is, in each third class, one or two fourth classes paired with it are checked and recycled once every horizontal check interval. In this example, it is equivalent to trying to evenly distribute the horizontal check task, so that all classes have a relatively even chance of being checked horizontally, improving processing efficiency.

[0016] In combination with the first aspect, in some implementations of the first aspect, the above-mentioned multiple classes include class0 and at least one regular class, class0 is used to represent a management class, and the regular class is used to represent an unmanaged class, and the above-mentioned method further includes: performing a polling scan on at least one regular class in class0 according to a scanning cycle to determine the recycling time of at least one regular class, and the scanning cycle of each class in at least one regular class is a positive integer multiple of the recycling time interval of the class. Class0 is the management node of the memory allocator, and the allocation and release of other classes will trigger the allocation and release of class0, so the memory release of other classes (that is, regular classes, or unmanaged classes) can be triggered by the release behavior of class0. In order to reduce the performance impact, other classes can be scanned in a polling manner, and a scan is performed every one or more recycling time intervals of other classes. The current scanning class is recorded in class0, and the current scanning position and scanning step information are recorded in the corresponding class to determine the recycling time of other classes. It should be understood that this method is based on recycling according to a personalized customized recycling time interval, and an additional scanning mechanism is added, so additional recycling opportunities will be added, that is, the possibility of triggering recycling will increase.

[0017] In one example, the size of at least one of the regular classes is greater than or equal to the preset class size threshold. That is to say, instead of scanning all regular classes, only larger classes are scanned. This is because larger classes are more likely to cause more cache memory, smaller classes are used more frequently, memory is released more timely, and the amount of cache memory generated is relatively small, while larger classes are used less frequently, memory is not released in a timely manner, and the amount of cache memory generated is relatively large. Therefore, scanning only larger classes can reduce resource usage caused by scanning while further increasing the opportunity to release memory.

[0018] In a second aspect, a device for reclaiming memory is provided, the device comprising a unit composed of software and / or hardware for executing any one of the methods of the first aspect.

[0019] In a third aspect, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the electronic device is enabled to implement any one of the methods of the first aspect.

[0020] In a fourth aspect, a chip is provided, comprising a processor, wherein the processor is used to read and execute a computer program stored in a memory, and when the computer program is executed by the processor, the electronic device in which the chip is located can implement any one of the methods of the first aspect.

[0021] Optionally, the chip also includes a memory, and the memory is electrically connected to the processor.

[0022] Optionally, the chip may also include a communication interface.

[0023] According to a fifth aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by an electronic device, any one of the methods according to the first aspect can be implemented.

[0024] In a sixth aspect, a computer program product is provided, which includes a computer program, and when the computer program is executed by an electronic device, it can implement any one of the methods of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] Figure 1 It is a schematic diagram of the execution process of reclaiming memory using scudo.

[0026] Figure 2 This is a schematic diagram of the idle chain of scudo.

[0027] Figure 3 This is a schematic diagram of the daily recycling of scudo in the traditional scheme.

[0028] Figure 4 is a schematic flow chart of a method for reclaiming memory according to an embodiment of the present application. Figure 4 Each step is introduced.

[0029] Figure 5 It is a schematic diagram of the execution process of a method for reclaiming memory according to an embodiment of the present application.

[0030] Figure 6 This is an example diagram of a pairing situation of a horizontal inspection mechanism in an embodiment of the present application.

[0031] Figure 7 This is a schematic diagram of scanning and recycling a large block of classes through class0 according to an embodiment of the present application.

[0032] Figure 8 It is a schematic diagram of a device for reclaiming memory according to an embodiment of the present application.

[0033] Fig. 9 It is a schematic diagram of the hardware structure of an electronic device according to an embodiment of the present application.

[0034] Fig.10 It is a schematic diagram of the hardware structure of another electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0035] The scheme of the embodiment of the present application is introduced below with reference to the accompanying drawings.

[0036] Figure 1 This is a schematic diagram of the execution process of using scudo to reclaim memory. Figure 1 As shown in the figure, the application (application, app) in the application layer sends dynamic memory allocation (memory allocation, malloc) information to the memory allocator scudo in the native framework layer (native layer) to use the memory, and after use, the no longer needed memory is released (free) to scudo, which recycles it and releases the reclaimed memory to the memory management unit (that is, the memory management unit) in the system layer (kernel layer). Figure 1 mm module in the , that is, released to the operating system (OS), that is, Figure 1 As shown in the figure, the memory is released by calling the mmap and munmap / madvise interfaces.

[0037] During the memory recovery process, the memory held by scudo is exclusively occupied by the app process and cannot be reused by other processes. Therefore, when the process is no longer in use, the less native memory the process holds, the better, in order to free up more memory space for other processes. However, as a native memory allocator, scudo will not release all the business free memory to the OS, but will reserve a portion as cache.

[0038] Scudo releases memory to the OS through two methods: daily garbage collection (GC) and forced GC.

[0039] Daily GC (lazy GC): When the business calls the free interface to release memory, scudo's daily GC (synchronous operation) is triggered. However, not every free will trigger GC, because GC has to traverse the free list and sort out the free pages before releasing them to the OS. Every GC will cause performance problems. For this reason, scudo sets a recycling time interval. The current default recycling time interval is 1 second (s), that is, when freeing, it checks whether the memory block of this size has been recycled for more than 1s since the last time it was recycled. If not, it will not be recycled. The size of a free page (page) is 4 kilobytes.

[0040] Forced GC: scudo provides a forced GC interface mallopt (M_PURGE), which does not set the recycling trigger condition and releases the idle pages to the OS to the maximum extent. This interface needs to be called actively, but it has high business requirements, such as how to choose the time to force GC. Not all businesses can choose a suitable time. For the foreground application, it is very likely that the memory needs to be re-applied just after the GC is completed, which will cause performance loss.

[0041] In response to the above problems, this application provides a new method for reclaiming memory, which effectively improves the recycling effect by setting different recycling time intervals for different memory block types (classes), so that memory can be more reasonably recycled to the operating system. Different businesses will call different specific classes, and the recycling time interval is set according to the class granularity (level), which realizes the personalized and flexible customization of the business's recycled memory, thereby better balancing the execution performance of the business and optimizing the resource usage of the system.

[0042] In order to better understand the present application scheme, Figure 2 and Figure 3 Further introduction to scudo.

[0043] Figure 2 This is a schematic diagram of the idle chain of scudo. Figure 2 As shown in the figure, scudo divides memory blocks into 39 memory block types (classes) of different sizes, with the smallest class being 32 bytes and the largest class being 392k bytes. Different sizes of memory have different free chains (freelists), and when releasing memory, the memory blocks of the class are attached to the corresponding freelists. Here, taking class3 as an example, each free chain has multiple memory blocks (chunks) in each batch (transferbatch), which can also be called blocks.

[0044] Figure 3This is a schematic diagram of the daily recycling of scudo in the traditional solution. The bold arrows represent checkpoints (which can be understood as recycling points), and the time interval between checkpoints is 1s. The small arrows without bold represent each free. Each free will generate some free blocks. When these blocks reach the preset number of pages, that is, the page threshold, they will be released to the operating system. That is, when each checkpoint is free, it will count whether the number of pages of free blocks that can be recycled has been reached. If it has been reached, it will be recycled. If not, it will not be recycled. In the last 1s, the recycling time interval cannot be reached, that is, the last free occurs before the 1s interval. Therefore, the free blocks in the last second time interval will be cached. In the last 1s time interval, if a large amount of memory is released, it will cause more cache in scudo. In other words, when a process ends and reclaims the memory in progress, if a large amount of memory is released in the last second time interval, it will be left in scudo for cache because it will no longer be recycled. If there is too much cache left, it will inevitably fail to meet the expectation of the less cache, the better.

[0045] For example, in a test experiment, the three sizes of 96k, 128K, and 392K blocks of the layer compositor (surfaceflinger) process cached 6 megabytes (M), 8M, and 24M of memory respectively, as shown in Table 1.

[0046] Table 1

[0047] ClassId Size(B) Size in freelist(KB) 33 98320 6248 34 131088 8328 38 393232 24968

[0048] As can be seen from Table 1, the block of class33 (i.e., size 96k, i.e., 98320 in Table 1) is cached by 6M, the block of class34 (i.e., size 128k, i.e., 131088 in Table 1) is cached by 8M, and the block of class38 (i.e., size 392k, i.e., 393232 in Table 1) is cached by 24M. These memories cached in scudo cannot be used by other processes. This application aims to reduce the memory cached in scudo by more reasonably reclaiming memory, that is, to reduce the memory usage of scudo.

[0049] Figure 4 is a schematic flow chart of a method for reclaiming memory according to an embodiment of the present application. Figure 4 Each step is introduced.

[0050] S401. Set a recycling time interval for each of multiple classes according to the size of the class.

[0051] In the embodiment of the present application, at least two classes among the multiple classes have different recycling time intervals.

[0052] As described above, there are 39 classes for scudo, so the multiple classes here are at least two classes among the 39 classes. If the solution of the embodiment of the present application is applied to other memory allocators, the multiple classes here are at least two classes of the other memory allocator.

[0053] In one implementation, multiple classes include a first class and a second class; the recycling time interval of the first class is greater than the recycling time interval of the second class; the size of the first class is smaller than the size of the second class. That is to say, the larger the size of the class, the shorter the recycling time interval is set, and conversely, the smaller the size of the class, the longer the recycling time interval is set. For example, the recycling time interval of class2 can be set to 1 second, and the recycling time interval of class36 can be set to 0.5 seconds, etc. It should be understood that the above-mentioned first class and second class are any classes among multiple classes, as long as the relative relationship between the above-mentioned recycling time interval and class size is satisfied. It should be understood that the values ​​of the above-mentioned specific time intervals are only for example. In actual application, the values ​​can be taken according to actual needs, as long as they are set according to the size of the class and the time interval of the larger class is shorter.

[0054] Compared with large memory (memory size, i.e., classes with a large number of bytes), small memory (memory size, i.e., classes with a large number of bytes) is applicable to more businesses and is used more frequently. Therefore, setting a smaller recycling interval for larger classes can increase the probability of memory release and avoid the cached memory not being released because it has not been used for a long time. For smaller classes, due to frequent use, they will be frequently checked and released after use, so there is no need to set a shorter recycling interval. In addition, the cache volume of larger classes will be higher. For example, the several examples in Table 1 above all show that the cache volume of larger classes is higher, so setting a shorter recycling interval can ensure that the memory can be released as much as possible. For smaller classes, the cache volume is relatively low, so a relatively long recycling interval can be set. For example, for a 128k-byte class, according to the recycling interval of 1s, statistics show that the memory that cannot be recycled in the last 1s will cause 8M cache. When recycled according to the recycling interval of 0.5s, the memory that cannot be recycled in the last 0.5s may only cause 4M cache, which is significantly lower than 8M. For a 64-byte class, with a recycling time interval of 1 second, statistics show that the memory that cannot be recycled within the last second each time only causes 30 bytes of cache. There is no need to shorten the recycling time interval for the sake of this 30 bytes of memory, which increases the processing burden of the electronic device.

[0055] S402: Perform periodic memory check and recycling on multiple classes according to recycling time intervals of multiple classes.

[0056] That is to say, after setting the recycling time interval for different classes, you can perform periodic inspection and recycling according to the recycling time interval of each class.

[0057] In one implementation, step S402 may include: for any one of the multiple classes, a memory check is performed on the class at every recycling time interval of the class; when the check result is that the number of free memory blocks meets the preset conditions, the free memory is recycled and released to the operating system. That is to say, for each class, a memory check can be performed at every recycling time interval. Not every release will be checked and recycled, but a memory check is performed at the time of release at every recycling time interval. Each release will generate some free memory blocks, and when these free memory blocks reach a certain number, they will become free pages. When the number of free pages reaches the tree age set by the preset conditions, recycling can be triggered. Therefore, for each class, a memory check is performed at every recycling time interval of the class. When it is found that the number of free memory blocks meets the preset conditions, the free memory can be released to the operating system as free pages.

[0058] In one implementation, the method further includes:

[0059] S403, setting a recycling threshold for each of the multiple classes, wherein at least two of the multiple classes have different recycling thresholds;

[0060] S404: For any one of the multiple classes, when the capacity of the to-be-released memory of the any one of the classes is greater than or equal to the recycling threshold of the class, the to-be-released memory of the class is recycled and released to the operating system.

[0061] The recycling threshold is set at the class granularity. For each class, when the capacity of unreleased memory (that is, free memory blocks) is greater than or equal to the recycling threshold of the class, memory recycling can be triggered even if the recycling interval is not reached. It should be understood that this method adds an additional threshold to trigger the recycling mechanism on the basis of recycling according to the customized recycling interval, so the number of recycling times triggered will increase and the memory cache will be reduced.

[0062] In one implementation, the multiple classes include a third class and a fourth class, and the method further includes:

[0063] S405. During the periodic memory check and recycling of the third class, periodically trigger the memory check and recycling of the fourth class according to the horizontal check time interval, and the horizontal check time interval is a positive integer multiple of the recycling time interval of the third class.

[0064] The addition of a horizontal check mechanism can increase the frequency of class checks, thereby further increasing the chance of memory being released to the operating system and reducing cached memory. It should be understood that the third class and the fourth class can be at least one of the multiple classes mentioned above, and there is no other limitation, that is, the third class can be the same class as the first class or the second class, and the fourth class can be the same class as the first class or the second class. It should be understood that this method adds a horizontal check mechanism on the basis of recycling according to a personalized recycling time interval, so it will increase the number of additional triggered recycling times and reduce memory cache.

[0065] Considering that smaller classes are used more frequently, free is triggered more frequently, so one or more larger classes can be checked horizontally in a smaller class.

[0066] In one example, the size of the third class is smaller than the size of the fourth class.

[0067] It should be understood that the horizontal check time interval is a positive integer multiple of the recycling time interval, which can be understood as performing a horizontal check every one or more recycling time intervals. For example, if the recycling time interval of a class is 0.5 seconds, and the horizontal check time interval is 0.5*10=5 seconds, then a horizontal check is performed every 5 seconds, and a check of the class itself is performed every 0.5 seconds. Or it can be understood that within this class, the memory of this class is checked every 0.5 seconds to determine whether it needs to be recycled to the operating system, and the memory of one or more other classes paired with this class is checked every 5 seconds to determine whether it needs to be recycled to the operating system.

[0068] In another example, the number of the third class and the fourth class are allocated according to the number of all classes, and the number of the third class is less than or equal to the number of the fourth class. Taking the above scudo as an example, the number of the third class is less than the fourth class, and each third class corresponds to one or more fourth classes.

[0069] In order to make the horizontal check mechanism more reasonable, each third class can correspond to one or two fourth classes, that is, for each third class, at each horizontal check interval, one or two fourth classes paired with it will be checked and recycled. In this example, it is equivalent to trying to evenly distribute the horizontal check task, so that all classes have a relatively even chance of being horizontally checked, improving processing efficiency.

[0070] In another example, we can also consider the rule that larger classes are more likely to generate more memory, and smaller classes are more likely to be used. Pair the smallest class with the largest class, the second smallest class with the second largest class, and so on. This will further increase the chances of freeing up memory and reduce cache.

[0071] In another example, the frequency of use can also be considered, because for an electronic device, the types of installed applications are relatively stable, and the uninstallation or addition of individual applications will not bring about too much difference. Therefore, by counting the frequency of use of each class over a period of time, all classes can be sorted from high to low according to the frequency of use, and the class with a frequency greater than or equal to the preset frequency threshold is regarded as the third class, and the class with a frequency less than the preset frequency threshold is regarded as the fourth class. In this example, it is used that the more frequently a class is used, the less likely the cached memory will not be released, and the more frequently the memory recovery check occurs. Therefore, when checking such a class, horizontally checking other less frequently used classes can effectively increase the number of memory releases of the less frequently used classes and reduce the caching of the less frequently used classes.

[0072] In one implementation, the plurality of classes include class0 and at least one regular class, class0 is used to represent a management class, and the regular class is used to represent a non-management class, and the method further includes:

[0073] S406. Perform a polling scan on at least one regular class in class0 according to the scanning cycle to determine the recycling time of at least one regular class. The scanning cycle of each class in at least one regular class is a positive integer multiple of the recycling time interval of the class. Class0 is the management node of the memory allocator. The allocation and release of other classes will trigger the allocation and release of class0, so the memory release of other classes (that is, regular classes, or non-management classes) can be triggered by the release behavior of class0. In order to reduce the performance impact, other classes can be scanned in a polling manner. A scan is performed every recycling time interval of one or more other classes. The current scanning class is recorded in class0, and the current scanning position and scanning step information are recorded in the corresponding class to determine the recycling time of other classes. It should be understood that this method adds an additional scanning mechanism on the basis of recycling according to the personalized recycling time interval, so it will increase additional recycling opportunities, that is, the possibility of triggering recycling will increase.

[0074] In one example, the size of at least one of the regular classes is greater than or equal to the preset class size threshold. That is to say, instead of scanning all regular classes, only larger classes are scanned. This is because larger classes are more likely to cause more cache memory, smaller classes are used more frequently, memory is released more timely, and the amount of cache memory generated is relatively small, while larger classes are used less frequently, memory is not released in a timely manner, and the amount of cache memory generated is relatively large. Therefore, scanning only larger classes can reduce resource usage caused by scanning while further increasing the opportunity to release memory.

[0075] Figure 4 The method shown mainly sets a suitable recycling time interval for each class at the class granularity, so that classes of different sizes have more suitable recycling time intervals, thereby effectively improving the technical problem of untimely recycling caused by the traditional unified fixed time interval for all classes. In addition, the present application still adopts the method of recycling according to the recycling time interval, but only optimizes the setting of the time interval. Compared with the direct use of the traditional forced recycling mechanism, this method retains the method of recycling according to the recycling time interval, and can also avoid the technical problem of inappropriate recycling timing caused by forced recycling. In the traditional solution, the recycling time interval is globally unified, that is, the class granularity is not considered, and all classes use the same fixed time interval, that is, 1 second, which results in it being not suitable for larger classes and smaller classes. The present application makes the setting of the recycling time interval more refined, and sets the appropriate recycling time interval according to the size of each class, so as to achieve better recycling effect.

[0076] Figure 5 It is a schematic diagram of the execution process of a method for reclaiming memory according to an embodiment of the present application. Figure 5 It can be seen as Figure 4 An example of the method shown. Figure 5 Taking multiple classes including a 32-byte class and a 256k-byte class as an example, for the sake of ease of description, the 32-byte class will be referred to as class1 and the 256k-byte class will be referred to as class37.

[0077] from Figure 5It can be seen that the recycling interval of class1 is 1s, and the recycling interval of class37 is 0.5s. Class1 can be regarded as an example of the first class, and class37 can be regarded as an example of the second class. Figure 5 Where N1 and N2 are both positive integers. The meaning and related description of arrows and free can be found in Figure 3 , no more details.

[0078] The cache formed by all free blocks before the actual recycling occurs is memory that can be released to the operating system (OS) and will be released to the operating system at a certain time, but the cached memory has no chance to be released.

[0079] Figure 5 It also shows that when the free corresponding to the N1th recycling of class1 is executed, the horizontal recycling check between different classes is also triggered, that is, the memory check and recycling of class37 will be triggered. Since the memory that can be released will be released to the operating system when the recycling is checked according to the recycling time interval of the class itself, the horizontal recycling check is mainly for the memory that has no release opportunity, that is, the cached memory. During the horizontal check, class1 is regarded as the third class and class37 is regarded as the fourth class.

[0080] from Figure 5 It can be clearly seen that after setting different recycling time intervals, the possibility of class37 memory being released increases, and the cached memory will also decrease, because only the memory generated in less than 0.5 seconds after the last recycling is cached. Therefore, setting different recycling time intervals for different classes according to their sizes can effectively reduce the cached memory. In addition, the addition of the horizontal check mechanism further increases the inspection and recycling of cached memory that has not been released in class37, which can further reduce the cached memory.

[0081] It can be considered Figure 5 yes Figure 4 An example of the execution process of a specific example of steps S401-S402 and S405 in the method shown.

[0082] Figure 6 FIG. 1 is an example diagram of a pairing situation of a horizontal inspection mechanism in an embodiment of the present application. Figure 6 As shown, each smaller class corresponds to one or two larger classes. Figure 6 It is just an example, there is no limitation, and it only illustrates the pairing of some classes. In actual application, how to pair the classes can be set according to actual needs.

[0083] exist Figure 6 In the example, 15 smaller classes (third classes) and 24 larger classes (fourth classes) are shown. The class with a size of 32 bytes is paired with the class with a size of 392k (393232) bytes and the class with a size of 256k (262160) bytes, that is, the class with a size of 32 bytes is regarded as the third class, and the class with a size of 392k bytes and the class with a size of 256 bytes are regarded as the two fourth classes corresponding to the third class. The class with a size of 48 bytes is paired with the class with a size of 192k (196624) bytes and the class with a size of 160k (163856) bytes, that is, the class with a size of 48 bytes is regarded as the third class, and the class with a size of 192k bytes and the class with a size of 160k bytes are regarded as the two fourth classes corresponding to the third class. The class with a size of 64 bytes is paired with the class with a size of 128k bytes and a size of 96k bytes, that is, the class with a size of 64 bytes is regarded as the third class, and the class with a size of 128k (131088) bytes and a size of 96k (98320) bytes is regarded as the two fourth classes corresponding to the third class. The class with a size of 800 bytes is paired with the class with a size of 1104 bytes and a size of 1648 bytes, that is, the class with a size of 800 bytes is regarded as the third class, and the class with a size of 1104 bytes and a size of 1648 bytes is regarded as the two fourth classes corresponding to the third class. Other classes are not given examples one by one.

[0084] Figure 7 This is a schematic diagram of scanning and recycling a large class through class0 in an embodiment of the present application. In other words, Figure 7 This is an example of scanning only larger classes in the scanning mechanism. Figure 7 As shown, each class corresponds to a scanning cycle, and class0 performs polling scanning according to the scanning cycle of each class. Here, a large block class is taken as an example, which is a class greater than or equal to 1104 bytes, that is, the class size threshold preset in the above text is 1104.

[0085] The above mainly introduces the method of the embodiment of the present application in conjunction with the accompanying drawings. It should be understood that although the various steps in the flowcharts involved in the various embodiments described above are displayed in sequence, these steps are not necessarily performed in sequence in the order shown in the figure. Unless clearly stated in this article, there is no strict order restriction on the execution of these steps, and these steps can be performed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the various embodiments described above may include multiple steps or multiple stages, and these steps or stages are not necessarily performed at the same time, but can be performed at different times, and the execution order of these steps or stages is not necessarily performed in sequence, but can be performed in turn or alternately with other steps or at least a part of the steps or stages in other steps. The device of the embodiment of the present application is introduced below in conjunction with the accompanying drawings.

[0086] Figure 8 Schematic diagram of a memory recycling device according to an embodiment of the present application. Figure 8 As shown, the device 2000 includes a setting unit 2001 and a recycling unit 2002. The device 2000 can be integrated in electronic devices such as mobile phones, tablet computers, touch-screen laptops, computers, servers, etc.

[0087] The device 2000 can be used to execute the steps executed by the first device in any of the above methods for reclaiming memory. For example, the setting unit 2001 can be used to execute step S401, and the recycling unit 2002 can be used to execute step S402. For another example, the setting unit 2001 can be used to execute step S403, and the recycling unit 2002 can be used to execute step S404. For another example, the recycling unit 2002 can be used to execute steps S405 and S406.

[0088] In one implementation, the apparatus 2000 may further include a storage unit for storing relevant data. The storage unit may be integrated in any one of the above units, or may be a unit independent of all the above units.

[0089] Fig. 9 Schematic diagram of the hardware structure of an electronic device according to an embodiment of the present application. Fig. 9 As shown, the electronic device 3000 includes: at least one processor 3001 ( Fig. 9 Only one is shown in the figure) a processor, a memory 3002, and a computer program 3003 stored in the memory 3002 and executable on the at least one processor 3001, and when the processor 3001 executes the computer program 3003, the steps in any one of the above methods are implemented.

[0090] Those skilled in the art will understand that Fig. 9These are merely examples of electronic devices and do not constitute a limitation on the electronic device. In practice, the electronic device may include more or fewer components than those shown in the figure, or a combination of certain components, or different components. For example, it may also include input and output devices, network access devices, etc.

[0091] The processor 3001 may be a central processing unit (CPU), other general-purpose processors, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0092] In some embodiments, the memory 3002 may be an internal storage unit of the electronic device 3000, such as a hard disk or memory of the electronic device 3000. In other embodiments, the memory 3002 may also be an external storage device of the electronic device 3000, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the electronic device 3000. Optionally, the memory 3002 may also include both an internal storage unit of the electronic device 3000 and an external storage device. The memory 3002 is used to store an operating system, an application program, a boot loader, data, and other programs, such as the program code of the computer program. The memory 3002 may also be used to temporarily store data that has been output or is to be output.

[0093] Fig.10 Schematic diagram of the hardware structure of an electronic device according to an embodiment of the present application. Fig.10As shown, the electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. Among them, the sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.

[0094] It is to be understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.

[0095] For example, Fig.10 The processor 110 shown may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Among them, different processing units may be independent devices or integrated in one or more processors.

[0096] The controller may be the nerve center and command center of the electronic device 100. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.

[0097] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.

[0098] In some embodiments, the processor 110 may include one or more interfaces. The interface may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.

[0099] In some embodiments, the I2C interface is a bidirectional synchronous serial bus, including a serial data line (SDA) and a serial clock line (SCL). The processor 110 may include multiple groups of I2C buses. The processor 110 may be coupled to the touch sensor 180K, the charger, the flash, the camera 193, etc. through different I2C bus interfaces. For example, the processor 110 may be coupled to the touch sensor 180K through the I2C interface, so that the processor 110 communicates with the touch sensor 180K through the I2C bus interface, thereby realizing the touch function of the electronic device 100.

[0100] In some embodiments, the I2S interface can be used for audio communication. The processor 110 can include multiple I2S buses. The processor 110 can be coupled to the audio module 170 via the I2S bus to achieve communication between the processor 110 and the audio module 170.

[0101] In some embodiments, the audio module 170 can transmit audio signals to the wireless communication module 160 through the I2S interface to implement the function of answering calls through a Bluetooth headset.

[0102] In some embodiments, the PCM interface can also be used for audio communication, sampling, quantizing and encoding analog signals. The audio module 170 and the wireless communication module 160 can be coupled via a PCM bus interface.

[0103] In some embodiments, the audio module 170 can also transmit audio signals to the wireless communication module 160 through the PCM interface to implement the function of answering calls through a Bluetooth headset. It should be understood that both the I2S interface and the PCM interface can be used for audio communication.

[0104] In some embodiments, the UART interface is a universal serial data bus for asynchronous communication. The bus can be a bidirectional communication bus. It converts the data to be transmitted between serial communication and parallel communication. The UART interface is generally used to connect the processor 110 and the wireless communication module 160. For example, the processor 110 communicates with the Bluetooth module in the wireless communication module 160 through the UART interface to implement the Bluetooth function. In some embodiments, the audio module 170 can transmit an audio signal to the wireless communication module 160 through the UART interface to implement the function of playing music through a Bluetooth headset.

[0105] In some embodiments, the MIPI interface can be used to connect the processor 110 with peripheral devices such as the display screen 194 and the camera 193. The MIPI interface includes a camera serial interface (CSI), a display serial interface (DSI), etc. The processor 110 and the camera 193 communicate via the CSI interface to realize the shooting function of the electronic device 100. The processor 110 and the display screen 194 communicate via the DSI interface to realize the display function of the electronic device 100.

[0106] In some embodiments, the GPIO interface can be configured by software. The GPIO interface can be configured as a control signal or as a data signal. The GPIO interface can be used to connect the processor 110 with the camera 193, the display 194, the wireless communication module 160, the audio module 170, the sensor module 180, etc. The GPIO interface can also be configured as an I2C interface, an I2S interface, a UART interface, a MIPI interface, etc.

[0107] Exemplarily, the USB interface 130 is an interface that complies with the USB standard specification, and specifically can be a Mini USB interface, a Micro USB interface, a USB Type C interface, etc. The USB interface 130 can be used to connect a charger to charge the electronic device 100, and can also be used to transmit data between the electronic device 100 and a peripheral device. It can also be used to connect headphones to play audio through the headphones. The interface can also be used to connect other electronic devices, such as AR devices, etc.

[0108] It is understandable that the interface connection relationship between the modules illustrated in the embodiment of the present application is only a schematic illustration and does not constitute a structural limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.

[0109] The charging management module 140 is used to receive charging input from a charger. The charger may be a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 140 may receive charging input from a wired charger through the USB interface 130. In some wireless charging embodiments, the charging management module 140 may receive wireless charging input through a wireless charging coil of the electronic device 100. While the charging management module 140 is charging the battery 142, it may also power the electronic device through the power management module 141.

[0110] The power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140, and supplies power to the processor 110, the internal memory 121, the external memory, the display screen 194, the camera 193, and the wireless communication module 160. The power management module 141 can also be used to monitor parameters such as battery capacity, battery cycle number, battery health status (leakage, impedance), etc. In some other embodiments, the power management module 141 can also be set in the processor 110. In other embodiments, the power management module 141 and the charging management module 140 can also be set in the same device.

[0111] The wireless communication function of the electronic device 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor and the baseband processor.

[0112] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve the utilization of antennas. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In some other embodiments, the antenna can be used in combination with a tuning switch.

[0113] The mobile communication module 150 can provide a wireless communication solution applied to the electronic device 100, such as at least one of the following solutions: a second generation (2G) mobile communication solution, a third generation (3G) mobile communication solution, a fourth generation (5G) mobile communication solution, and a fifth generation (5G) mobile communication solution. The mobile communication module 150 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 150 may receive electromagnetic waves from the antenna 1, and perform filtering and amplification on the received electromagnetic waves, and then transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 150 may also amplify the signal modulated by the modulation and demodulation processor, and the amplified signal is converted into electromagnetic waves and radiated out through the antenna 1. In some embodiments, at least some of the functional modules of the mobile communication module 150 may be arranged in the processor 110. In some embodiments, at least some of the functional modules of the mobile communication module 150 may be arranged in the same device as at least some of the modules of the processor 110.

[0114] The modem processor may include a modulator and a demodulator. Among them, the modulator is used to modulate the low-frequency baseband signal to be sent into a medium-high frequency signal. The demodulator is used to demodulate the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After the low-frequency baseband signal is processed by the baseband processor, it is passed to the application processor. The application processor outputs a sound signal through an audio device (not limited to a speaker 170A, a receiver 170B, etc.), or displays an image or video through a display screen 194. In some embodiments, the modem processor may be an independent device. In other embodiments, the modem processor may be independent of the processor 110 and be set in the same device as the mobile communication module 150 or other functional modules.

[0115] The wireless communication module 160 can provide wireless communication solutions including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc., which are applied to the electronic device 100. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, modulates the frequency of the electromagnetic wave signal and performs filtering, and sends the processed signal to the processor 110. The wireless communication module 160 can also receive the signal to be sent from the processor 110, modulate the frequency of it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2.

[0116] In some embodiments, the antenna 1 of the electronic device 100 is coupled to the mobile communication module 150, and the antenna 2 of the electronic device 100 is coupled to the wireless communication module 160, so that the electronic device 100 can communicate with the network and other electronic devices through wireless communication technology. The wireless communication technology may include at least one of the following communication technologies: global system for mobile communications (GSM), general packet radio service (GPRS), code division multiple access (CDMA), wideband code division multiple access (WCDMA), time-division code division multiple access (TD-SCDMA), long term evolution (LTE), BT, GNSS, WLAN, NFC, FM, IR technology. The GNSS may include at least one of the following positioning technologies: global positioning system (GPS), global navigation satellite system (GLONASS), Beidou navigation satellite system (BDS), quasi-zenith satellite system (QZSS), and satellite based augmentation systems (SBAS).

[0117] The electronic device 100 implements the display function through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or change display information.

[0118] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode or an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), Mini-LED, Micro-Led, Micro-oLed, quantum dot light-emitting diodes (QLED), etc. In some embodiments, the electronic device 100 may include 1 or N display screens 194, where N is a positive integer greater than 1.

[0119] The electronic device 100 can realize the shooting function through ISP, camera 193, video codec, GPU, display screen 194 and application processor.

[0120] The ISP is used to process the data fed back by the camera 193. For example, when taking a photo, the shutter is opened, and the light is transmitted to the camera photosensitive element through the lens. The light signal is converted into an electrical signal, and the camera photosensitive element transmits the electrical signal to the ISP for processing and converts it into an image visible to the naked eye. The ISP can also perform algorithm optimization on the noise and brightness of the image. The ISP can also optimize the exposure, color temperature and other parameters of the shooting scene. In some embodiments, the ISP can be set in the camera 193.

[0121] The camera 193 is used to capture still images or videos. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the optical signal into an electrical signal, and then passes the electrical signal to the ISP to be converted into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into an image signal in a standard RGB, YUV or other format. In some embodiments, the electronic device 100 may include 1 or N cameras 193, where N is a positive integer greater than 1.

[0122] The digital signal processor is used to process digital signals, and can process not only digital image signals but also other digital signals. For example, when the electronic device 100 is selecting a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy.

[0123] Video codecs are used to compress or decompress digital videos. The electronic device 100 may support one or more video codecs. Thus, the electronic device 100 may play or record videos in a variety of coding formats, such as Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, MPEG4, etc.

[0124] NPU is a neural network (NN) computing processor. By drawing on the structure of biological neural networks, such as the transmission mode between neurons in the human brain, it can quickly process input information and can also continuously self-learn. Through NPU, applications such as intelligent cognition of electronic device 100 can be realized, such as image recognition, face recognition, voice recognition, text understanding, etc.

[0125] The external memory interface 120 can be used to connect an external memory card, such as a secure digital (SD) card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function, such as storing music, video and other files in the external memory card.

[0126] The internal memory 121 can be used to store computer executable program codes, which include instructions. The processor 110 executes various functional applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 121. The internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area may store data created during the use of the electronic device 100 (such as audio data, a phone book, etc.), etc. In addition, the internal memory 121 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.

[0127] The electronic device 100 can implement audio functions such as music playing and recording through the audio module 170 , the speaker 170A, the receiver 170B, the microphone 170C, the headphone jack 170D, and the application processor.

[0128] The audio module 170 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signals. The audio module 170 can also be used to encode and decode audio signals. In some embodiments, the audio module 170 can be arranged in the processor 110, or some functional modules of the audio module 170 can be arranged in the processor 110.

[0129] The speaker 170A, also called a "speaker", is used to convert an audio electrical signal into a sound signal. The electronic device 100 can listen to music or listen to a hands-free call through the speaker 170A.

[0130] The receiver 170B, also called a "earpiece", is used to convert audio electrical signals into sound signals. When the electronic device 100 receives a call or voice message, the voice can be received by placing the receiver 170B close to the human ear.

[0131] Microphone 170C, also called "microphone" or "microphone", is used to convert sound signals into electrical signals. When making a call or sending a voice message, the user can speak by putting their mouth close to microphone 170C to input the sound signal into microphone 170C. The electronic device 100 can be provided with at least one microphone 170C. In other embodiments, the electronic device 100 can be provided with two microphones 170C, which can not only collect sound signals but also realize noise reduction function. In other embodiments, the electronic device 100 can also be provided with three, four or more microphones 170C to collect sound signals, reduce noise, identify the sound source, realize directional recording function, etc.

[0132] The earphone interface 170D is used to connect a wired earphone and can be a USB interface 130 or a 3.5 mm open mobile terminal platform (OMTP) standard interface or a cellular telecommunications industry association of the USA (CTIA) standard interface.

[0133] The pressure sensor 180A is used to sense the pressure signal and can convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor 180A can be set on the display screen 194. There are many types of pressure sensors 180A, such as resistive pressure sensors, inductive pressure sensors, capacitive pressure sensors, etc. The capacitive pressure sensor can be a parallel plate including at least two conductive materials. When a force acts on the pressure sensor 180A, the capacitance between the electrodes changes. The electronic device 100 determines the intensity of the pressure according to the change in capacitance. When a touch operation acts on the display screen 194, the electronic device 100 detects the touch operation intensity according to the pressure sensor 180A. The electronic device 100 can also calculate the touch position according to the detection signal of the pressure sensor 180A. In some embodiments, touch operations acting on the same touch position but with different touch operation intensities can correspond to different operation instructions. For example, when a touch operation with a touch operation intensity less than the first pressure threshold acts on the short message application icon, an instruction to view the short message is executed. When a touch operation with a touch operation intensity greater than or equal to the first pressure threshold acts on the short message application icon, an instruction to create a new short message is executed.

[0134] The gyroscope sensor 180B can be used to determine the motion posture of the electronic device 100. In some embodiments, the angular velocity of the electronic device 100 around three axes (i.e., the x, y, and z axes) can be determined by the gyroscope sensor 180B. The gyroscope sensor 180B can be used for anti-shake shooting. For example, when the shutter is pressed, the gyroscope sensor 180B detects the angle of the electronic device 100 shaking, calculates the distance that the lens module needs to compensate based on the angle, and allows the lens to offset the shaking of the electronic device 100 through reverse movement to achieve anti-shake. The gyroscope sensor 180B can also be used for navigation and somatosensory game scenes.

[0135] The air pressure sensor 180C is used to measure air pressure. In some embodiments, the electronic device 100 calculates the altitude through the air pressure value measured by the air pressure sensor 180C to assist positioning and navigation.

[0136] The magnetic sensor 180D includes a Hall sensor. The electronic device 100 can use the magnetic sensor 180D to detect the opening and closing of the flip leather case. In some embodiments, when the electronic device 100 is a flip phone, the electronic device 100 can detect the opening and closing of the flip cover according to the magnetic sensor 180D; according to the detected opening and closing state of the leather case or the opening and closing state of the flip cover, set the flip cover automatic unlocking and other features.

[0137] The acceleration sensor 180E can detect the magnitude of the acceleration of the electronic device 100 in all directions (generally three axes). When the electronic device 100 is stationary, the magnitude and direction of gravity can be detected. It can also be used to identify the posture of the electronic device and is applied to applications such as horizontal and vertical screen switching and pedometers.

[0138] The distance sensor 180F is used to measure the distance. The electronic device 100 can measure the distance by infrared or laser. In some embodiments, when shooting a scene, the electronic device 100 can use the distance sensor 180F to measure the distance to achieve fast focusing.

[0139] The proximity light sensor 180G may include, for example, a light-emitting diode (LED) and a light detector, such as a photodiode. The light-emitting diode may be an infrared light-emitting diode. The electronic device 100 emits infrared light outward through the light-emitting diode. The electronic device 100 uses a photodiode to detect infrared reflected light from nearby objects. When sufficient reflected light is detected, it can be determined that there is an object near the electronic device 100. When insufficient reflected light is detected, the electronic device 100 can determine that there is no object near the electronic device 100. The electronic device 100 can use the proximity light sensor 180G to detect that the user holds the electronic device 100 close to the ear to talk, so as to automatically turn off the screen to save power. The proximity light sensor 180G can also be used in leather case mode and pocket mode to automatically unlock and lock the screen.

[0140] The ambient light sensor 180L is used to sense the ambient light brightness. The electronic device 100 can adaptively adjust the brightness of the display screen 194 according to the perceived ambient light brightness. The ambient light sensor 180L can also be used to automatically adjust the white balance when taking pictures. The ambient light sensor 180L can also cooperate with the proximity light sensor 180G to detect whether the electronic device 100 is in a pocket to prevent accidental touches.

[0141] The fingerprint sensor 180H is used to collect fingerprints. The electronic device 100 can use the collected fingerprint characteristics to implement fingerprint unlocking, access application locks, fingerprint photography, fingerprint call answering, etc.

[0142] The temperature sensor 180J is used to detect temperature. In some embodiments, the electronic device 100 uses the temperature detected by the temperature sensor 180J to execute a temperature processing strategy. For example, when the temperature reported by the temperature sensor 180J exceeds a threshold, the electronic device 100 reduces the performance of a processor located near the temperature sensor 180J to reduce power consumption and implement thermal protection. In other embodiments, when the temperature is lower than another threshold, the electronic device 100 heats the battery 142 to avoid abnormal shutdown of the electronic device 100 due to low temperature. In other embodiments, when the temperature is lower than another threshold, the electronic device 100 performs a boost on the output voltage of the battery 142 to avoid abnormal shutdown caused by low temperature.

[0143] The touch sensor 180K is also called a "touch panel". The touch sensor 180K can be set on the display screen 194, and the touch sensor 180K and the display screen 194 form a touch screen, also called a "touch screen". The touch sensor 180K is used to detect touch operations acting on or near it. The touch sensor can pass the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through the display screen 194. In other embodiments, the touch sensor 180K can also be set on the surface of the electronic device 100, which is different from the position of the display screen 194.

[0144] The bone conduction sensor 180M can obtain a vibration signal. In some embodiments, the bone conduction sensor 180M can obtain a vibration signal of a vibrating bone block of the vocal part of the human body. The bone conduction sensor 180M can also contact the human pulse to receive a blood pressure beat signal. In some embodiments, the bone conduction sensor 180M can also be set in an earphone and combined into a bone conduction earphone. The audio module 170 can parse out a voice signal based on the vibration signal of the vibrating bone block of the vocal part obtained by the bone conduction sensor 180M to realize a voice function. The application processor can parse the heart rate information based on the blood pressure beat signal obtained by the bone conduction sensor 180M to realize a heart rate detection function.

[0145] The key 190 includes a power key, a volume key, etc. The key 190 may be a mechanical key or a touch key. The electronic device 100 may receive key input and generate key signal input related to user settings and function control of the electronic device 100.

[0146] Motor 191 can generate vibration prompts. Motor 191 can be used for incoming call vibration prompts, and can also be used for touch vibration feedback. For example, touch operations acting on different applications (such as taking pictures, audio playback, etc.) can correspond to different vibration feedback effects. For touch operations acting on different areas of the display screen 194, motor 191 can also correspond to different vibration feedback effects. Different application scenarios (for example: time reminders, receiving messages, alarm clocks, games, etc.) can also correspond to different vibration feedback effects. The touch vibration feedback effect can also support customization.

[0147] The indicator 192 may be an indicator light, which may be used to indicate the charging status, power changes, messages, missed calls, notifications, etc.

[0148] The SIM card interface 195 is used to connect a SIM card. The SIM card can be connected to and separated from the electronic device 100 by inserting it into the SIM card interface 195 or pulling it out from the SIM card interface 195. The electronic device 100 can support 1 or N SIM card interfaces, where N is a positive integer greater than 1. The SIM card interface 195 can support Nano SIM cards, Micro SIM cards, SIM cards, and the like. Multiple cards can be inserted into the same SIM card interface 195 at the same time. The types of the multiple cards can be the same or different. The SIM card interface 195 can also be compatible with different types of SIM cards. The SIM card interface 195 can also be compatible with external memory cards. The electronic device 100 interacts with the network through the SIM card to implement functions such as calls and data communications. In some embodiments, the electronic device 100 uses an eSIM, i.e., an embedded SIM card. The eSIM card can be embedded in the electronic device 100 and cannot be separated from the electronic device 100.

[0149] It should be noted that the information interaction, execution process, etc. between the above-mentioned devices / units are based on the same concept as the method embodiment of the present application. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.

[0150] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.

[0151] An embodiment of the present application also provides an electronic device, which includes: at least one processor, a memory, and a computer program stored in the memory and executable on the at least one processor, wherein when the processor executes the computer program, the electronic device can implement the steps in any of the above methods.

[0152] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by an electronic device, the steps in the above-mentioned method embodiments can be implemented.

[0153] An embodiment of the present application provides a computer program product, which includes a computer program. When the computer program is executed by an electronic device, the steps in the above-mentioned method embodiments can be implemented.

[0154] If the integrated unit is implemented in the form of 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 present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may at least include: any entity or device that can carry the computer program code to the camera / electronic device, recording medium, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium. For example, a USB flash drive, a mobile hard disk, a magnetic disk or an optical disk. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electric carrier signals and telecommunication signals.

[0155] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0156] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0157] In the embodiments provided in the present application, it should be understood that the disclosed devices / equipment and methods can be implemented in other ways. For example, the device / equipment embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

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

[0159] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.

[0160] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0161] As used in the specification and appended claims of this application, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.

[0162] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.

[0163] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.

[0164] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.

Claims

1. A method for reclaiming memory, It is characterized in that include: According to the size of the memory block type class, a recycling time interval of each class in the multiple classes is set, and the recycling time intervals of at least two classes in the multiple classes are different; Performing periodic memory check and recycling on the multiple classes according to recycling time intervals of the multiple classes; The multiple classes include a third class and a fourth class, and the method further includes: During the periodic memory check and recycling of the third class, the memory check and recycling of the fourth class is periodically triggered according to a horizontal check time interval, and the horizontal check time interval is a positive integer multiple of the recycling time interval of the third class.

2. The method according to claim 1, It is characterized in that The multiple classes include a first class and a second class; a recycling time interval of the first class is greater than a recycling time interval of the second class; and a size of the first class is smaller than a size of the second class.

3. The method according to claim 1, It is characterized in that The performing periodic memory check and recycling on the multiple classes according to the recycling time intervals of the multiple classes includes: For any one of the multiple classes, perform a memory check on the class at every recycling time interval of the class; When the check result shows that the number of free memory blocks meets the preset conditions, the free memory is reclaimed and released to the operating system.

4. The method according to claim 1, It is characterized in that The method further comprises: Setting a recycling threshold for each of the multiple classes, wherein at least two of the multiple classes have different recycling thresholds; For any one of the multiple classes, when the capacity of the to-be-released memory of the any one of the classes is greater than or equal to the recycling threshold of the class, the to-be-released memory of the class is recycled and released to the operating system.

5. The method according to any one of claims 1 to 4, It is characterized in that The size of the third class is smaller than the size of the fourth class.

6. The method according to any one of claims 1 to 4, It is characterized in that Each of the third classes corresponds to one or two of the fourth classes.

7. The method according to any one of claims 1 to 4, It is characterized in that The multiple classes include class0 and at least one regular class, the class0 is used to represent a management class, and the regular class is used to represent a non-management class, and the method further includes: The at least one regular class in the class0 is polled and scanned according to a scanning period to determine a recycling timing of the at least one regular class, and the scanning period of each class in the at least one regular class is a positive integer multiple of the recycling time interval of the class.

8. The method according to claim 7, It is characterized in that The size of the at least one regular class is greater than or equal to a preset class size threshold.

9. A device for reclaiming memory, It is characterized in that include: A setting unit, configured to set a recycling time interval of each class in a plurality of classes according to a size of a memory block type class, wherein at least two classes in the plurality of classes have different recycling time intervals; A recycling unit, configured to perform periodic memory check and recycling on the multiple classes according to recycling time intervals of the multiple classes; The multiple classes include a third class and a fourth class, and the recycling unit is further used for: During the periodic memory check and recycling of the third class, the memory check and recycling of the fourth class is periodically triggered according to a horizontal check time interval, and the horizontal check time interval is a positive integer multiple of the recycling time interval of the third class.

10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the computer program, the electronic device implements the method according to any one of claims 1 to 8.

11. A computer-readable storage medium storing a computer program. It is characterized in that When the computer program is executed by an electronic device, the method according to any one of claims 1 to 8 is implemented.

Citation Information

Patent Citations

  • Memory recovery method and device and electronic equipment

    CN110727605A

  • Electronic equipment, memory recovery method thereof and medium

    CN114253872A

  • Structure of small object internal memory with high-speed fragments and allocation method thereof

    CN1567250A

  • Method for processing application, electronic device, and computer-readable storage medium

    IN201814048951A

  • Continuous media priority aware storage scheduler

    US20050044289A1