Garbage recycling method and device

By implementing a garbage collection method in electronic devices, scanning and removing garbage objects in response to activity exit, the problem of low memory management efficiency in the existing technology is solved, the startup frequency of Full GC is reduced, and the overall garbage collection efficiency and user experience are improved.

CN119718679AActive Publication Date: 2025-03-28HONOR DEVICE CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

In the prior art, the memory management efficiency of electronic devices is low, especially when the application run time increases, the startup frequency and time consumption of Full GC increases, resulting in frequent pauses of applications.

Method used

By implementing a garbage collection method in electronic devices, in response to the exit of the activity, it scans and removes garbage objects in the area corresponding to the activity, and reduces the startup frequency of Full GC.

Benefits of technology

This method removes garbage objects in a timely manner without starting Full GC, reducing the startup frequency of Full GC and improving the efficiency and user experience of memory management.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119718679A_ABST
    Figure CN119718679A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computers, and provides a garbage recycling method and device. In the method, in response to quit of a first activity in n activities, the electronic equipment searches and clears garbage objects in a recovery area according to a reference relationship of root objects. Wherein the memory area comprises a young area, an old area and n areas corresponding to the n activities respectively. Each region at least comprises a first region corresponding to the homepage surface, and each region comprises an active young region coinciding with the young region and an active old region coinciding with the old region. The recycling area comprises a young area and a second area corresponding to the first activity. According to the method, when the activity exits each time, the junk objects of the old age area and the young age area of the activity in the second area are cleared away in time, the starting frequency of Full GC is reduced, consumed time is small, and the memory management efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a garbage collection method and device. Background Art

[0002] Electronic devices usually use the garbage collector in the Android runtime (ART) to manage the memory area occupied by applications. The garbage collection mechanisms currently used by the garbage collector in ART include young garbage collection (Young GC) and full garbage collection (Full GC). Among them, Young GC is used to recycle garbage objects with a short life cycle, and Full GC is used to recycle garbage objects with a long life cycle through global search. When using Young GC for garbage collection, it takes less time. When using Full GC for garbage collection, it takes a long time.

[0003] As the application runtime increases, the memory area allocated by the electronic device for the application is used more and more, and the Full GC is started more and more frequently, which takes more time. Therefore, the overall efficiency of memory management of third-party applications is currently low. Summary of the invention

[0004] The embodiments of the present invention provide a garbage collection method and device for improving the overall efficiency of memory management of an electronic device.

[0005] The first aspect of the present application provides a garbage collection method, which can be applied to electronic devices. Unless otherwise specified, the "electronic device" in the implementation mode of the present application can refer to the electronic device itself, or a component in the electronic device (for example, a processor, a chip, or a chip system, etc.), or a logic module or software that can realize all or part of the functions of the electronic device.

[0006] The method includes: in response to the exit of the first activity among n activities, the electronic device can scan the young generation area in the memory area and the second area corresponding to the first activity starting from each root object according to the reference relationship of each root object, and obtain and clear garbage objects, where n is a natural number greater than 1. Among them, the memory area can be divided into a young generation area, an old generation area, and n areas corresponding to n activities. The young generation area is used to store objects when n activities are created, and the old generation area is used to store surviving objects after garbage collection. Among the n areas, at least one first area corresponding to a main page can be included, and the area corresponding to each activity overlaps with the old generation area and the young generation area respectively. That is, the area corresponding to each activity includes an active young generation area that overlaps with the young generation area, and an active old generation area that overlaps with the old generation area.

[0007] It can be understood that the memory area in the embodiment of the present application is the memory area occupied by the application. The above-mentioned garbage collection method can promptly clear the garbage objects in the area corresponding to the exited activity and the young generation area each time the activity exits. Compared with Full GC's global traversal and removal of garbage objects in the old generation area and the young generation area, this method only performs garbage cleaning on the young generation area and the active old generation area in the area corresponding to the exited activity, which consumes less time. In addition, in the existing garbage collection method, garbage objects with a long life cycle in the old generation area can only be cleaned up by FullGC, and by using this method to timely clear the garbage objects in the area corresponding to the exited activity and the area overlapping with the old generation area, the startup frequency of Full GC can be reduced, and the overall garbage collection efficiency and memory management efficiency can be improved.

[0008] In a possible implementation of the first aspect above, the method also includes: obtaining surviving objects in the young generation area and the second area, and moving the surviving objects in the active young generation area and the active old generation area in the second area, and the active young generation area in the first area, to the active old generation area in the first area.

[0009] It can be understood that in the above-mentioned garbage collection method, after the first activity exits, it switches to the main page. After obtaining the surviving objects in the recycling area (such as the young generation area and the second area), the electronic device can move the surviving objects in the active young generation area and the active old generation area in the second area, and the active young generation area in the first area, to the active old generation area in the first area, and release the area corresponding to the surviving objects. Moreover, after these surviving objects become garbage objects, they can be cleared by Full GC; or they can be cleared by starting the above-mentioned garbage collection method after the main page exits. Compared with the garbage collection mechanism that only includes Young GC and Full GC, the above-mentioned garbage collection method can cooperate with Young GC and Full GC to jointly perform garbage collection, reduce the startup frequency of Full GC, and make the overall garbage collection efficiency higher.

[0010] In a possible implementation of the first aspect above, the root objects include: root objects with cross-activity reference relationships, root objects in the running stack, root objects in the native method stack, root objects in static variables, and root objects in the Android card table.

[0011] It can be understood that the Android card table is the ART card table in the Android system. The root object with cross-activity reference relationship can be the root object with cross-activity reference relationship stored in the cross-activity table below, which is used to quickly find the surviving object with cross-activity reference relationship, and improve the correctness and efficiency of garbage collection after the first activity exits.

[0012] In a possible implementation of the first aspect above, live objects include objects that have a direct reference relationship and an indirect reference relationship with the root object; and garbage objects include objects that have neither a direct reference relationship nor an indirect reference relationship with the root object.

[0013] It can be understood that live objects and garbage objects can be searched in the recycling area based on the reference relationship starting from the root object. In the search process, objects that can be accessed from the root object and are in the recycling area are live objects. Objects that cannot be accessed from the root object and are in the recycling area are garbage objects.

[0014] In a possible implementation of the first aspect above, the n areas corresponding to the n activities are determined based on the activities to which the objects belong and the areas occupied by the objects in the memory area.

[0015] It can be understood that in some embodiments, the memory area is divided into areas corresponding to each activity, and the area occupied by each object is marked according to the activity to which the object belongs. The area corresponding to each activity can be accurately divided in the memory area, so that the recovery area can be accurately determined.

[0016] In a possible implementation of the first aspect above, the n regions corresponding to the n activities are divided based on the activities to which the objects in the third region belong, and the third region is a subset of the young generation region or the old generation region, and the young generation region and the old generation region respectively include multiple third regions of the same size.

