Memory management method, electronic equipment, storage medium and program product

By identifying and separating hot objects and cold objects in electronic devices and storing them in different memory areas respectively, and prioritizing the compression of the cold objects, the system load increase caused by random compression and decompression is solved, and the response speed and usage performance of electronic devices are improved.

CN119576806AActive Publication Date: 2025-03-07HONOR DEVICE CO LTD
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202510141512.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-08
Publication Date
2025-03-07
Estimated Expiration
2045-02-08

AI Technical Summary

Technical Problem

In the prior art, random compression and decompression of memory pages lead to an increase in system load, reducing the response speed of electronic devices, and affecting the performance of usage.

Method used

By detecting the application startup status of the electronic device, the hot object and the cold object are determined, and they are transferred to different target areas respectively, and the memory area corresponding to the cold object is compressed first.

Benefits of technology

The probability of compressed areas being decompressed due to cold objects being accessed is reduced, the response speed of electronic devices is improved, and the performance of use is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119576806A_ABST
    Figure CN119576806A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of memory management, and discloses a memory management method, electronic equipment, a storage medium and a program product. In the method, after the electronic equipment detects that a first application program is in a starting state, a first object belonging to a first category in a plurality of application objects of the first application program can be transferred and stored from a first initial area to a first target area; and transferring and storing a second object belonging to the second category in the plurality of application objects from the second initial area to the second target area. Wherein the access probability of the first object is greater than the access probability of the second object, and the electronic equipment can preferentially compress the second target area under the condition that the memory is insufficient. According to the method, the probability that the second object in the compressed second target area is accessed is small, the probability that the compressed second target area is decompressed is reduced, and the response speed of the electronic equipment is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of memory management technology, and in particular to a memory management method, electronic device, storage medium and program product. Background Art

[0002] When an application of an electronic device is in the startup state, different objects corresponding to the application are created according to different task requirements. For example, if the task is to add a new contact A in an instant messaging application, the application can create an object corresponding to contact A to store information corresponding to contact A. For another example, if the task is to load a corresponding configuration file when the instant messaging application is started, the application can create a configuration object to store and manage the configuration file.

[0003] It can be understood that each object created by an application will be stored in the memory of the electronic device and occupy a certain size of memory space. Specifically, the memory can be divided into multiple memory pages of fixed size, and the objects of the application can be randomly stored in different memory pages. Since the objects of the application include objects with a higher access probability (hereinafter referred to as hot objects) and objects with a lower access probability (hereinafter referred to as cold objects), each memory page may store hot objects and / or cold objects. If the electronic device has insufficient memory space available, the electronic device will randomly compress some of the multiple memory pages to increase the available memory space.

[0004] It is understandable that if one or more objects in a compressed memory page need to be accessed, the compressed memory page needs to be decompressed. Therefore, in the above-mentioned scheme of randomly compressing memory pages, the probability that hot objects are included in the compressed memory page is relatively high, which leads to a high probability that the compressed memory page is decompressed because the hot objects need to be accessed. This method of repeatedly compressing and decompressing memory pages will increase the load on the system, reduce the response speed of the electronic device, and thus affect the performance of the electronic device. Summary of the invention

[0005] The embodiments of the present application provide a memory management method, an electronic device, a storage medium, and a program product to improve the response speed of the electronic device, thereby improving the performance of the electronic device.

[0006] In a first aspect, the present application provides a memory management method, which is applied to an electronic device, and the method includes: detecting that a first application of the electronic device is in a startup state, wherein the first application corresponds to multiple application objects; determining a first object belonging to a first category among the multiple application objects, and transferring the first object from a first initial area to a first target area; determining a second object belonging to a second category among the multiple application objects, and transferring the second object from a second initial area to a second target area; performing a compression operation on the second target area, wherein the probability of the first object of the first category being accessed is greater than the probability of the second object of the second category being accessed.

[0007] The method stores the first object and the second object in different target areas (i.e., the first target area and the second target area), and preferentially compresses the second target area corresponding to the second object. Since the probability of the second object in the second target area being accessed is relatively small, the method can reduce the probability of the compressed second target area being decompressed due to the second object being accessed, and can improve the response speed of the electronic device, thereby improving the performance of the electronic device.

[0008] In a possible implementation of the first aspect, before determining a first object belonging to the first category among multiple application objects, the method further includes: detecting that a remaining memory of the electronic device meets a memory cleanup condition.

[0009] In this case, after the electronic device determines the first object and the second object, it can directly perform a compression operation on the second target area.

[0010] In a possible implementation of the first aspect, before determining a first object belonging to a first category among multiple application objects, the method also includes: detecting a first instruction, or detecting that the time interval between the current moment and the first moment is greater than or equal to a time threshold, the first moment being the starting moment when the first application is in a startup state; before performing a compression operation on the second target area, the method also includes: detecting that the remaining memory of the electronic device meets a memory cleanup condition.

[0011] In this case, the electronic device may start to determine the first object and the second object when the first instruction is detected or the time interval is greater than or equal to the time threshold, and then perform a compression operation on the second target area when it is determined that the remaining memory meets the memory cleaning condition.

[0012] In a possible implementation of the first aspect, the multiple application objects include multiple foreground objects and multiple background objects, the multiple foreground objects are objects created when the first application is running in the foreground, and the multiple background objects are objects created when the first application is running in the background.

[0013] In a possible implementation of the first aspect, when a first application is in a background running state, determining a first object belonging to a first category among multiple application objects includes: treating the multiple background objects as the first object belonging to the first category; and determining a second object belonging to a second category among multiple application objects includes: treating the multiple foreground objects as the second objects belonging to the second category.

[0014] It is understood that the startup state of the first application includes a foreground running state or a background running state. That is, no matter whether the electronic device detects that the first application is in the foreground running state or the background running state, it can be determined that the first application is in the startup state, and then the first object and the second object are determined.

[0015] Since the foreground object is responsible for displaying information and receiving user input, such as the display window and related controls of the application, when the first application is running in the background, the probability of the foreground object being accessed is small, and the probability of the background object being accessed is large. When the first application is in the background running state, the electronic device can regard the background object as the first object belonging to the first category; and regard multiple foreground objects as the second objects belonging to the second category.

[0016] In a possible implementation of the first aspect, when a first application is in a background running state, determining a first object belonging to a first category among multiple application objects includes: determining a first foreground object belonging to the first category among multiple foreground objects; treating multiple background objects and the first foreground object as the first object belonging to the first category; determining a second object belonging to a second category among multiple application objects includes: treating objects among the multiple foreground objects except the first foreground object as second objects belonging to the second category.

[0017] It is understandable that when the first application is running in the background, there may still be some foreground objects with a high probability of being accessed. Therefore, in this method, in addition to directly treating multiple background objects as first objects belonging to the first category, the electronic device can also determine the first foreground object belonging to the first category from multiple foreground objects, and then treat the multiple background objects and the first foreground object together as the first object.

[0018] In a possible implementation of the first aspect, determining a first foreground object belonging to a first category among multiple foreground objects includes: obtaining at least one creation thread corresponding to a first application, the at least one creation thread being used to create multiple foreground objects; determining at least one first creation object created by a first creation thread among the at least one creation thread, the at least one first creation object belonging to multiple foreground objects; corresponding to the first number of objects accessed in the at least one first creation object, a ratio of a second number of the at least one first creation object being greater than a first ratio threshold, treating the at least one first creation object as a first foreground object belonging to the first category.

[0019] It can be understood that if the ratio of the first number to the second number is greater than the first ratio threshold, it means that the first created objects created by the first created thread are more likely to be accessed when the first application is running in the background, then at least one first created object corresponding to the first created thread will be used as the first foreground object.

[0020] In the method, when the electronic device determines that the ratio of the number of objects that have been visited in at least one first created object is greater than a first ratio threshold, the at least one first created object is taken as a first object and transferred to the first target area. In this case, the objects in the foreground object other than the first created object whose corresponding ratio is greater than the first ratio threshold will be taken as second objects and stored in the second target area.

[0021] In this way, the probability of the second object in the second target area being accessed is relatively small, which can reduce the probability of the compressed second target area being decompressed again due to the second object being accessed, thereby improving the response speed of the electronic device and the performance of the electronic device.

[0022] In a possible implementation of the first aspect, determining a first foreground object belonging to a first category among multiple foreground objects also includes: obtaining at least one access thread corresponding to at least one first created object, the at least one access thread being used to access the at least one first created object; determining a third number of first created objects accessed by a first access thread among the at least one access thread; and corresponding to a ratio of the third number to the second number being greater than a second ratio threshold, treating the foreground object accessed by the first access thread as the first foreground object belonging to the first category.

[0023] In the method, the electronic device may determine the first foreground object based on the creation thread and then determine the first foreground object based on the access thread.

[0024] It can be understood that if the ratio of the third number to the second number is greater than the second ratio threshold, it means that the foreground objects accessed by the first access thread are more likely to be accessed when the first application is running in the background. Therefore, the foreground objects accessed by the first access thread can all be treated as first foreground objects and transferred to the first target area.