[0017] It can be understood that in some embodiments, the memory area is divided into an old generation area and a young generation area, and the old generation area and the young generation area each include a plurality of sub-areas of the same size, namely, the third area. According to the activities to which the objects stored in each third area belong, each third area is marked as the third area corresponding to each activity, and finally the memory area can be accurately marked as each area corresponding to each activity, so that the recovery area can be accurately determined. Moreover, marking according to each third area has fewer marking times and occupies less memory than marking each object, thereby achieving the purpose of reducing memory overhead.

[0018] In a possible implementation of the first aspect above, the method further includes: switching to a second activity among the n activities.

[0019] It is understood that in some embodiments, if there is a first activity and a main page, then when the first activity is exited, it will switch to the main page. If there is a first activity, a main page, and a second activity, when the first activity is exited, it can switch to the second activity.

[0020] In a possible implementation of the first aspect above, the method further includes: moving surviving objects in an activity young generation area in a fourth area corresponding to the second activity to an activity old generation area in the fourth area.

[0021] It can be understood that when the first activity exits and switches to the second activity, the surviving objects in the active young generation area in the fourth area corresponding to the second activity can be moved to the active old generation area in the fourth area, and the area corresponding to the surviving objects is released. Moreover, after these surviving objects become garbage objects, they can be cleared by Full GC, or by starting the above garbage collection method after the second activity exits, and the overall garbage collection efficiency is high.

[0022] The second aspect of the present application provides an electronic device, including a processor and an interface circuit, the interface circuit is used to receive signals from other communication devices and transmit them to the processor or send signals from the processor to other communication devices, and the processor implements any one of the methods in the above first aspect through logic circuits or executing code instructions.

[0023] A third aspect of the present application provides a program product, which includes instructions. When the instructions are executed on an electronic device, the electronic device implements any one of the methods in the first aspect.

[0024] A fourth aspect of the present application provides a communication device, which includes a module for executing any one of the methods in the first aspect.

[0025] The fifth aspect of the present application provides a computer-readable storage medium, on which a computer program or instruction is stored. When the computer program or instruction is executed by a communication device, any one of the methods in the above-mentioned first aspect is implemented.

[0026] The sixth aspect of the present application provides a chip, which includes a processor, the processor is coupled to a memory, and is used to execute a computer program or instruction stored in the memory to implement any one of the methods in the first aspect above.

[0027] The seventh aspect of the present application provides a system, which includes a memory for storing instructions executed by one or more processors, and a processor, which is one of the processors of the system, for calling instructions to execute any one of the methods in the first aspect above.

[0028] It can be understood that the beneficial effects of the second to seventh aspects mentioned above refer to the first aspect and various possible implementations, and will not be elaborated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] In order to more clearly illustrate the technical solution of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the following drawings are only drawings of some embodiments of the present application. For ordinary technicians in this field, without paying any creative labor, other drawings that can also realize the technical solution of the present application can be obtained based on these drawings.

[0030] Figure 1 According to some embodiments of the present application, a schematic flow chart of a Full GC method is shown; Figure 2A According to some embodiments of the present application, a schematic diagram of an unlocking interface of a mobile phone 100 is shown; Figure 2B According to some embodiments of the present application, a schematic diagram of a main page of a shopping application is shown; Figure 2C According to some embodiments of the present application, a schematic diagram of an activity interface of a supermarket is shown; Figure 3A According to some embodiments of the present application, a schematic flow chart of a garbage collection method is shown; Figure 3B According to some embodiments of the present application, a flow chart of another garbage collection method is shown; Figure 4 According to some embodiments of the present application, a schematic diagram of memory partitioning is shown; Figure 5 According to some embodiments of the present application, a schematic diagram comparing an original Android allocation mechanism and an activity object grouping mechanism is shown; Figure 6 According to some embodiments of the present application, a schematic diagram of a garbage collection process based on an AGC mechanism is shown; Figure 7 According to some embodiments of the present application, a flow chart of a garbage collection method based on an AGC mechanism is shown; Figure 8 According to some embodiments of the present application, a schematic structural diagram of a communication device is shown; Fig. 9 According to some embodiments of the present application, a structural schematic diagram of an electronic device is shown; Fig.10 According to some embodiments of the present application, a schematic diagram of a system software architecture is shown; Fig.11 According to some embodiments of the present application, a schematic diagram of the hardware structure of a mobile phone is shown. DETAILED DESCRIPTION

[0031] In order to make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application.

[0032] The method provided in the embodiment of the present application can be applied to any electronic device, including but not limited to a mobile station (MS), a mobile terminal (MT), etc. For example, the electronic device can be a mobile phone, a smart TV, a wearable device, a tablet computer (Pad), a virtual reality (VR) device, an augmented reality (AR) device, a terminal in industrial control, a terminal in self-driving, a terminal in remote medical surgery, a terminal in a smart grid, a terminal in transportation safety, a terminal in a smart city, a terminal in a smart home, etc. The embodiment of the present application does not limit the specific form of the electronic device.

[0033] The "electronic device" in the embodiments of the present application may refer to the electronic device itself, or a component in the electronic device (for example, a processor, a chip, or a chip system, etc.), or a logic module or software that can implement all or part of the functions of the electronic device.

[0034] For the convenience of description, in the embodiments of the present application, the electronic device will be described by taking a smart phone as an example. It is understandable that the technical solution of the present application can also be applied to other electronic devices, which will not be described in detail here.

[0035] As described in the background technology, in the Android system, electronic devices usually manage memory areas through the garbage collector in ART. It can be understood that the memory area in the embodiment of the present application is the memory area occupied by the application. When the usage of the memory area reaches the upper limit, the garbage collector in ART will release the useless memory according to the garbage collection mechanism. The garbage collection mechanism is an automatic memory management mechanism. The garbage collection mechanism can be used to clear and recycle garbage objects in the memory area, release the corresponding area, and let other applications or objects use it. The garbage collection mechanism originated from the LISP language, and most high-level languages ​​support the garbage collection mechanism, such as Java, .net, Go, etc.

[0036] Currently, the garbage collection mechanism used by the garbage collector in ART includes Young GC and Full GC. Among them, Young GC is used to quickly recycle garbage objects with a short life cycle, and Young GC can efficiently recycle memory. Full GC is used to slowly globally scan and recycle garbage objects with a long life cycle. Full GC can find all useless garbage objects in the memory area in time and release them.

[0037] In some embodiments, ART divides the memory area into a young generation area and an old generation area. The startup mechanism of Young GC may include: when the storage amount in the young generation area reaches a first preset threshold, the garbage collector of ART may use Young GC to recycle garbage objects in the young generation area. The startup mechanism of FullGC may include: when the storage amount in the young generation area and the old generation area reaches a second preset threshold, the garbage collector of ART may use Full GC to scan all objects in the young generation area and the old generation area, find the garbage objects therein and release the memory. Among them, the young generation area includes newly allocated objects. After the garbage objects in the young generation area are recycled by Young GC or Full GC, the surviving objects will be moved to the old generation area. Surviving objects include objects that have direct reference relationships and indirect reference relationships with the root object; garbage objects include objects that have no direct reference relationship or indirect reference relationship with the root object. Since most of the newly allocated objects have a short life cycle and become garbage objects quickly, there are fewer surviving objects in the young generation area, and the Young GC takes less time. The objects in the old generation area have a long life cycle, and different objects become garbage objects at different times, making it difficult to predict when different objects will become garbage objects. Therefore, ART's garbage collector needs to use Full GC to scan all objects in the young generation area and the old generation area to find all garbage objects.

[0038] For example, in some embodiments, the process of Full GC executed by ART in the electronic device can be as follows: Figure 1 As shown, the following steps are included:

[0039] S101: traverse the memory area allocated to the application and mark unreachable objects (ie, garbage objects).

[0040] It can be understood that marking unreachable objects, also known as unreachable objects, is to facilitate the deletion of these unreachable objects in the subsequent steps. This step is called marking objects. In some possible implementations, ART will traverse the memory area, including all objects in the young generation area and the old generation area, find the area with low survival rate, and mark the unreachable objects in a rough marking manner. The area with low survival rate refers to the area with low occupancy rate of surviving objects.

[0041] Step S102: traverse the memory area again and delete unreachable objects.

[0042] In some possible implementations, when deleting unreachable objects, the garbage collector in ART will scan the memory area allocated to the application again, clean up the areas with low survival rates, delete the unreachable objects marked in the areas with low survival rates, and release their memory. It can be understood that when Full GC performs garbage collection through the above garbage collection method, the garbage collector needs to traverse all objects in the young generation area and the old generation area twice, and perform a global scan of the memory area twice, so it takes a long time.

[0043] As the application runs longer, the memory area allocated by the electronic device for the application is used more and more, and there are more and more long-lifecycle objects. The number of objects in the young and old generation areas is also increasing. Objects with long lifecycles cannot be recycled by Young GC and can only accumulate in the memory heap. Finally, Full GC can only be triggered frequently to recycle garbage objects in the young and old generation areas. It can be understood that starting Full GC at an appropriate frequency can effectively reduce the memory pressure of the system, but due to the increasing usage of the memory area, the Full GC based on global scanning takes longer and longer. Frequently starting Full GC puts additional burden on the central processor of the electronic device, causing the application to be frequently suspended.

[0044] Therefore, the garbage collection mechanism adopted by the garbage collector in ART makes the overall efficiency of memory management low.

[0045] In view of this, the present application provides a garbage collection method for electronic devices. When an activity created by a third-party application exits, the method scans and clears the memory area occupied by the activity and the garbage objects in the young generation area according to the reference relationship of each root object, and releases the area corresponding to the garbage object.

[0046] Specifically, ART can divide the memory area into a young generation area, an old generation area, and areas corresponding to each activity. Among them, the young generation area is used to store newly allocated objects, and the old generation area is used to store surviving objects after garbage collection. The areas corresponding to each activity store the objects corresponding to each activity respectively. It can be understood that the area corresponding to each activity can include an area that overlaps with the young generation area, called an active young generation area, and an area that overlaps with the old generation area, called an active old generation area.

[0047] Furthermore, in some embodiments, ART may use a cross-activity table to record the cross-activity reference relationship of each object when a cross-activity reference relationship occurs for each object.

[0048] For example, if object M in the area corresponding to activity X points to an object in the area corresponding to activity Y, and activity X is different from activity Y, then object M is set to activity Y in the card of the cross-activity table. For another example, if object M in the area corresponding to activity X points to an object in the area corresponding to activity Y, and activity X is the same as activity Y, then object M is set to 0 in the card of the cross-activity table. For another example, if object M in the area corresponding to activity X points to objects in the areas corresponding to at least two activities, and the at least two activities are not activity X, then object M is set to multiple activities in the card of the cross-activity table. In addition, for some objects that have no reference relationship, their cards in the cross-activity table are also set to 0.

[0049] It is understandable that in some embodiments, other forms of tables for recording cross-activity reference relationships of objects may be used, such as indexes, bitmaps, etc. In the embodiments of the present application, no specific limitation is imposed on the form of recording cross-activity reference relationships of objects.

[0050] If an activity exits, such as the first activity exits, ART can scan the recycling area, find the root objects needed for the recycling area, and then start looking for garbage objects and surviving objects from each root object, and then clear the garbage objects and move the surviving objects to the corresponding area. The recycling area includes the area corresponding to the exited activity and the young generation area, such as Figure 6 The root objects required for recycling the area include: the root objects with cross-activity reference relationships in the cross-activity table (such as Figure 6 00 and object 01 in the ), the root object in the running stack, the root object in the local method stack, the root object in the static variable, and the root object in the Android card table. It can be understood that each object that can be accessed from the root object and is in the recycling area is a surviving object, such as Figure 6There are surviving objects 1, surviving objects 2, surviving objects 3 and surviving objects 4. If an object has no reference connection to the root object and is in the recycling area, the object is a garbage object.

[0051] The above garbage collection method promptly clears the garbage objects in the area occupied by the exited activity and the garbage objects in the young generation area each time an activity exits. This method clears the garbage objects that exist in both the area occupied by the exited activity and the old generation area without starting the Full GC. Compared with the global traversal and garbage removal of the young generation area and the old generation area by the Full GC, it not only takes less time, but also reduces the startup frequency of the Full GC due to the timely removal of garbage objects in some old generation areas, which not only improves the efficiency of memory management, but also improves the user experience.

[0052] Some terms involved in this application are first described below.

[0053] 1. Android runtime (ART): A managed runtime environment used by applications and some system services on the Android platform, responsible for executing and managing the runtime environment of applications. ART is a runtime library that provides core functions such as memory management, thread management, and garbage collection. ART plays an important role in the application life cycle, ensuring that applications run correctly and efficiently on Android devices.

[0054] 2. Memory area: In the embodiments of the present application, it specifically refers to the heap memory used to store objects. The heap is an area of ​​memory managed by the Java virtual machine and is shared by all application threads. It is created when the virtual machine starts. When the virtual machine executes a program, it creates an object and allocates a piece of memory for the object in the memory area, and the object is stored in the memory area. Since the virtual machine will continuously create objects and allocate memory, if an object is no longer referenced, it will become garbage and need to be garbage collected, otherwise the memory will be consumed and affect the operation of the program.

[0055] 3. Application activities: An important part of an application is a component that can contain a user interface (UI), usually used to interact with users. Each activity is responsible for handling specific user interactions. Each activity is implemented as a separate class and inherited from the activity base class. The activity class will display a user interface composed of view controls and respond to events.

[0056] 4. Objects are basic elements in the code of an application, such as strings, functions, variables, arrays, etc. In object-oriented programming languages, objects are instances of a class. Objects have unique identifiers, and objects include properties and methods. Methods are the services that an object can provide, and properties are the properties of an object (for example, data structures, domains, etc.).