[0025] In this way, the probability of the second object in the second target area being accessed is further reduced, and the probability of the compressed second target area being decompressed again due to the second object being accessed can be further reduced, thereby improving the response speed of the electronic device and the performance of the electronic device.

[0026] In a possible implementation of the first aspect, the object header of each application object among multiple application objects includes a creation thread data bit and an access thread data bit; obtaining at least one creation thread corresponding to a first application program includes: determining the creation thread of each application object based on data corresponding to the creation thread data bit in each application object, and obtaining at least one creation thread for creating multiple application objects; obtaining at least one access thread corresponding to at least one first creation object includes: determining the access thread of each first creation object based on data corresponding to the access thread data bit of each first creation object in at least one first creation object, and obtaining at least one access thread for accessing at least one first creation object.

[0027] As later Figure 6 and Fig.12 As shown, when creating an application object, the electronic device can add a creation thread data bit and an access thread data bit in the object header. The creation thread data bit is used to store (or record) the creation thread of the application object. The access thread data bit is used to store (or record) the access thread of the application object. In this way, the electronic device can determine the creation thread and access thread of the application object based on the data corresponding to the creation thread data bit and the data corresponding to the access thread data bit. It can be understood that in the structure of the application object before and after adding the creation thread data bit and the access thread data bit, the size of the data part remains unchanged, so that the data carrying capacity of the application object can be ensured to remain unchanged.

[0028] Using Android in electronic devices TM Taking the system as an example, if an electronic device wants to change the data structure of an application object, it can modify the creation logic of the application object in the Android runtime (ART), such as recording the creation thread corresponding to the application object when the application object is created, and recording the access thread of the application object when the application object is accessed.

[0029] In some embodiments, the electronic device may modify the creation logic of the application object in the Android operating environment based on the switch interpreter. For example, the electronic device modifies the acquisition instruction (such as the sget instruction, the aget instruction, etc.) based on the switch interpreter, so that the electronic device can obtain the creation thread and access thread corresponding to the application object based on the modified acquisition instruction.

[0030] The method changes the creation logic of the application object so that the electronic device can obtain the creation thread and the access thread through the data structure of the application object.

[0031] In a possible implementation of the first aspect, determining a first object belonging to a first category among multiple application objects includes: obtaining an object type set including multiple object types; treating an application object among the multiple application objects whose object type belongs to the object type set as the first object belonging to the first category; determining a second object belonging to a second category among the multiple application objects includes: treating objects among the multiple application objects other than the first object as the second objects belonging to the second category.

[0032] It can be understood that the object type set can be a predetermined object type of the first object. Therefore, if the electronic device determines that the object type of a certain application object belongs to the object type set, it can be determined that the application object is the first object. If the electronic device determines that the object type of a certain application object does not belong to the object type set, it can be determined that the application object is not the first object, but the second object.

[0033] In this way, the electronic device can determine the first object and the second object from multiple application objects based on a predetermined set of object types. The first object and the second object can be determined quickly and with high accuracy. When the second object is determined with high accuracy, the probability of the second object in the second target area being accessed is reduced, and the probability of the compressed second target area being decompressed again due to the second object being accessed can be reduced, thereby improving the response speed of the electronic device and the performance of the electronic device.

[0034] In a second aspect, the present application provides an electronic device, comprising: one or more processors; one or more memories; one or more memories storing one or more programs, and when the one or more programs are executed by one or more processors, the electronic device executes the memory management method of the first aspect and any possible implementation of the first aspect.

[0035] In a third aspect, the present application provides a storage medium having instructions stored thereon, which, when executed on an electronic device, causes the electronic device to execute the memory management method of the first aspect and any possible implementation of the first aspect.

[0036] In a fourth aspect, the present application provides a program product, which includes: instructions, when the instructions are executed on an electronic device, the electronic device executes the memory management method of the first aspect and any possible implementation of the first aspect.

[0037] Among them, the beneficial effects of the second to fourth aspects can refer to the beneficial effects of the first aspect and any possible implementation of the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] Figure 1 According to some embodiments of the present application, a schematic diagram of a storage method of application objects of a virtual machine and a (physical) memory in an electronic device is shown; Figure 2 According to some embodiments of the present application, a flowchart of a memory management method provided by the present application is shown; Figure 3 According to some embodiments of the present application, a schematic diagram of a storage transfer process of a first object and a second object is shown; Figure 4 According to some embodiments of the present application, a flowchart of a method for determining a first foreground object is shown; Figure 5 According to some embodiments of the present application, a flowchart of a method for determining at least one creation thread is shown; Figure 6 According to some embodiments of the present application, a schematic diagram of the structure of an application object before and after adding a create thread data bit is shown; Figure 7 According to some embodiments of the present application, a flowchart of another method for determining a first foreground object is shown; Figure 8 According to some embodiments of the present application, a flow chart of a method for determining a target creation thread is shown; Fig. 9 According to some embodiments of the present application, a flowchart of a method for recording thread information is shown; Fig.10 According to some embodiments of the present application, a flowchart of another method for determining a first foreground object is shown; Fig.11 According to some embodiments of the present application, a flow chart of a method for determining at least one access thread is shown; Fig.12 According to some embodiments of the present application, a schematic diagram of the structure of an application object before and after adding access thread data bits is shown; Fig.13According to some embodiments of the present application, a flow chart of a method for determining an access thread of an accessed application object is shown; Fig.14 According to some embodiments of the present application, a flowchart of a method for determining an initial object type is shown; Fig.15 According to some embodiments of the present application, another flowchart of a memory management method provided by the present application is shown; Fig.16 According to some embodiments of the present application, a schematic diagram of a virtual machine and a memory after transferring an application object to another storage is shown; Fig.17 According to some embodiments of the present application, another schematic diagram of a virtual machine and a memory after transferring an application object to another storage is shown; Fig.18 According to some embodiments of the present application, another flowchart of a memory management method provided by the present application is shown; Fig.19 According to some embodiments of the present application, a schematic diagram of changes in application objects during a memory management process is shown; Fig. 20 According to some embodiments of the present application, a schematic structural diagram of an electronic device is shown. DETAILED DESCRIPTION

[0039] Illustrative embodiments of the present application include, but are not limited to, a memory management method, an electronic device, a storage medium, and a program product.

[0040] To facilitate understanding, the specific terms involved in this application are first explained below.

[0041] Application object: A specific instance generated by instantiation (such as using the "new" keyword) according to the class definition during the running process of the application. Each application object has its own properties and behaviors, and different application objects can perform different tasks after being called. Take the task of adding contact A in the instant messaging application as an example. Assuming that there is already a class: contact (name, age), the application object created by the application under this task can be: contact A = contact (Zhang San, thirty).

[0042] In this application, the application objects of an application can be divided into foreground objects and background objects according to the time of creation. Among them, the foreground object is the application object created when the application is in the foreground running state, for example, it can be an application object that directly interacts with the user, responsible for displaying information and receiving user input, such as the display window and related controls of the application.

[0043] Background objects are application objects created when an application is in the background. They do not interact directly with the user and usually perform tasks such as logic processing, data storage and retrieval in the background. When the application interface of an application is displayed on the display screen of an electronic device, the application is in the foreground running state; when the application interface of an application is not displayed on the display screen of an electronic device and the application is not closed, the application is in the background running state.

[0044] In this application, the application objects of the application program can be divided into hot objects and cold objects according to the probability of being accessed, and both hot objects and cold objects belong to the reference chain corresponding to the root object, that is, both have the possibility of being accessed by other application objects. Among them, hot objects represent application objects with a high access probability (such as greater than the access probability threshold), and cold objects represent application objects with a low access probability (such as greater than 0 and less than or equal to the access probability threshold). It can be understood that the access probability represents the probability of a certain application object being accessed by other application objects.

[0045] Memory page: A unit of memory in an electronic device. Each memory page occupies a fixed size of memory in the electronic device and can store application objects of the application program. When the available memory space (i.e., remaining memory) of the electronic device is insufficient, the memory page can be compressed to increase the available memory space. If the application object in the compressed memory page needs to be accessed, the compressed memory page needs to be decompressed.

[0046] Virtual machine: A complete computer system simulated by software. In this application, the process of an application object (such as an access object) of an application program accessing another application object (such as an accessed object) is implemented based on a virtual machine. Specifically, the virtual address of the accessed object is stored inside the virtual machine. When the virtual machine accesses the accessed object, the virtual address can be converted into the physical address of the physical memory of the electronic device (that is, the memory that actually stores the object instance). In this way, the virtual machine can successfully access the accessed object based on the physical address of the accessed object in the physical memory.