[0057] 5. Root object: refers to an object that can reference other objects but cannot be referenced by other objects.

[0058] 6. Surviving objects: refers to objects that have a direct or indirect reference relationship with the root object, that is, every object that can be accessed from the root object. In a reference relationship, the first object pointing to the second object means that the first object references the second object, or the second object is referenced by the first object.

[0059] 7. Garbage object: If an object has no reference to the root object, the object is a garbage object.

[0060] 8. Garbage collection (GC): A memory management mechanism that uses the GC thread to recycle garbage objects in a memory area (or heap) to release the memory area. In other words, GC is an automatic memory management mechanism. When the dynamic memory on a computer is no longer needed, it should be released to make room for the storage area.

[0061] The following is based on Figures 2A to 7 The technical solution of this application is described in detail.

[0062] FIG. 2A to FIG. 2C A schematic diagram of a usage scenario of a third-party application is shown. Figure 2A Schematic diagram of the unlocking interface of the mobile phone 100 is shown. Figure 2A As shown, the unlocking interface 101 of the mobile phone 100 can display multiple third-party application icons, including: clock, calendar, file management, email, music card, video, sports health, weather, browser, smart life, settings, recorder, shopping, camera, address book, phone, information, etc. When the user needs to shop online, he can click the shopping application icon 102 in the unlocking interface 101. The mobile phone 100 can display the icon 102 of the shopping application on the display screen in response to the user's click operation. Figure 2B The main page 103 of the shopping application shown in FIG. When the user clicks any control in the main page 103 of the shopping application, such as the supermarket control 104, the mobile phone 100 can display the Figure 2C The activity interface 105 of the supermarket is shown.

[0063] It can be understood that an activity is an application component in the Android operating system component, and the interface of an application is composed of several activities. Each activity will get a window for drawing the user interface, on which various views (that is, the content displayed in the window) can be placed, as well as various display controls derived from the view, such as buttons and labels. Users can perform various operations on the window. Different applications can correspond to different activities. For example, the activity corresponding to the shopping application is different from the activity corresponding to the memo application. All activities will run on the process created by the system. When ART executes an application, each activity created will create a corresponding object and allocate memory for it in the memory area occupied by the application. For example, when the system creates the main page of a shopping application, it will create multiple objects corresponding to the main page. When the system creates an activity for a supermarket, it will also create multiple objects corresponding to the supermarket's activities. Since the memory space is limited, in order to use the memory reasonably, the garbage collector in ART will recycle the objects in the memory according to the garbage collection mechanism and release the corresponding memory.

[0064] It can be understood that in the Android system, when each activity exits, many objects allocated to the activity in the foreground period will become garbage objects and need to be destroyed after the activity exits. To this end, the embodiment of the present application proposes an activity garbage collector, which is set in ART and can be used to efficiently recycle useless memory and improve the overall memory management efficiency of ART. The activity garbage collector includes: (1) an activity object group (AOG) module, which is used to divide the area in the memory area and identify the object or the area occupied by the object according to the activity to which the object belongs. (2) an activity garbage collection (AGC) module, which is a garbage collection mechanism that can efficiently recycle the areas of the young generation area and the old generation area marked as exited activities. (3) a cross activity table (CAT) module, which is used to mark the cross-activity references of each object, so that the cross-activity references can be quickly found through the marking during garbage collection. (4) a trigger mechanism module, which is a garbage collection mechanism actively triggered by an activity, which can actively notify ART through the Android application framework layer (Framework) to start garbage collection when there is an activity exit, release memory in advance, and thus reduce memory pressure.

[0065] Based on the above active garbage collector, combined with Figures 3A to 11 , introduces the garbage collection method in the embodiment of the present application.

[0066] First, according to Figure 3A , a garbage collection method in an embodiment of the present application is introduced. The execution subject of the garbage collection method can be a mobile phone 100. Figure 3A As shown, a garbage collection method may include but is not limited to the following steps:

[0067] S301, in response to the exit of the first activity among n activities, the ART in the mobile phone 100 scans the young generation area in the memory area and the second area corresponding to the first activity according to the reference relationship of each root object to obtain garbage objects.

[0068] Exemplarily, the memory area includes a young generation area, an old generation area, and n areas corresponding to n activities, wherein the n areas include at least a first area corresponding to a main page, and each of the n areas includes an active young generation area overlapping with the young generation area, and an active old generation area overlapping with the old generation area. The young generation area is used to store objects when n activities are created, and the old generation area is used to store surviving objects after garbage collection, and n is a natural number greater than 1.

[0069] S302, the ART in the mobile phone 100 clears garbage objects.

[0070] It can be understood that Full GC can clean up long-life garbage objects in the young generation area and the old generation area. In the existing garbage collection method, long-life garbage objects in the old generation area can only be cleaned up by Full GC. According to the aforementioned Full GC startup mechanism, when the storage volume in the young generation area and the old generation area reaches the second preset threshold, ART's garbage collector can use Full GC to scan and clear garbage objects in the young generation area and the old generation area.

[0071] The above garbage collection method cleans up the garbage objects in the area corresponding to the exited activity and the young generation area in time every time an activity exits, which takes less time than Full GC. Moreover, without starting Full GC, the above garbage collection method clears the garbage objects in the old generation area of ​​the activity that overlaps with the old generation area in the area corresponding to the exited activity, so that the interval time for the storage amount in the young generation area and the old generation area to reach the second preset threshold is increased, thereby reducing the startup frequency of Full GC, improving the efficiency of memory management, reducing the suspension time of the application, and improving the user experience.

[0072] According to the following Figure 3B Another garbage collection method in the embodiment of the present application is introduced. The execution subject of the garbage collection method can be the mobile phone 100.

[0073] like Figure 3B As shown, a garbage collection method may include but is not limited to the following steps:

[0074] S3001, dividing the memory area into a young generation area, an old generation area, and n areas corresponding to n activities.

[0075] It can be understood that in some embodiments, in response to the start of the application, the ART in the mobile phone 100 can divide the memory area into a young generation area and an old generation area, and the young generation area and the old generation area can respectively include a plurality of third areas of the same size. Figure 4 As shown, the young generation area and the old generation area are respectively composed of a plurality of third areas, and each third area is of equal size. Among them, the third area of ​​the young generation area is called the young generation sub-area (Young Region), which is used to place objects newly allocated by the mobile phone 100 for the application. The third area of ​​the old generation area is called the old generation sub-area (Old Region), which is used to place objects that are still used after garbage collection, that is, surviving objects.

[0076] Furthermore, the active object grouping module in ART can group and mark each third area in the memory area according to the activity to which the stored object belongs, and obtain the active object grouping mark of each third area. According to the active object grouping mark of each third area, the memory area is divided into n areas corresponding to n activities, where n is a natural number greater than 1. The n areas include at least one first area corresponding to a main page, and each of the n areas includes an active young generation area that overlaps with the young generation area, and an active old generation area that overlaps with the old generation area.

[0077] In some embodiments, after the third-party application is started, when ART assigns an object to each third area, each third area may be marked based on the activity to which the assigned object belongs according to the activity object grouping module.

[0078] Figure 5 Figure 2 shows a comparison diagram of the original Android allocation mechanism and the active object grouping mechanism. Figure 5 As shown, the young generation area and the old generation area in the memory area each include several third areas, such as third area 1, third area 2, third area 3, third area 4, third area 5, third area 6, third area 7, etc., and each third area is equal in size. ART can continuously allocate objects in each third area.

[0079] When the application switches from the first activity to the second activity, according to the original Android allocation mechanism, each object is stored in the young generation area and the old generation area accordingly.

[0080] According to the active object grouping mechanism, ART allocates objects belonging to the same activity in the young generation area and the old generation area to the same third area, and marks each third area according to the activity to which the stored objects belong. Figure 5 For example, the third area 1 of the young generation area stores objects of the first activity, and the activity objects of the third area 1 are grouped and marked as the first activity; the third area 2 of the old generation area stores objects corresponding to the first activity, and the activity objects of the third area 2 are grouped and marked as the first activity; the third area 3 of the old generation area stores objects corresponding to the first activity, and the activity objects of the third area 3 are grouped and marked as the first activity; the third area 4 of the young generation area stores objects of the second activity, and the activity objects of the sub-area 4 are grouped and marked as the second activity; the third area 5 of the young generation area stores objects of the first activity, and the activity objects of the third area 5 are grouped and marked as the first activity; the third area 6 of the old generation area stores objects corresponding to the first activity, and the activity objects of the third area 6 are grouped and marked as the first activity; the third area 7 of the old generation area stores objects corresponding to the first activity, and the activity objects of the third area 7 are grouped and marked as the first activity, and so on.

[0081] It can be understood that by grouping and marking the third regions according to the activities to which the objects stored in the third regions belong, the memory region can be accurately divided into regions corresponding to the activities, thereby accurately determining the recycling region.

[0082] In some embodiments, after the third-party application is started, when ART allocates objects to the memory area, the area occupied by each object in the memory area can also be marked according to the activity to which each object belongs, and the activity object grouping mark of the area occupied by each object is obtained. According to the activity object grouping mark of the area occupied by each object, the memory area is divided into n areas corresponding to n activities, where n is a natural number greater than 1.

[0083] It can be understood that by grouping and marking the areas occupied by the objects in the memory area according to the activities to which the stored objects belong, the areas corresponding to the activities can be accurately divided, so that the reclaimed areas can be accurately determined. Compared with marking the areas occupied by the objects in the memory area according to the activities to which the stored objects belong, marking each third area in the young generation area and the old generation area according to the activities to which the stored objects belong requires fewer markings, occupies less memory, and requires less memory overhead.

[0084] S3002, marking the cross-activity reference relationship of each object in the memory area, and storing the mark of the cross-activity reference relationship in a cross-activity table.

[0085] It is understandable that ART can dynamically mark the cross-activity reference relationship of each object allocated to the application. In some embodiments, ART can write the cross-activity reference relationship into the memory occupied by each object when the cross-activity reference relationship appears, mark the cross-activity reference relationship during the writing process, and then store the cross-activity reference relationship in the cross-activity table. In some embodiments, ART can also mark and store the cross-activity reference relationship of each allocated object according to preset time or conditions. In the embodiments of the present application, there is no specific limitation on the frequency and time of marking and storing the cross-activity reference relationship of each object.

[0086] Specifically, the cross-activity table may include multiple cards, each of which corresponds to an area of ​​a predetermined size in the memory area, such as a 1KB area, and each card records a cross-activity reference relationship of an object.

[0087] For example, if in the third area of ​​the active object grouping marked as activity X, object M points to an object in the third area of ​​the active object grouping marked as activity Y, and activity X is different from activity Y, then the card corresponding to object M is set to activity Y. For another example, if in the third area of ​​the active object grouping marked as activity X, object M points to an object in the third area of ​​the active object grouping marked as activity Y, and activity X is the same as activity Y, then the card corresponding to object M is set to 0. For another example, if in the third area of ​​the active object grouping marked as activity X, object M points to objects in at least two third areas, and at least two third areas are not marked as activity X, then the card corresponding to object M is set to multiple activities, that is, Multiple activities. And, for some objects that have no reference relationship, their corresponding cards are also set to 0.

[0088] It can be understood that the cross-activity table borrows the write barrier of ART to record reference updates and expands the Android card table, that is, the ART card table in the Android system. The original ART card table only records the reference relationship between objects in the old generation area pointing to objects in the young generation area, while the cross-activity table records the cross-activity reference relationship between objects. Therefore, the cross-activity table does not require additional memory overhead and introduces new write barriers, and will not cause additional overhead to program operation. In addition, through the cross-activity table, cross-activity reference relationships can be quickly found, and the auxiliary AGC only needs to quickly find garbage objects in the recycling area and avoid global scans similar to Full GC. It can be understood that in some embodiments, other forms of tables that record cross-activity reference relationships of various objects can also be used, such as indexes, bitmaps (BitMap), etc. In the embodiments of the present application, there is no specific limitation on the form of recording the cross-activity reference relationship of each object.

[0089] S3003, when the first activity exits, garbage collection is started, and the root objects required for the recycling area are found according to the cross-activity reference relationship recorded in the cross-activity table and other reference relationships.

[0090] It can be understood that based on the trigger mechanism module in the activity garbage collector, the Android system framework layer can pass the life cycle of activity switching to ART to help ART determine the activity of the current application to exit and the activity to switch. When any activity exits, such as when the first activity exits, the Android system framework layer can actively notify ART to start garbage collection. ART will start the activity garbage collector to perform garbage collection on the recycling area. Among them, the recycling area includes the young generation area and all third areas where the activity objects are grouped and marked as the first activity, that is, the young generation area and the second area corresponding to the first activity.

[0091] It is understandable that the Young GC and Full GC in the existing garbage collection mechanism will continue to be retained to adapt to different garbage collection scenarios.

[0092] Figure 6 Figure 2 shows the garbage collection process based on the AGC mechanism. Figure 6 As shown, the memory area may include: an area marked as a first activity, an area marked as a second activity, and an area marked as a main page. When the first activity is exited, it may be switched to the second activity. It is understandable that Figure 6 The area corresponding to each activity in is only an example. In some embodiments, the memory area may include areas corresponding to more activities, or areas corresponding to fewer activities. In the embodiment of the present application, the memory area may include at least a second area where the activity objects are grouped and marked as the first activity, and a first area where the activity objects are grouped and marked as the main page, where the first activity is the exited activity. That is, when the first activity is exited, it can be switched to the main page.