[0047] Figure 1 A schematic diagram showing a storage method of application objects in a virtual machine and (physical) memory in an electronic device. Figure 1 As shown, the virtual machine stores multiple application objects (such as Figure 1 In addition, the application objects in the memory are randomly stored in different memory pages. Figure 1 As shown, objects A, B and C can be stored in memory page a of the memory; objects D, E and F can be stored in memory page b of the memory. It can be understood that the storage method of application objects in the memory in different memory pages is managed by the kernel of the electronic device.

[0048] Based on the above Figure 1 From the different storage methods of the virtual machine and the application objects in the memory shown, it can be seen that the virtual machine accesses the accessed object in units of application objects, while the memory stores the application objects in units of memory pages. Figure 1 For example, if memory page a in is compressed, if object A is a hot object, which means that the probability of the virtual machine accessing object A is high, then the probability of memory page a being decompressed is high. This method of repeatedly compressing and decompressing memory pages will increase the system load, reduce the response speed of electronic devices, and thus affect the performance of electronic devices.

[0049] Therefore, in order to solve the above technical problems, the present application provides a method. The method stores application objects with a higher access probability (i.e., hot objects) and application objects with a lower access probability (i.e., cold objects) in different memory areas (such as memory pages). In this way, when the memory area needs to be compressed due to insufficient memory space, the memory area corresponding to the cold object can be compressed first. Specifically, the method includes: after the electronic device detects that the first application is in a startup state, it determines a first object (i.e., a hot object) belonging to a first category from multiple application objects corresponding to the first application, and transfers the first object from the first initial area to the first target area; determines a second object (i.e., a cold object) belonging to a second category from multiple application objects, and transfers the second object from the second initial area to the second target area. Then, the electronic device can perform a compression operation on the second target area first.

[0050] The method stores the first object and the second object in different target areas (i.e., the first target area and the second target area), and preferentially compresses the second target area corresponding to the second object. Since the probability of the second object in the second target area being accessed is relatively small, the method can reduce the probability of the compressed second target area being decompressed due to the second object being accessed, and can improve the response speed of the electronic device, thereby improving the performance of the electronic device.

[0051] In some embodiments, the electronic device may determine the first object and the second object when the electronic device detects that the remaining memory meets the memory cleanup condition. In this case, after determining the first object and the second object, the electronic device may directly perform a compression operation on the second target area.

[0052] In some other embodiments, the electronic device may determine the first object and the second object when the electronic device detects the first instruction or detects that the time interval between the current moment and the start moment when the first application is in the startup state is greater than or equal to the time threshold. The first instruction may be an instruction to instruct determination of the first object and the second object among multiple application objects.

[0053] In the case of the above-mentioned determination timing of the first object and the second object, the timing when the electronic device performs the compression operation on the second target area may be when the electronic device detects that the remaining memory meets the memory clearing condition.

[0054] In some embodiments, the electronic device may preferentially perform the compression operation on the entire area of ​​the second target area, or perform the compression operation on a portion of the second target area, which is not limited in the embodiments of the present application.

[0055] In some other embodiments, after the second target area is compressed, if the remaining memory of the electronic device is still insufficient, a compression operation may be further performed on part or all of the first target area to further release memory.

[0056] In some other embodiments, the memory management method provided by the present application can be applied to the garbage collection (GC) process of the electronic device.

[0057] Before introducing the memory management method provided by the present application in detail, the electronic device to which the memory management method is applicable is first described.

[0058] It can be understood that the memory management method provided in the embodiment of the present application is applicable to electronic devices including, but not limited to, mobile phones, smart TVs, wearable devices, tablet computers, computers with wireless transceiver functions, virtual reality (VR) devices, augmented reality (AR) devices, wireless devices in industrial control, wireless devices in self-driving, wireless devices in remote medical surgery, wireless devices in smart grids, wireless devices in transportation safety, wireless devices in smart cities, wireless devices in smart homes, etc. The embodiment of the present application does not limit the type of electronic devices.

[0059] Let's first combine Figure 2 , taking the timing when the electronic device determines the first object and the second object as detecting that the remaining memory meets the memory cleanup condition as an example, the memory management method provided in the present application is described in detail.

[0060] Figure 2 A flowchart of the first memory management method provided by the present application is shown. Figure 2 The execution subject of the process shown is an electronic device. For the convenience of description, the following is the introduction Figure 2 The execution entities will not be described repeatedly in the processes shown. Figure 2 As shown, the method includes but is not limited to the following schemes:

[0061] 201: It is detected that a first application of the electronic device is in an activated state.

[0062] It is understood that in the method provided by the present application, the electronic device can determine the first object and the second object among the multiple application objects corresponding to the first application when the first application is in the startup state. Among them, the embodiment of the present application does not limit the way in which the electronic device determines whether the first application is in the startup state. Exemplarily, if the electronic device determines that the process of the first application exists in the list of running processes, it can be determined that the first application is in the startup state.

[0063] In the embodiment of the present application, the startup state of the first application includes a foreground running state or a background running state. That is, no matter whether the electronic device detects that the first application is in the foreground running state or the background running state, it can be determined that the first application is in the startup state.

[0064] The embodiments of the present application do not limit the manner in which the electronic device determines that the first application is in the foreground / background running state. For example, if the electronic device determines that the display interface of the first application is currently displayed on the display screen, it can be determined that the first application is currently in the foreground running state. If the electronic device determines that the display interface of the first application is not currently displayed on the display screen, and the first application is in the open state, it can be determined that the first application is currently in the background running state.

[0065] 202: It is detected that the remaining memory of the electronic device meets the memory cleaning condition.

[0066] It can be understood that if the electronic device determines that the remaining memory of the electronic device meets the memory cleaning conditions, it can execute subsequent 203 and 204 to respectively determine the first object and the second object among the multiple application objects corresponding to the first application, and transfer the first object and the second object to clean up the memory of the second object.

[0067] The embodiment of the present application does not limit the content of the memory cleaning condition. For example, the memory cleaning condition may be that the remaining memory of the electronic device is less than a preset memory threshold; for another example, the memory cleaning condition may be that the ratio of the remaining memory of the electronic device to the total memory is less than a preset ratio threshold, etc. The values ​​of the preset memory threshold and the preset ratio threshold may be set based on experience or flexibly adjusted based on actual application scenarios.

[0068] 203: Determine a first object belonging to a first category among the multiple application objects, and transfer the first object from the first initial area to the first target area.

[0069] The first object of the first category is the hot object mentioned above, that is, the application object with a high probability of being accessed. The method of determining the first object of the first category will be described in detail later, and will not be repeated here.

[0070] It can be understood that after being created, each application object among the multiple application objects is first randomly stored in different memory pages. Therefore, taking the example that a certain application object is first stored in the first initial area (such as a memory page), after the electronic device determines that the application object is the first object belonging to the first category, the first object can be transferred from the first initial area to the first target area, wherein the first target area can be, for example, a memory page for storing the first object.

[0071] The embodiment of the present application does not limit the number of first target areas for storing the first object. For example, the number of the first target areas may be one or more.

[0072] When there are multiple first target areas, the number of first objects included in each first target area may be the same or different, and the number of first objects included in each first target area may be set based on experience or flexibly adjusted based on actual application scenarios.

[0073] 204: Determine a second object belonging to a second category among the multiple application objects, and transfer the second object from the second initial area to the second target area.

[0074] The second object of the second category is the cold object mentioned above, that is, the application object with a low probability of being accessed. The method for determining the second object of the second category will be described in detail later, and will not be repeated here.

[0075] It can be understood that after being created, each of the multiple application objects is first randomly stored in different memory pages. Therefore, taking the example that a certain application object is first stored in the second initial area (such as a memory page), after the electronic device determines that the application object is a second object belonging to the second category, the second object can be transferred from the second initial area to the second target area, wherein the second target area can be, for example, a memory page for storing the second object.

[0076] It can be understood that the first initial area and the second initial area in the embodiment of the present application can be the same or different, and the first target area and the second target area are different.

[0077] The embodiment of the present application also does not limit the number of the second target areas for storing the second object. For example, the number of the second target areas may be one or more.

[0078] When there are multiple second target areas, the number of second objects included in each second target area may be the same or different, and the number of second objects included in each second target area may be set based on experience or flexibly adjusted based on actual application scenarios.

[0079] Figure 3 A schematic diagram of a storage transfer process of a first object and a second object is shown. Figure 3 As shown, taking the number of the first target area and the second target area as one as an example, the initial area_1 stores objects A1, A2, A3 and A4; the initial area_2 stores objects B1, B2, B3 and B4. If the electronic device determines that objects A1 and A2 in the initial area_1 are the first objects, and objects A3 and A4 are the second objects, then objects A1 and A2 can be transferred from the initial area_1 to the first target area, and objects A3 and A4 can be transferred from the initial area_1 to the second target area.

[0080] It can be understood that for objects A1 and A2, initial region_1 is the first initial region; for objects A3 and A4, initial region_1 is the second initial region. In this case, the first initial region and the second initial region are the same, both of which are initial region_1.

[0081] Similarly, if the electronic device determines that objects B1 and B2 in the initial area_2 are first objects and objects B3 and B4 are second objects, objects B1 and B2 can be transferred from the initial area_1 to the first target area, and objects B3 and B4 can be transferred from the initial area_2 to the second target area.

[0082] It can be understood that for objects B1 and B2, initial region_2 is the first initial region; for objects B3 and B4, initial region_2 is the second initial region. In this case, the first initial region and the second initial region are the same, both of which are initial region_2.

[0083] like Figure 3 As shown, after the first and second objects are transferred and stored, the first target area stores the first objects, namely, objects A1, A2, B1 and B2, and the second target area stores the second objects, namely, objects A3, A4, B3 and B4.

[0084] It can be understood that in the method provided in the present application, the electronic device can transfer the first object and the second object to the first target area and the second target area respectively in a garbage collection thread or a Java (a programming language) thread.

[0085] 205: Perform a compression operation on the second target area, wherein the probability that the first object of the first category is accessed is greater than the probability that the second object of the second category is accessed.

[0086] When the remaining memory satisfies the memory cleaning condition, the electronic device determines the first object and the second object, and transfers the first object and the second object to the first target area and the second target area respectively, and then can perform the memory cleaning operation. It can be understood that since the probability of the first object being accessed is greater than the probability of the second object being accessed, the electronic device can preferentially perform the compression operation on the second target area, that is, perform the compression operation on the memory of the second object.

[0087] Based on the foregoing, the number of the second target areas may be one or more. Therefore, when the number of the second target areas is multiple, in some embodiments, the electronic device may perform a compression operation on all or part of the second target areas.

[0088] In the case where the electronic device performs a compression operation on a part of the second target area, illustratively, the electronic device can randomly determine a first preset number of second target areas from the plurality of second target areas, and then perform a compression operation on the determined second target areas. The first preset number can be set based on experience, or can be flexibly adjusted based on actual application scenarios, and the embodiments of the present application do not limit this.

[0089] Exemplarily, the electronic device may also arrange the multiple second target areas in a certain order. For example, when the number of second objects in each second target area is different, the electronic device may arrange the multiple second target areas in order from large to small in terms of the number of second objects included. Then, the electronic device may perform a compression operation on the first second preset number of second target areas. The second preset number may be set based on experience or flexibly adjusted based on actual application scenarios, and the first preset number and the second preset number may be the same or different.

[0090] In some other embodiments, after the second target area is compressed, if the remaining memory of the electronic device is still insufficient, the electronic device may further perform a compression operation on part or all of the first target area to further release memory.

[0091] The memory management method provided by the present application stores the first object and the second object in different target areas (i.e., the first target area and the second target area), and preferentially compresses the second target area corresponding to the second object. Since the probability of the second object in the second target area being accessed is relatively small, the method can reduce the probability of the compressed second target area being decompressed due to the second object being accessed, and can improve the response speed of the electronic device, thereby improving the performance of the electronic device.

[0092] Based on the above, the startup state of the first application includes a foreground running state and a background running state. That is to say, in the embodiment of the present application, the electronic device can start memory management when the first application is in the foreground running state or when the first application is in the background running state, for example, determining the first object and the second object among the multiple application objects of the first application.

[0093] Taking the first application of the electronic device in the background running state as an example, the determination methods of the first object and the second object respectively involved in 203 and 204 are described in detail below. Specifically, the determination methods of the first object and the second object may include the following three methods.

[0094] Method 1: The electronic device regards a plurality of background objects as first objects belonging to a first category; and regards a plurality of foreground objects as second objects belonging to a second category.

[0095] It can be understood that since the foreground object is responsible for displaying information and receiving user input, such as the display window and related controls of the application, the probability of the foreground object being accessed is small when the first application is running in the background. Since the background object does not interact directly with the user, it usually performs tasks such as logic processing, data storage and retrieval in the background. Therefore, when the first application is running in the background, the probability of the background object being accessed is large.

[0096] Therefore, in this manner, when the first application is in the background running state, the electronic device can treat multiple background objects among the multiple application objects corresponding to the first application as first objects belonging to the first category (i.e., hot objects); and treat multiple foreground objects as second objects belonging to the second category (i.e., cold objects).

[0097] It can be understood that, since the above method 1 describes the method for determining the first object and the second object when the first application is running in the background, the first object includes the background object and the second object includes the foreground object. However, it should be understood that when the first application is running in the foreground, the first object may include the foreground object and the second object may include the background object.

[0098] Method 2: The electronic device uses the first foreground object belonging to the first category among the multiple background objects and the multiple foreground objects as the first object; and uses the objects among the multiple foreground objects except the first foreground object as the second objects belonging to the second category.

[0099] It is understandable that when the first application is running in the background, there may still be some foreground objects with a high probability of being accessed. Therefore, in this method, in addition to directly treating multiple background objects as first objects belonging to the first category, the electronic device can also determine the first foreground object belonging to the first category from multiple foreground objects, and then treat the multiple background objects and the first foreground object together as the first object.

[0100] In this case, the electronic device may regard the foreground objects among the multiple foreground objects except the first foreground object belonging to the first category as the second objects belonging to the second category.

[0101] In some embodiments, the electronic device may determine the first foreground object based on the creation thread corresponding to the application object. Figure 4 As shown, the method for determining the first foreground object includes the following process.

[0102] 401: Obtain at least one creation thread corresponding to a first application, where the at least one creation thread is used to create multiple foreground objects.

[0103] It can be understood that each application object corresponding to the first application is created by a creation thread. Therefore, in order to determine the first foreground object from multiple foreground objects, in this process, the electronic device can obtain at least one creation thread for creating multiple foreground objects.

[0104] The embodiment of the present application does not limit the way in which the electronic device obtains at least one creation thread. For example, the electronic device can change the data structure of each application object, for example, add a creation thread data bit in the data structure of the application object, and the creation thread data bit can be used to store (or record) the creation thread of the application object. In this way, the electronic device can determine the creation thread of each application object according to the data corresponding to the creation thread data bit in each application object, and then obtain at least one creation thread of multiple foreground objects in multiple application objects.

[0105] In the above manner, when the electronic device creates a foreground object, it can record the creation thread of the foreground object based on the data structure of the foreground object. Then, when the electronic device determines that the remaining memory meets the memory cleanup condition and starts to determine the first foreground object, it can directly obtain at least one recorded creation thread.

[0106] Specifically, Figure 5As shown, the recording method of at least one creation thread in the present application may include the following process.

[0107] 4011: Create multiple application objects.

[0108] In an embodiment of the present application, when creating an application object, the electronic device may change the data structure of the created application object, for example, by adding a creation thread data bit to the data structure of the application object to store (or record) the creation thread of the application object.

[0109] Figure 6 FIG. 1 shows a schematic diagram of the structure of an application object before and after adding a thread creation data bit. Figure 6 As shown in (1) in the figure, the data structure of the application object mainly includes an object header, a data part, and an object layout control part. The object header may include class reference information and a monitor word. The class reference information is a pointer or reference to the metadata of the class described by the application object. Through the class reference information, the application object can access the properties and methods of its class. The monitor word stores information such as the hash code of the application object at runtime.

[0110] The data part of the application object is used to store various data of the application object at runtime. The object layout control part can include page margin (padding) information. In the graphical user interface design, page margin is used to define the space between the element content and the border.

[0111] The structure of the application object after adding the thread creation data bit can be as follows Figure 6 As shown in (2) in FIG. 1 , it can be understood that the thread creation data bit can be added to the object header part of the application object, and the size of the data part in the structure of the application object before and after the thread creation data bit is added remains unchanged, so that the size of the data structure of the application object after the thread creation data bit is added is larger than the size of the data structure of the application object when the thread creation data bit is not added.

[0112] It is understandable that electronic devices adopt Android TM Taking the system as an example, if the electronic device wants to change the data structure of an application object, the creation logic of the application object in the Android runtime (ART) can be modified, for example, recording the creation thread corresponding to the application object when the application object is created.

[0113] In some embodiments, the electronic device may modify the creation logic of the application object in the Android operating environment based on the switch interpreter. For example, the electronic device modifies the acquisition instruction (such as the sget instruction, the aget instruction, etc.) based on the switch interpreter so that the electronic device can obtain the creation thread corresponding to the application object based on the modified acquisition instruction.

[0114] 4012: Allocate memory space for each application object.

[0115] After the electronic device creates multiple application objects in the manner described in 4011, it may allocate memory space for each application object, that is, store each application object in an initial area (such as the first initial area and the second initial area described above).

[0116] 4013: Record creation threads of foreground objects in multiple application objects, and obtain at least one creation thread corresponding to the first application program.

[0117] It can be understood that since the data structure of each application object created by the electronic device contains a creation thread data bit for storing the creation thread of the application object, the electronic device can determine (or record) the creation thread of each foreground object in multiple application objects based on the data corresponding to the creation thread data bit, and thereby obtain at least one creation thread corresponding to the first application.

[0118] It can be understood that the number of application objects corresponding to the first application is greater than the number of creation threads, that is, one creation thread may be used to create multiple different application objects, for example, one creation thread may be used to create multiple different foreground objects.

[0119] Taking application object A1, application object A2 and application object A3 as foreground objects, if the creation thread data bit record in the data structure of application object A1 is thread B1, the creation thread data bit record in the data structure of application object A2 is thread B1, and the creation thread data bit record in the data structure of application object A3 is thread B2, then the electronic device can determine based on the data structure of each application object: the creation thread of application object A1 is thread B1, the creation thread of application object A2 is thread B1, and the creation thread of application object A3 is thread B2. In other words, thread B1 creates application object A1 and application object A2, and thread B2 creates application object A3.

[0120] Based on this, the electronic device can determine that at least one creation thread corresponding to the first application is thread B1 and thread B2.

[0121] It can be understood that after the electronic device records at least one creation thread, when it determines that the remaining memory meets the memory cleanup condition and starts to determine the first foreground object, it can directly obtain the at least one creation thread previously recorded.

[0122] 402: Determine at least one first created object created by a first creation thread in at least one creation thread, where the at least one first created object belongs to multiple foreground objects.

[0123] After the electronic device determines at least one creation thread corresponding to the first application, it can determine at least one creation object created by each creation thread. Taking the first creation thread as an example, the electronic device can determine at least one first creation object corresponding to the first creation thread. It can be understood that the at least one first creation object belongs to multiple foreground objects of the first electronic device.

[0124] Taking the first creation thread as thread B1 as an example, the electronic device may determine that at least one first creation object created by thread B1 includes application object A1 and application object A2.

[0125] 403: Corresponding to the first number of accessed objects in the at least one first created object, a ratio of the first number of accessed objects to the second number of the at least one first created object is greater than a first ratio threshold, and the at least one first created object is regarded as a first foreground object belonging to the first category.

[0126] After the electronic device determines at least one first created object created by the first creation thread, it can determine the first number of objects in the at least one first created object that have been accessed (for example, accessed between the start time when the first application is in the background running state and the current time) during the background running of the first application. If the ratio of the first number to the second number is greater than the first ratio threshold, it means that the first created objects created by the first creation thread have a high probability of being accessed when the first application is running in the background, and the at least one first created object corresponding to the first creation thread is used as the first foreground object.

[0127] The embodiment of the present application does not limit the value of the first ratio threshold, and can be set based on experience or flexibly adjusted according to actual application scenarios.

[0128] Understandably, Figure 4 In the method for determining the first foreground object shown, when the electronic device determines that the ratio of the number of objects that have been visited in at least one first created object is greater than the first ratio threshold, the at least one first created object is taken as the first object and transferred to the first target area. In this case, the objects in the foreground object other than the first created object whose corresponding ratio is greater than the first ratio threshold will be taken as the second object and stored in the second target area.

[0129] In this way, the probability of the second object in the second target area being accessed is relatively small, which can reduce the probability of the compressed second target area being decompressed again due to the second object being accessed, thereby improving the response speed of the electronic device and the performance of the electronic device.

[0130] In the previous article Figure 4 In the method shown, the electronic device determines the proportion of objects that are accessed in at least one creation object created by each creation thread, and uses at least one creation object whose corresponding proportion is greater than a first proportion threshold as the first foreground object. In some other embodiments, the electronic device can also directly determine the proportion of objects that are accessed in at least one target creation object created by the target creation thread of the visited foreground object.

[0131] Figure 7 FIG. 2 shows a flow chart of another electronic device determining a first foreground object based on a creation thread corresponding to an application object. Figure 7 As shown, the method for determining the first foreground object includes the following process.

[0132] 701: Obtain at least one creation thread corresponding to a first application, where the at least one creation thread is used to create multiple foreground objects.

[0133] It can be understood that the execution principle of 701 is the same as the execution principle of 401 above, and will not be repeated here. In some embodiments, this process is optional.

[0134] 702: Determine at least one target creation thread corresponding to at least one foreground object accessed when the first application is running in the background.

[0135] In an embodiment of the present application, each of the at least one target creation thread may be recorded when the foreground object is accessed. Then, when the electronic device detects that the remaining memory is insufficient and then determines the first foreground object, it may obtain the recorded at least one target creation thread.

[0136] In some embodiments, Figure 8 As shown, the manner in which the electronic device records the target creation thread corresponding to the accessed foreground object may include the following process.

[0137] 7021: Determine the application object being accessed.

[0138] It is understandable that the accessed application object may be a foreground object or a background object. Therefore, the electronic device needs to perform the subsequent step 7022, that is, determining whether the accessed application object is a foreground object or a background object.

[0139] 7022: Determine whether the accessed application object is a foreground object.

[0140] It can be understood that the purpose of accessing the application object is to execute relevant instructions or tasks. Therefore, after the electronic device determines the accessed application object, it can start to determine whether the accessed application object is a foreground object during the process of executing the relevant instructions or tasks, or after executing the relevant instructions or tasks.

[0141] If the electronic device determines that the accessed application object is a foreground object, it executes 7023 to determine whether the accessed foreground object is accessed for the first time. If the electronic device determines that the accessed application object is not a foreground object, it executes 7025 to not record the creation thread of the application object.

[0142] 7023: Determine whether the accessed application object is being accessed for the first time.

[0143] It is understood that if the electronic device determines that the application object is accessed for the first time, it executes 7024 to record the creation thread of the application object. If the electronic device determines that the application object is not accessed for the first time, it executes 7025 to not record the creation thread of the application object.

[0144] 7024: Records the creation thread of the accessed application object and uses it as the target creation thread.

[0145] Exemplarily, the electronic device can determine the target creation thread corresponding to the application object according to the data corresponding to the creation thread data bit in the data structure of the accessed application object. The target creation thread of the application object is recorded in the same manner as described above. Figure 5 The principles of the methods shown are the same and will not be described in detail.

[0146] In the present application, after the electronic device records the creation thread of the accessed application object, it can continue to execute the relevant instructions or tasks involved in the above 7022.

[0147] 7025: Do not record the creation thread of the application object being accessed.

[0148] In the present application, after the electronic device determines not to record the creation thread of the accessed application object, it can continue to execute the relevant instructions or tasks involved in the above 7022.

[0149] 703: Determine at least one first target creation object created by a first target creation thread in at least one target creation thread, where the at least one first target creation object belongs to a plurality of foreground objects.

[0150] 704: Corresponding to at least one first target creation object, the ratio of the number of first targets of the accessed application objects to the number of second targets of at least one first target creation object is greater than a first ratio threshold, and the at least one first target creation object is treated as a first foreground object belonging to the first category.

[0151] It can be understood that the execution principle of the above 703-704 is similar to the execution principle of the related processes in the previous 402-403, and will not be repeated here.

[0152] Figure 7 In the method shown, since at least one target creation thread corresponds to at least one foreground object being accessed, compared to Figure 4 At least one of the methods described above creates a thread, and at least one of the target threads creates a smaller number of threads. Figure 7 The method shown can make the first foreground object determination speed faster, improve the efficiency of determining the first foreground object, and further improve the efficiency of memory cleaning.

[0153] Understandably, the previous Figure 5 and Figure 8 The method shown involves recording modes of at least one creation thread and a target creation thread corresponding to an accessed foreground object, respectively. Fig. 9 FIG. 1 is a flow chart showing a method for recording thread information. Fig. 9 As shown, the method for recording thread information includes the following process.

[0154] 901: Determine whether the first application is in the foreground running state.

[0155] 902: Execute related tasks and create foreground objects.

[0156] It is understood that when the first application is running in the foreground, the electronic device can execute related tasks (i.e., the process of executing the related program), and the process of executing the task may involve the creation of foreground objects. For example, in response to the user adding a contact, the electronic device can add a foreground object corresponding to the contact to add the contact information.

[0157] 903: Record at least one creation thread of the created foreground object.

[0158] It can be understood that the execution principle of 903 can be found in the previous text. Figure 5 The execution principle of the method shown will not be described in detail here.

[0159] 904: Determine that the first application is switched to a background running state.

[0160] 905: Record at least one target creation thread corresponding to at least one foreground object accessed when the first application is running in the background.

[0161] It can be understood that the execution principle of 905 can be found in the previous text. Figure 8 The execution principle of the method shown will not be described in detail here.

[0162] 906: Output the record result.

[0163] It can be understood that the recording result includes at least one creation thread and at least one target creation thread.

[0164] The embodiment of the present application does not limit the timing of the electronic device outputting the record result. For example, the electronic device may output the record result when detecting that the remaining memory is insufficient, so as to determine the first object based on the record result. For another example, the electronic device may also output the record result after determining that the first application has switched to the foreground running state. In this case, the record result can be used to determine the first object when the first application switches to the background running state next time.

[0165] Understandably, the previous Figures 4 to 9 The method shown describes a way in which the electronic device determines the first foreground object based only on the creation thread. In some other embodiments, the electronic device may determine the first foreground object based on the creation thread and then based on the access thread. Specifically, Fig.10 As shown, the method for determining the first foreground object in this case includes the following process.

[0166] 1001: Obtain at least one access thread corresponding to at least one first created object, where the at least one access thread is used to access the at least one first created object.

[0167] The embodiment of the present application does not limit the manner in which the electronic device obtains at least one access thread corresponding to at least one first created object. Exemplarily, the electronic device may change the data structure of each application object, for example, by adding an access thread data bit to the data structure of the application object, and the access thread data bit may be used to store (or record) the access thread of the application object. In this way, the electronic device can determine the access thread of each first created object based on the data corresponding to the access thread data bit in each first created object, and further obtain at least one access thread corresponding to at least one first created object.

[0168] Specifically, Fig.11 As shown, the method for determining at least one access thread in the present application may include the following process.

[0169] 1011: Create multiple application objects.

[0170] In an embodiment of the present application, when creating an application object, the electronic device may change the data structure of the created application object, for example, by adding an access thread data bit to the data structure of the application object to store (or record) the access thread of the foreground object.

[0171] Fig.12 A schematic diagram of the structure of an application object before and after adding access thread data bits is shown. Fig.12 (1) in the previous text Figure 6 The data structure of the application object shown in (1) is the same as that of the application object and will not be described in detail.

[0172] The structure of the foreground object after adding the access thread data bit can be as follows Fig.12 As shown in (2) in FIG. 1 , it can be understood that the access thread data bit can be added to the object header part of the application object, and the size of the data part in the structure of the application object before and after the access thread data bit is added remains unchanged, so that the size of the data structure of the application object after the access thread data bit is added is larger than the size of the data structure of the application object when the access thread data bit is not added.

[0173] It is understandable that electronic devices adopt Android TM Taking the system as an example, if the electronic device wants to change the data structure of the application object, it can modify the creation logic of the application object in the Android runtime (ART), such as adding an access thread data bit when the application object is created to record the access thread that accessed the foreground object.

[0174] In some embodiments, the electronic device may modify the creation logic of the application object in the Android operating environment based on the switch interpreter. For example, the electronic device modifies the acquisition instruction (such as the sget instruction, the aget instruction, etc.) based on the switch interpreter so that the electronic device can acquire the access thread corresponding to the application object based on the modified instruction.

[0175] 1012: Allocate memory space for each application object.

[0176] It can be understood that the execution principle of 1012 is the same as the execution principle of 4012 mentioned above, so it will not be repeated.

[0177] 1013: Obtain access threads of first created objects accessed among multiple application objects, and obtain at least one access thread corresponding to at least one first created object.

[0178] It can be understood that since the data structure of each application object created by the electronic device contains an access thread data bit for storing the access thread of the application object, the electronic device can determine the access thread of the first created object being accessed based on the data corresponding to the access thread data bit, and thereby obtain at least one access thread corresponding to at least one first created object.

[0179] In the above manner, when an application object is accessed, the electronic device can record the access thread of the application object based on the data structure of the application object. Then, when the electronic device determines that the remaining memory meets the memory cleanup condition and starts to determine the first foreground object, it can directly obtain at least one access thread corresponding to the recorded at least one first created object.

[0180] In some embodiments, Fig.13 As shown, the manner in which the electronic device records the access thread of the accessed application object may include the following process.

[0181] 1301: Determine the application object being accessed.

[0182] It is understandable that the accessed application object may belong to at least one first created object, or may not belong to at least one first created object. Therefore, the electronic device needs to perform the subsequent 1302, that is, determine whether the accessed application object belongs to at least one first created object.

[0183] 1302: Determine whether the accessed application object is accessed for the first time.

[0184] It can be understood that the purpose of accessing the application object is to execute related instructions or tasks. Therefore, after the electronic device determines the accessed application object, it can start to determine whether the accessed application object is accessed for the first time during the process of executing the related instructions or tasks, or after executing the related instructions or tasks.

[0185] It is understood that if the electronic device determines that the accessed application is accessed for the first time, it executes 1303 to record the access thread of the accessed application object. If the electronic device determines that the accessed application object is not accessed for the first time, it executes 1304 to not record the access thread of the application object.

[0186] 1303: Record the access thread of the accessed application object.

[0187] Exemplarily, the electronic device may determine the access thread corresponding to the application object according to the data corresponding to the access thread data bit in the data structure of the accessed application object. The recording method of the access thread of the application object has been described in the previous text. Fig.11 The corresponding text content has been described and will not be repeated here.

[0188] In the present application, after the electronic device records the access thread of the accessed application object, it can continue to execute the relevant instructions or tasks involved in the above 1302.

[0189] 1304: The access thread of the accessed application object is not recorded.

[0190] In the present application, after the electronic device determines not to record the access thread of the accessed application object, it can continue to execute the relevant instructions or tasks involved in the above 1302.

[0191] It can be understood that after the electronic device records the access thread of the accessed application object, when it determines that the remaining memory meets the memory cleanup conditions and starts to determine the first foreground object, it can directly obtain the access thread of the accessed first creation object from the access thread of the accessed application object.

[0192] 1002: Determine a third number of first created objects accessed by a first access thread in at least one access thread.

[0193] After the electronic device determines at least one access thread corresponding to at least one first created object, it can determine the number of first created objects accessed by each first access thread. Taking the first access thread of the at least one access thread as an example, the electronic device can determine the third number of first created objects accessed by the first access thread.

[0194] 1003: corresponding to a ratio of the third number to the second number being greater than a second ratio threshold, treating the foreground object accessed by the first access thread as a first foreground object belonging to the first category.

[0195] It can be understood that if the ratio of the third number to the second number is greater than the second ratio threshold, it means that the foreground objects accessed by the first access thread are more likely to be accessed when the first application is running in the background. Therefore, the foreground objects accessed by the first access thread can all be regarded as the first foreground objects.

[0196] The embodiment of the present application does not limit the value of the second ratio threshold, and can be set based on experience or flexibly adjusted according to actual application scenarios.

[0197] Understandably, Fig.10 In the method for determining the first foreground object shown, in addition to taking at least one first creation object created by the first creation thread as the first foreground object, the electronic device also takes the foreground object accessed by the first access thread as the first foreground object. Then, the electronic device can transfer and store the above-mentioned first foreground object to the first target area. In this case, the objects in the foreground object other than the first foreground object will be taken as the second object and stored in the second target area.

[0198] In this way, the probability of the second object in the second target area being accessed is further reduced, and the probability of the compressed second target area being decompressed again due to the second object being accessed can be further reduced, thereby improving the response speed of the electronic device and the performance of the electronic device.

[0199] It can be understood that since the above method 2 describes the method for determining the first object and the second object when the first application is running in the background, the first object includes the background object and part of the foreground object, and the second object includes the remaining foreground objects. However, it should be understood that when the first application is running in the foreground, the first object may include the foreground object and part of the background object, and the second object includes the remaining background objects. Regardless of whether the first application is running in the foreground or the background, the principles for determining the first object and the second object are similar, and will not be described one by one.

[0200] Method three: the electronic device obtains an object type set including multiple object types, takes an application object whose object type belongs to the object type set among multiple application objects as a first object; and takes objects other than the first object among the multiple application objects as a second object.

[0201] It is understandable that the electronic device may first determine the object type set, and then obtain the determined object type set after determining that the remaining memory meets the memory cleanup condition. The electronic device may first obtain at least one initial object type of at least one application object being accessed, and then determine the object type that can be stored in the object type set from the at least one initial object type.

[0202] In some embodiments, Fig.14 As shown, the method for determining the initial object type includes the following process.

[0203] 1401: Determine the application object being accessed.

[0204] 1402: Determine whether the accessed application object is accessed for the first time.

[0205] It can be understood that the purpose of accessing the application object is to execute related instructions or tasks. Therefore, after the electronic device determines the accessed application object, it can start to determine whether the accessed application object is accessed for the first time during the process of executing the related instructions or tasks, or after executing the related instructions or tasks.

[0206] It can be understood that if the electronic device determines that the accessed application object is accessed for the first time, it executes 1403 to record the object type of the accessed application object; if the electronic device determines that the accessed application object is not accessed for the first time, it executes 1404 to not record the object type of the accessed application object.

[0207] 1403: Record the object type of the accessed application object and use it as the initial object type.

[0208] In the present application, after the electronic device records the initial object type of the accessed application object, it can continue to execute the relevant instructions or tasks involved in the above 1402.

[0209] 1404: The object type of the accessed application object is not recorded.

[0210] In the present application, after the electronic device determines not to record the object type of the accessed application object, it can continue to execute the relevant instructions or tasks involved in the above 1402.

[0211] Electronic devices based on Fig.14 After obtaining at least one initial object type of at least one application object, the method shown can determine the target number of application objects accessed in the first initial application object corresponding to the first initial object type in the at least one initial object type. Then, when the proportion of the target number to the total number of the first initial application objects is greater than a third proportion threshold, the first initial object type is stored in the object type set.

[0212] In this way, the electronic device can determine the first object and the second object from a plurality of application objects based on a predetermined set of object types. The first object and the second object can be determined quickly and with high accuracy. The probability of the second object in the second target area being accessed is reduced, and the probability of the compressed second target area being decompressed again due to the second object being accessed can be reduced, thereby improving the response speed of the electronic device and improving the performance of the electronic device.

[0213] It is understandable that the above Figures 2 to 14 The memory cleaning process is described by taking the case where the determination timing of the first object and the second object and the execution timing of the compression operation on the second target area are the same, that is, both are the case where the remaining memory is detected to meet the memory cleaning condition. In some other embodiments, the determination timing of the first object and the second object and the execution timing of the compression operation on the second target area may also be different. This memory management method may be as follows Fig.15 shown.

[0214] 1501: It is detected that the first application of the electronic device is in the startup state.

[0215] It can be understood that the execution principle of 1501 is the same as the execution principle of 201 mentioned above, and will not be repeated here.

[0216] 1502: A first instruction is detected, or it is detected that the time interval between the current moment and the first moment is greater than or equal to a time threshold.

[0217] The first instruction is an instruction to instruct the electronic device to determine a first object and a second object among a plurality of application objects, and the first moment is a starting moment when the first application is in an activated state.

[0218] The embodiment of the present application does not limit the value of the time threshold, which can be set based on experience or flexibly adjusted according to actual application scenarios.

[0219] 1503: Determine a first object belonging to a first category among a plurality of application objects, and transfer the first object from a first initial area to a first target area.

[0220] 1504: Determine a second object belonging to a second category among the multiple application objects, and transfer the second object from the second initial area to the second target area.

[0221] It can be understood that the execution principle of the above 1503-1504 is the same as the execution principle of the corresponding process in the previous 203-204, and will not be repeated here.

[0222] 1505: It is detected that the remaining memory of the electronic device meets the memory cleaning conditions.

[0223] It can be understood that the execution principle of 1505 is the same as the execution principle of 202 above, and will not be repeated here.

[0224] 1506: Perform a compression operation on the second target area, wherein the probability that the first object of the first category is accessed is greater than the probability that the second object of the second category is accessed.

[0225] It can be understood that the execution principle of 1506 is the same as the execution principle of 205 above, and will not be repeated here.

[0226] It can be understood that in this method, since there may be a time interval between the determination time of the first object and the second object and the determination time when the remaining memory meets the memory cleanup condition, in some embodiments, the electronic device can treat the foreground object created by the first creation thread in the previous 403 within the time interval, or the foreground object accessed by the first access thread in 1003 within the time interval, as the first object, and transfer it to the first target area.

[0227] exist Figure 1 Based on the storage method of the virtual machine and the application objects in the memory, Fig.16 FIG. 1 shows a schematic diagram of a situation after transferring an application object to another storage device. Fig.16As shown, taking object A, object B and object D as the first object and object C, object E and object F as the second object as an example, after the virtual machine determines the first object and the second object, the virtual addresses of object A, object B and object D can be stored in the first target virtual area, and the virtual addresses of object C, object E and object F can be stored in the second target virtual area.

[0228] Then, the virtual machine may send a message to the kernel to notify the kernel to transfer the determined first object and second object, and the kernel may transfer the first object and the second object to different areas in the memory. For example, object A, object B and object D are stored in the first target area, and object C, object E and object F are stored in the second target area.

[0229] During the memory cleaning process (e.g., under the GC mechanism), when the electronic device determines that the remaining memory meets the memory cleaning conditions, the second target area can be compressed to release the memory. It can be understood that when this method is applied in the GC mechanism, the second target area can be compressed first during memory recycling, which can achieve the optimization of the GC mechanism (or algorithm), that is, the optimization of the memory recycling process.

[0230] In other embodiments, Fig.17 As shown, when the remaining memory is insufficient, the kernel can also control to transfer at least part of the second object in the second target area to the swap area again, so that the memory space can also be released. Fig.17 Objects E and F in the storage are transferred to the swap area.

[0231] Fig.18 FIG. 2 shows a flow chart of another memory management method provided by an embodiment of the present application. Fig.18 As shown, the method includes the following process.

[0232] 1801: Add identifiers to multiple application objects corresponding to the first application.

[0233] In some embodiments, taking the case where the number of the first target area for storing the first object and the number of the second target area for storing the second object are both one, the electronic device may pre-randomly set the first target area and the second target area. Fig.19 As shown, taking the example of an electronic device pre-setting two memory pages in the memory as the first target area and the second target area respectively, at this time, the first target area initially stores objects A, B and C, and the second target area initially stores objects D, E and F.

[0234] Next, the electronic device may determine a first object belonging to the first category and a second object belonging to the second category among the multiple application objects, and then add a first identifier (such as a hot identifier) ​​to the first object and a second identifier (such as a cold identifier) ​​to the second object.

[0235] Continue as Fig.19 As shown, the electronic device determines that object A, object B and object D are first objects, and then a first identifier can be added to object A, object B and object D. The electronic device determines that object C, object E and object F are second objects, and then a second identifier can be added to object C, object E and object F.

[0236] 1802: Determine whether the identifier of the first application object among the multiple application objects matches the current area.

[0237] It can be understood that after the electronic device adds a corresponding identifier to each application object, it can determine whether each application object matches the current area.

[0238] If the electronic device determines that the identifier of the first application object matches the region where the first application object is located, the subsequent step 1803 is executed; if the electronic device determines that the identifier of the first application object does not match the region where the first application object is located, the subsequent step 1804 is executed.

[0239] Taking the first application object as object A as an example, the electronic device can determine that object A is the first object, i.e., the hot object, based on the first identifier of object A. Moreover, the first target area where object A is currently located is an area for storing the first object, so the electronic device can determine that the identifier of object A matches the area where it is located.

[0240] Taking the first application object as object C as an example, the electronic device can determine that object C is a second object, i.e., a cold object, based on the second identifier of object C. However, the first target area where object C is currently located is an area for storing the first object (i.e., a hot object), so the electronic device can determine that the identifier of object C does not match the area where it is located.

[0241] 1803: Continue to store the first application object in the current area.

[0242] Taking the first application object as object A as an example, after the electronic device determines that the identifier of object A matches the area where it is located, object A can continue to be stored in the first target area.

[0243] 1804: Transfer and store the first application object to an area different from the current area.

[0244] Taking the first application object as object C as an example, after the electronic device determines that the identifier of object C does not match the area where it is located, the object C can be transferred to the second target area.

[0245] It can be understood that after the electronic device executes 1803 and 1804, the application objects in the first target area are all first objects with the first identifier, and the application objects in the second target area are all second objects with the second identifier.

[0246] like Fig.19 As shown, the first target area stores object A, object B and object D; the second target area stores object C, object E and object F.

[0247] The above 1803 and 1804 can also be understood as a process of storing the first application object in the area where the first application object should be located.

[0248] 1805: After each first application object among the multiple application objects is stored in the corresponding area, if it is determined that the remaining memory of the electronic device meets the memory cleaning condition, compress the second target area.

[0249] When the remaining memory of the electronic device is insufficient, the second target area can be compressed, for example, the memory of object C, object E and object F is released.

[0250] 1806: Move at least part of the second objects in the second target area to the exchange area.

[0251] It is understandable that this process is optional. After the electronic device compresses the second target area, it can also choose whether to move at least part of the second objects in the compressed second target area to the swap area (for example, move object E and object F to the swap area), so as to further release memory space.

[0252] In the method provided by the present application, the electronic device transfers the first object and the second object to different target areas (i.e., the first target area and the second target area), and preferentially compresses the second target area corresponding to the second object. Since the probability of the second object in the second target area being accessed is relatively small, the method can reduce the probability of the compressed second target area being decompressed due to the second object being accessed, and can improve the response speed of the electronic device, thereby improving the performance of the electronic device.

[0253] In addition, the first foreground object in the first object in the present application is distinguished based on threads. This method can make the determination of the first object more lightweight, reduce the determination time of the first object, and thus improve the efficiency of memory cleaning.

[0254] In addition, in other embodiments, the first object and the second object are distinguished based on the type of application object. This method can also make the determination of the first object and the second object more lightweight, reduce the determination time of the first object and the second object, and thus improve the efficiency of memory cleaning.

[0255] In some embodiments, the embodiments of the present application further provide a storage medium having instructions stored thereon, which, when executed on an electronic device, enables the electronic device to execute the memory management method described in the above embodiments.

[0256] In some embodiments, the embodiments of the present application further provide a program product, including: instructions, which, when executed on an electronic device, enable the electronic device to implement the memory management method described in the above embodiments.

[0257] In some embodiments, the embodiments of the present application also provide an electronic device, which includes: one or more processors; one or more memories; one or more memories storing one or more programs, when the one or more programs are executed by one or more processors, the electronic device executes the memory management method described in the above embodiments.

[0258] Fig. 20 FIG. 1 is a schematic diagram showing the structure of an electronic device provided in an embodiment of the present application. Fig. 20 As shown, the electronic device 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. 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.

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

[0260] The processor 110 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 video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.

[0261] The controller can generate operation control signals according to the instruction operation code and timing signal to complete the control of instruction fetching and execution.

[0262] A memory may also be provided in the processor 110 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 above-mentioned memory. Repeated access is avoided, the waiting time of the processor 110 is reduced, and the efficiency of the system is improved. The processor may be used to execute the memory management method mentioned in the present application.

[0263] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function. For example, files such as music and videos can be stored in the external memory card.

[0264] The internal memory 121 can be used to store computer executable program codes, which include instructions. 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 (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. The processor 110 executes various functional applications and data processing of the electronic device by running instructions stored in the internal memory 121 and / or instructions stored in a memory provided in the processor.

[0265] The SIM card interface 195 is used to connect a SIM card.

[0266] It will be understood that, as used herein, the term "module" may refer to or include an application-specific integrated circuit (ASIC), an electronic circuit, a processor (shared, dedicated, or group) and / or memory that executes one or more software or firmware programs, a combinational logic circuit, and / or other appropriate hardware components that provide the described functionality, or may be part of these hardware components.

[0267] It is understood that in each embodiment of the present application, the processor may be a microprocessor, a digital signal processor, a microcontroller, etc., and / or any combination thereof. According to another aspect, the processor may be a single-core processor, a multi-core processor, etc., and / or any combination thereof.

[0268] The embodiments disclosed in the present application may be implemented in hardware, software, firmware or a combination of these implementation methods. The embodiments of the present application may be implemented as a computer program or program code executed on a programmable system, the programmable system including at least one processor, a storage system (including volatile and non-volatile memory and / or storage elements), at least one input device and at least one output device.

[0269] Program code may be applied to input instructions to perform the functions described herein and to generate output information. The output information may be applied to one or more output devices in a known manner. For purposes of this application, a processing system includes any system having a processor such as a digital signal processor (DSP), a microcontroller, an application specific integrated circuit, or a microprocessor.

[0270] Program code can be implemented with high-level programming language or object-oriented programming language to communicate with the processing system. When necessary, program code can also be implemented with assembly language or machine language. In fact, the mechanism described in this application is not limited to the scope of any specific programming language. In either case, the language can be a compiled language or an interpreted language.

[0271] In some cases, the disclosed embodiments may be implemented in hardware, firmware, software, or any combination thereof. The disclosed embodiments may also be implemented as instructions carried or stored on one or more temporary or non-temporary machine-readable (e.g., computer-readable) storage media, which may be read and executed by one or more processors. For example, the instructions may be distributed over a network or through other computer-readable media. Therefore, a machine-readable medium may include any mechanism for storing or transmitting information in a machine (e.g., computer) readable form, including but not limited to floppy disks, optical disks, optical disks, read-only memories (CD-read-only memories, CD-ROMs), magneto-optical disks, read-only memories (ROM), random access memory (RAM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), magnetic or optical cards, flash memory, or a tangible machine-readable memory for transmitting information (e.g., carrier waves, infrared signals, digital signals, etc.) using the Internet in electrical, optical, acoustic, or other forms of propagation signals. Accordingly, machine-readable media include any type of machine-readable media suitable for storing or transmitting electronic instructions or information in a form readable by a machine (eg, a computer).

[0272] In the accompanying drawings, some structural or method features may be shown in a specific arrangement and / or order. However, it should be understood that such a specific arrangement and / or order may not be required. Instead, in some embodiments, these features may be arranged in a manner and / or order different from that shown in the illustrative drawings. In addition, the inclusion of structural or method features in a particular figure does not mean that such features are required in all embodiments, and in some embodiments, these features may not be included or may be combined with other features.

[0273] It should be noted that the units / modules mentioned in the various device embodiments of the present application are all logical units / modules. Physically, a logical unit / module can be a physical unit / module, or a part of a physical unit / module, or can be implemented as a combination of multiple physical units / modules. The physical implementation method of these logical units / modules themselves is not the most important. The combination of functions implemented by these logical units / modules is the key to solving the technical problems proposed by the present application. In addition, in order to highlight the innovative part of the present application, the above-mentioned device embodiments of the present application do not introduce units / modules that are not closely related to solving the technical problems proposed by the present application, which does not mean that there are no other units / modules in the above-mentioned device embodiments.

[0274] It should be noted that, in the examples and description of the present application, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that the process, method, article or equipment including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or equipment. In the absence of further restrictions, the elements defined by the statement "comprise one" do not exclude the presence of other identical elements in the process, method, article or equipment including the elements.

[0275] Although the present application has been illustrated and described with reference to certain preferred embodiments thereof, it will be understood by those skilled in the art that various changes in form and details may be made therein without departing from the scope of the present application.

Claims

1. A memory management method, characterized in that: Applied to electronic equipment, the method comprises: Detecting that a first application of the electronic device is in a startup state, wherein the first application corresponds to a plurality of application objects; Determine a first object belonging to a first category among the plurality of application objects, and transfer the first object from a first initial area to a first target area; Determine a second object belonging to a second category among the plurality of application objects, and transfer the second object from the second initial area to the second target area; A compression operation is performed on the second target area, wherein a probability that the first object of the first category is accessed is greater than a probability that the second object of the second category is accessed.

2. The method according to claim 1, characterized in that Before determining the first object belonging to the first category among the multiple application objects, the method further includes: It is detected that the remaining memory of the electronic device meets the memory cleaning condition.

3. The method according to claim 1, characterized in that Before determining the first object belonging to the first category among the multiple application objects, the method further includes: Detecting a first instruction, or detecting that the time interval between the current moment and the first moment is greater than or equal to a time threshold, the first moment being the start moment when the first application is in the startup state; Before performing the compression operation on the second target area, the method further includes: It is detected that the remaining memory of the electronic device meets the memory cleaning condition.

4. The method according to any one of claims 1 to 3, characterized in that: The multiple application objects include multiple foreground objects and multiple background objects. The multiple foreground objects are objects created when the first application is running in the foreground, and the multiple background objects are objects created when the first application is running in the background.

5. The method according to claim 4, characterized in that When the first application is in the background running state, The determining a first object belonging to a first category among the plurality of application objects comprises: taking the plurality of background objects as first objects belonging to a first category; The determining a second object belonging to a second category among the plurality of application objects comprises: The multiple foreground objects are regarded as second objects belonging to a second category.

6. The method according to claim 4, characterized in that When the first application is in the background running state, The determining a first object belonging to a first category among the plurality of application objects comprises: determining a first foreground object belonging to a first category among the plurality of foreground objects; taking the multiple background objects and the first foreground object as first objects belonging to the first category; The determining a second object belonging to a second category among the plurality of application objects comprises: Among the plurality of foreground objects, objects other than the first foreground object are regarded as second objects belonging to the second category.

7. The method according to claim 6, characterized in that The determining a first foreground object belonging to a first category among the plurality of foreground objects comprises: Obtain at least one creation thread corresponding to the first application, where the at least one creation thread is used to create the multiple foreground objects; Determine at least one first created object created by a first created thread in the at least one created thread, wherein the at least one first created object belongs to the plurality of foreground objects; Corresponding to the at least one first created object, the ratio of the first number of accessed objects to the second number of the at least one first created object is greater than the first ratio threshold, and the at least one first created object is regarded as the first foreground object belonging to the first category.

8. The method according to claim 7, characterized in that The determining of a first foreground object belonging to a first category among the plurality of foreground objects further includes: Acquire at least one access thread corresponding to the at least one first created object, where the at least one access thread is used to access the at least one first created object; determining a third number of first created objects accessed by a first access thread in the at least one access thread; Corresponding to a ratio of the third number to the second number being greater than a second ratio threshold, the foreground object accessed by the first access thread is regarded as a first foreground object belonging to the first category.

9. The method according to claim 8, characterized in that The object header of each application object in the plurality of application objects includes a create thread data bit and an access thread data bit; The obtaining at least one creation thread corresponding to the first application comprises: Determine the creation thread of each application object based on the data corresponding to the creation thread data bit in each application object, and obtain the at least one creation thread used to create the multiple application objects; The obtaining at least one access thread corresponding to the at least one first created object includes: Based on the data corresponding to the access thread data bit of each first created object in the at least one first created object, the access thread of each first created object is determined, and the at least one access thread for accessing the at least one first created object is obtained.

10. The method according to claim 4, characterized in that The determining a first object belonging to a first category among the plurality of application objects comprises: Get an object type collection including multiple object types; taking, among the multiple application objects, an application object whose object type belongs to the object type set as a first object belonging to the first category; The determining a second object belonging to a second category among the plurality of application objects comprises: Objects other than the first object among the plurality of application objects are regarded as second objects belonging to the second category.

11. An electronic device, characterized in that: include: one or more processors; One or more memories; the one or more memories store one or more programs, and when the one or more programs are executed by the one or more processors, the electronic device executes the memory management method described in any one of claims 1 to 10.

12. A storage medium, characterized in that: The storage medium stores instructions, which, when executed on an electronic device, enable the electronic device to execute the memory management method according to any one of claims 1 to 10.

13. A program product, characterized in that The method comprises: instructions, which, when executed on an electronic device, enable the electronic device to execute the memory management method according to any one of claims 1 to 10.

Citation Information

Patent Citations

  • Object storage system based on blue light and storage method thereof

    CN111475102A

  • Memory management method and device and electronic equipment

    CN115357389A

  • Object management method and device

    CN116737350A

  • Method for controlling memory and electronic equipment

    CN116820734A

  • Physical page cold and hot identification method and device, chip and storage medium

    CN117762830A