[0093] In order to avoid the need for global search similar to Full GC, ART first finds the root objects required by AGC based on the cross-activity reference relationships recorded in the cross-activity table and other reference relationships. These root objects include: root objects with cross-activity reference relationships in the cross-activity table, root objects in the running stack, root objects in the local method stack, root objects in static variables, and root objects in the Android card table. Among them, the root objects with cross-activity reference relationships in the cross-activity table can include: Figure 6 In the example, object 00 points to live object 1, and object 01 points to live object 4. The reclaimed area includes the young generation area and the second area where the active objects are grouped and marked as the first activity. It can be understood that the cross-activity table can help the AGC to quickly find garbage objects in the reclaimed area and avoid the global scan of the Full GC.

[0094] S3004: Perform a local search in the recycling area according to each root object to find the surviving object, move the surviving object to the corresponding area, and clear the garbage object.

[0095] Specifically, in step S3004, a local search is performed in the recycling area according to each root object to find the surviving object, move the surviving object to the corresponding area, and clear the garbage object. Figure 7 shown. Figure 7 The garbage collection method based on the AGC mechanism may include but is not limited to the following steps:

[0096] S701, obtaining an object graph according to all root objects, all objects in the recycling area and reference relationships.

[0097] It can be understood that all root objects found by ART include: root objects with cross-activity reference relationships in the cross-activity table, root objects in the run stack, root objects in the native method stack, root objects in static variables, and root objects in the Android card table. These root objects, young generation areas, and all objects and reference relationships in the second area of ​​the first activity grouped as active objects can form an object graph.

[0098] S702: Mark all root objects as visited.

[0099] S703, traverse the object graph starting from the root object to find all surviving objects.

[0100] It is understood that the object graph is traversed from the root object to find all reachable objects, that is, surviving objects. During the traversal process, the visited objects are marked as visited. It is understood that the surviving objects are reachable objects that are in the recycling area.

[0101] S704: Move the surviving object to a corresponding area according to the active object grouping mark of the third area where the surviving object is located.

[0102] For example, if the object grouping in the third area where the surviving object is located is marked as the first activity, then the surviving object is moved to the active old generation area in the area of ​​the main page that overlaps with the old generation area. If the object grouping in the third area where the surviving object is located is marked as the main page, then the surviving object is moved to the active old generation area in the area of ​​the main page that overlaps with the old generation area. If the object grouping in the sub-area where the surviving object is located is marked as other activities, then the reachable object is moved to the active old generation area in the area where the object grouping is marked as other activities that overlaps with the old generation area. For example, when the first activity exits and switches to the second activity, you can do the following: Figure 6As shown, the surviving objects in the active young generation area in the fourth area corresponding to the second activity, such as the surviving object 4, are moved to the active old generation area in the fourth area. It can be understood that the objects moved to the old generation area can be recycled by Full GC when they become garbage objects.

[0103] S705, clear garbage objects.

[0104] It can be understood that after the traversal is completed, all visited objects are marked as visited, and unvisited objects are unreachable, that is, garbage objects. After clearing the garbage objects and completing the movement of the surviving objects, the memory corresponding to the surviving objects and garbage objects is released.

[0105] It can be understood that the above garbage collection method, based on the characteristics of applications consisting of multiple activities, improves the ART object allocation mechanism and efficiently groups objects according to the activities in which the application is in when the objects are allocated, so as to help the garbage collection mechanism quickly find objects created by the activities. After the activity exits, garbage collection is used to clean up the groups corresponding to the exited activities. With almost no additional overhead introduced to Full GC and Young GC, AGC is used to actively, efficiently and timely clean up long-lifecycle objects, reducing the startup frequency of Full GC and improving the overall efficiency of ART garbage collection.

[0106] The above garbage collection method can start garbage collection when the activity exits, and promptly clear the garbage objects belonging to the exited activity and the garbage objects in the young generation area, which takes less time, avoids the frequent start of Full GC, reduces the application suspension time, and improves the efficiency of memory management and user experience. In addition, with the assistance of the cross-activity table, all root objects in the recycling area are found, which improves the correctness of garbage collection and the efficiency of finding surviving objects.

[0107] It can be understood that the AGC mechanism finds live objects by performing a depth-first search on objects and references in the reclaimed area, and identifies unaccessed objects as garbage objects. It can be divided into the following two steps: Step (A): In order to avoid a global search like Full GC, the AGC mechanism can find the reclaimed area (including Figure 6The root objects required for the young and middle generation areas and the area corresponding to the first activity to exit) include root objects with cross-activity reference relationships in the cross-activity table, root objects in the running stack, root objects in the local method stack, root objects in static variables, and root objects in the Android card table. Step (B): Perform a local depth-first search in the reclaimed area to find the surviving objects therein and move them to the corresponding memory area. The surviving objects in the second area corresponding to the first activity to exit are moved to the active old generation area of ​​the first area corresponding to the main page. The surviving objects in the first area corresponding to the main page are moved to the active old generation area of ​​the first area corresponding to the main page. The surviving objects in the area corresponding to the activities that have not exited are moved to the active old generation area of ​​the area corresponding to the activities that have not exited. When these surviving objects become useless later, use Full GC to recycle. After completing the movement of the surviving objects, release the corresponding memory.

[0108] It can be understood that when there is an activity exit, the above garbage collection method actively triggers garbage collection, and promptly recycles a large number of garbage objects generated by the activity exit, effectively reducing the memory pressure of the system. Since garbage collection runs through the entire life cycle of the program, the garbage collection performance has a great impact on the business. Currently, the garbage collection performance is mainly reflected in the throughput. The throughput is the ratio of the total amount of released memory to the time taken for garbage collection. The higher the throughput, the better the garbage collection performance. Table 1 shows the throughput of Android's original garbage collection mechanism and the throughput of the garbage collection mechanism of the embodiment of the present application.

[0109] Table 1:

[0110] It can be understood that the original garbage collection mechanism of Android in Table 1 includes Young GC and Full GC, and the garbage collection mechanism of the embodiment of the present application includes AGC, Young GC and Full GC. As can be seen from Table 1, by adopting the garbage collection mechanism of the embodiment of the present application, the throughput of each application has been greatly improved, for example, from 22% to 149%.

[0111] Table 2 shows the time consumed by AGC, Young GC, and Full GC.

[0112] Table 2:

[0113] As can be understood from Table 2, the time consumption of AGC is higher than that of Young GC, but much less than that of Full GC. By combining AGC with Young GC and Full GC for garbage collection and reducing the startup frequency of Full GC, the overall garbage collection efficiency can be greatly improved.

[0114] Table 3 shows the start interval of Full GC in the original Android system and the start interval of Full GC in the embodiment of the present application.

[0115] Table 3:

[0116] It can be understood from Table 3 that the AGC mechanism in the embodiment of the present application prolongs the start interval of the Full GC, reduces the impact on the user's foreground use, and can greatly improve the overall garbage collection efficiency.

[0117] In order to better implement the above-mentioned solution of the embodiment of the present application, relevant devices for implementing the above-mentioned solution are also provided below.

[0118] See also Figure 8 , is a structural diagram of a communication device provided in an embodiment of the present application, which is used to implement the functions of the electronic device in the above method embodiment. In some possible implementations, the communication device 800 provided in the embodiment of the present application may include a storage module 801 (sometimes also referred to as a storage unit), which is used to store any data, computer instructions and / or computer programs that may be involved in the embodiments of the present application; and a processing module 802 (sometimes also referred to as a processing unit), which is used to respond to the exit of the first activity in the n activities, scan the young generation area in the memory area and the second area corresponding to the first activity according to the reference relationship of each root object, obtain garbage objects, and clear the garbage objects, wherein the memory area includes a young generation area, an old generation area, and n areas corresponding to n activities, the n areas at least include a first area corresponding to a main page, each of the n areas includes an active young generation area overlapping with the young generation area, and an active old generation area overlapping with the old generation area, the young generation area is used to store objects when creating n activities, and the old generation area is used to store surviving objects after garbage collection, and n is a natural number greater than 1.

[0119] The device may also include a transceiver module (sometimes also referred to as a transceiver unit). The transceiver module can implement a sending function and a receiving function. When the transceiver module implements the sending function, it may be called a sending module (sometimes also referred to as a sending unit), and when the transceiver module implements the receiving function, it may be called a receiving module (sometimes also referred to as a receiving unit). The sending module and the receiving module may be the same functional module, which is called a transceiver module, and the functional module can implement the sending function and the receiving function; or, the sending module and the receiving module may be different functional modules, and the transceiver module is a general term for these functional modules.

[0120] For more detailed operation of the storage module 801 and the processing module 802, reference may be made to the description in the above method embodiment, which will not be repeated here.

[0121] It should be noted that the physical device corresponding to the storage module 801 in the present device may be a memory, the physical device corresponding to the processing module 802 may be a processor, and the physical device corresponding to the transceiver module may be a transceiver.

[0122] It should be noted that the information interaction, execution process and other contents between the modules of the above-mentioned device are based on the same concept as the method embodiment of the present application, and the technical effects they bring are the same as those of the method embodiment of the present application. For specific contents, please refer to the description in the method embodiment shown above in the present application, and will not be repeated here.

[0123] See also Fig. 9 , is a structural diagram of an electronic device 900 provided in an embodiment of the present application.

[0124] like Fig. 9 As shown, the electronic device includes a processor 910 and an interface circuit 920. The processor 910 and the interface circuit 920 are coupled to each other. It is understandable that the interface circuit 920 can be a transceiver or an input-output interface. Optionally, the electronic device 900 may also include a memory 930 for storing instructions executed by the processor 910, such as garbage collection instructions, etc., or storing input data required by the processor 910 to run instructions or storing data generated after the processor 910 runs instructions, such as grouping tags of active objects in each third area in the memory area, cross-activity reference relationships of each object, etc.

[0125] When the electronic device 900 is used to implement the above-mentioned garbage collection method and other embodiments, the processor 910 is used to implement the functions of the above-mentioned processing module 802, and the interface circuit 920 is used to implement the functions of the above-mentioned transceiver module.

[0126] When the above-mentioned electronic device is a chip applied to a terminal, the terminal chip realizes the functions of the electronic device in the above-mentioned method embodiment.

[0127] It can be understood that an operating system is running in the mobile phone 100. The embodiment of the present application takes the Android system with a layered architecture as an example to illustrate the software structure of the mobile phone 100. Fig.10 1 is a schematic diagram of the system software architecture of the mobile phone 100. The software structure adopts a layered architecture, which divides the software into several layers, and each layer has a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into five layers, from top to bottom, namely, the application layer, the application framework layer (Framework), the Android runtime (android runtime, ART) and the system library, the hardware abstraction layer (hardware abstraction layer, HAL), and the kernel layer (Kernel).

[0128] The application layer may include a series of application packages, including camera, gallery, calendar, call, map, navigation, wireless local area network (WLAN), Bluetooth, music, video, short message and other applications.

[0129] The application framework layer provides an application programming interface (API) and a programming framework for applications in the application layer. The application framework layer includes some predefined functions. For example, the application framework layer may include a window manager, a content provider, a phone manager, a resource manager, a notification manager, a view system, etc.

[0130] The window manager is used to manage window programs. The window manager can obtain the size of the display screen and set the windows corresponding to each display interface according to the properties of the window. The content provider is used to store and obtain data and make the data accessible to the application. The stored data may include video data, image data, audio data, etc. The phone manager is used to provide communication functions for the mobile phone 100. For example, the management of call status (including call connection, hang up, etc.). The resource manager provides various resources for the application, such as localized strings, icons, pictures, layout files, video files, etc. The notification manager enables the application to display notification information in the status bar of the screen, which can be used to convey messages to the user. The view system includes visual controls, such as controls for displaying text, controls for displaying pictures, etc. The view system can be used to build applications. The display interface can be composed of one or more views.

[0131] ART includes a core library and a virtual machine. ART is responsible for the scheduling and management of the Android system, and the garbage collector in the embodiment of the present application is set in ART. The core library contains two parts: one part is the function function that needs to be called by the Java language, and the other part is the core library of Android.

[0132] The application layer and the application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.

[0133] The system library can include multiple functional modules, such as surface manager, media library, three-dimensional (3D) graphics processing library (for example, OpenGLES), two-dimensional (2D) graphics engine, etc.

[0134] The surface manager is used to manage the display subsystem of electronic devices and provide fusion of 2D and 3D layers for multiple applications. The media library supports playback and recording of multiple common audio and video formats, as well as static image files. The media library can support multiple audio and video encoding formats. The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, synthesis, and layer processing. The 2D graphics engine is a drawing engine for 2D drawing.

[0135] The hardware abstraction layer (HAL) encapsulates the hardware driver and provides a common interface for calling the driver to the framework layer. The hardware abstraction layer includes the touch panel (TP) HAL, display HAL, sensor HAL, etc.

[0136] The kernel layer is the layer between hardware and software. The kernel layer contains at least display driver, camera driver, audio driver, and sensor driver.

[0137] Fig.11 According to an embodiment of the present application, a schematic diagram of the hardware structure of a mobile phone 100 is shown. The mobile phone 100 may be the electronic device mentioned in the above embodiment.

[0138] The mobile phone 100 may include a processor 110, an external memory interface 120, an internal memory 121, an interface module 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.

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

[0140] Processor 110 may include one or more processing units.

[0141] The charging management module 140 is used to receive charging input from a charger. The power management module 141 is used to connect the battery 142 , the charging management module 140 and the processor 110 .

[0142] The wireless communication function of the mobile phone 100 can be realized by antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modem processor and baseband processor. Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Mobile communication module 150 can provide solutions for wireless communication including 2G / 3G / 4G / 5G etc. applied on the mobile phone 100. Wireless communication module 160 can provide solutions for wireless communication including wireless local area networks (WLAN) etc. applied on the mobile phone 100.

[0143] In some embodiments, the antenna 1 of the mobile phone 100 is coupled to the mobile communication module 150, and the antenna 2 is coupled to the wireless communication module 160, so that the mobile phone 100 can communicate with the network and other devices through wireless communication technology.

[0144] The mobile phone 100 implements the display function through a graphics processing unit (GPU), a display screen 194, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 194 and the application processor. The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The camera 193 is used to capture static images or videos.

[0145] 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 mobile phone 100. The internal memory 121 can be used to store computer executable program codes, and the executable program codes include instructions. The internal memory 121 may include a program storage area and a data storage area. For example, the program storage area can be used to store computer instructions and / or computer programs corresponding to the above-mentioned garbage collection methods, algorithms, etc. The data storage area can be used to store the active object grouping tags of each third area in the above-mentioned memory area, the cross-activity reference relationship of each object, etc.

[0146] The mobile phone 100 can implement audio functions such as music playing and recording through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the earphone interface 170D, and the application processor.

[0147] The pressure sensor 180A is used to sense the pressure signal and convert the pressure signal into an electrical signal. The gyroscope sensor 180B can be used to determine the motion posture of the mobile phone 100. The air pressure sensor 180C is used to measure the air pressure. The magnetic sensor 180D includes a Hall sensor. The acceleration sensor 180E can detect the magnitude of the acceleration of the mobile phone 100 in various directions (generally three axes). The distance sensor 180F is used to measure the distance. The proximity light sensor 180G can include, for example, a light emitting diode (LED) and a light detector. The ambient light sensor 180L is used to sense the brightness of the ambient light. The fingerprint sensor 180H is used to collect fingerprints. The temperature sensor 180J is used to detect the temperature. The touch sensor 180K is also called a "touch device". The button 190 includes a power button, a volume button, etc. The motor 191 can generate a vibration prompt. The indicator 192 can be an indicator light, which can be used to indicate the charging status, the change of the power, and can also be used to indicate messages, missed calls, notifications, etc. The SIM card interface 195 is used to connect the SIM card.

[0148] It is understood that the structure of the electronic device shown in the embodiment 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.

[0149] The various embodiments of the mechanism disclosed in the present application can be implemented in hardware, software, firmware or a combination of these implementation methods. The embodiments of the present application can be implemented as a computer program or program code executed on a programmable system, which includes 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.

[0150] 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.

[0151] 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 a floppy disk, an optical disk, an optical disk, a magneto-optical disk, a read-only memory (ROM), a random access memory (RAM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a magnetic card or an optical card, a flash memory, or a tangible machine-readable memory for transmitting information (e.g., a carrier wave, an infrared signal, a digital signal, etc.) using the Internet in an electrical, optical, acoustic, or other form of propagation signal. Accordingly, machine-readable media includes 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.

[0152] The present application also provides a system that may include at least one processor that executes instructions stored in a non-transitory computer-readable medium such as a memory. The processor may be any conventional processor, such as a commercially available central processing unit (CPU). Alternatively, the processor may be a dedicated device such as an application specific integrated circuit (ASIC) or other hardware-based processor.

[0153] An embodiment of the present application further provides a communication device, which includes a module for executing the methods in the above embodiments.

[0154] An embodiment of the present application further provides a chip, which includes a processor, and the processor is coupled to a memory, and is used to execute a computer program or instruction stored in the memory to implement the methods in the above embodiments.

[0155] In addition, an embodiment of the present application further provides a computer-readable storage medium, on which instructions are stored, and when the instructions are executed on an electronic device, the electronic device executes the methods in the above aspects.

[0156] In addition, an embodiment of the present application further provides a computer program product, which includes: a computer program code, and when the computer program code is executed on a computer, the computer executes the methods in the above aspects.

[0157] 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.

[0158] 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.

[0159] While the present invention has been shown 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 invention.

Claims

1. A garbage collection method, characterized in that: include: In response to the exit of the first activity among the n activities, according to the reference relationship of each root object, a young generation area in a memory area and a second area corresponding to the first activity are scanned to obtain garbage objects, wherein the memory area includes a young generation area, an old generation area, and n areas corresponding to the n activities, the n areas at least include a first area corresponding to a main page, each of the n areas includes an active young generation area overlapping with the young generation area, and an active old generation area overlapping with the old generation area, the young generation area is used to store objects when the n activities are created, and the old generation area is used to store surviving objects after garbage collection, and n is a natural number greater than 1; Clear the garbage object.

2. The method according to claim 1, characterized in that The method further comprises: Obtain surviving objects in the young generation area and the second area; The surviving objects in the active young generation area and the active old generation area in the second area, and the active young generation area in the first area, are moved to the active old generation area in the first area.

3. The method according to claim 2, characterized in that The root objects include: root objects with cross-activity reference relationships, root objects in the run stack, root objects in the native method stack, root objects in static variables, and root objects in the Android card table.

4. The method according to claim 2, characterized in that: The surviving objects include objects that have direct reference relationships and indirect reference relationships with the root object; The garbage objects include objects that have no direct reference relationship or indirect reference relationship with the root object.

5. The method according to claim 1, characterized in that The n regions corresponding to the n activities are determined based on the activities to which the objects belong and the regions occupied by the objects in the memory area.

6. The method according to claim 1, characterized in that The n regions corresponding to the n activities are divided based on the activities to which the objects in the third region belong, the third region is a subset of the young generation region or the old generation region, and the young generation region and the old generation region respectively include multiple third regions of the same size.

7. The method according to claim 1, characterized in that The method further comprises: Switch to a second activity among the n activities.

8. The method according to claim 7, characterized in that The method further comprises: Move surviving objects in an active young generation area in a fourth area corresponding to the second activity to an active old generation area in the fourth area.

9. An electronic device, characterized in that: The method comprises a processor and an interface circuit, wherein the interface circuit is used to receive signals from other communication devices and transmit them to the processor or send signals from the processor to other communication devices, and the processor implements the method as claimed in any one of claims 1 to 8 through a logic circuit or by executing code instructions.

10. A program product, characterized in that The program product includes instructions, and when the instructions are executed, the method according to any one of claims 1 to 8 is implemented.

11. A communication device, characterized in that: Comprising modules for executing the method as claimed in any one of claims 1 to 8.

12. A computer-readable storage medium, characterized in that: The storage medium stores a computer program or an instruction. When the computer program or the instruction is executed by the communication device, the method according to any one of claims 1 to 8 is implemented.

13. A chip, characterized in that: The chip comprises a processor, which is coupled to a memory and is used to execute a computer program or instruction stored in the memory, so that the chip implements the method described in any one of claims 1 to 8.

Citation Information

Patent Citations

  • System and method for dynamically selecting a garbage collection algorithm based on the contents of heap regions

    CN105453054A

  • System internal memory control method and system thereof

    CN105573811A

  • Resource recovery method and apparatus

    CN108459898A

  • Application memory leakage detection method and device, electronic equipment and storage medium

    CN109558308A

  • Concurrent remembered set scanning

    US12147336B1