Memory management method, electronic equipment and computer readable storage medium

By responding to the application in an electronic device, copying and releasing the corresponding memory page, the problem of the backend application occupying too much memory causes the foreground application to run unstable, improving the user experience.

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

Patent Information

Application Number
CN202510118476.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-24
Publication Date
2025-03-07
Estimated Expiration
2045-01-24

AI Technical Summary

Technical Problem

In electronic devices, due to the increase in the number of applications running in the background, the memory usage is too large, which in turn causes the front-end applications to fail to run normally due to insufficient memory, causing lag, and the user experience is poor.

Method used

By switching from the foreground to the background to run in response to the application, the first page is determined, and the accessed objects stored in the first page are copied into the target page of memory, and the objects are copied to the storage area other than memory, and the multiple first pages are released to recycle the memory space occupied by the unreached object.

Benefits of technology

It increases the memory available capacity of electronic devices, ensures that the front desk application has sufficient memory usage, makes it run smoother, and improves the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119576583A_ABST
    Figure CN119576583A_ABST
Patent Text Reader

Abstract

The invention provides a memory management method, electronic equipment and a computer readable storage medium, and relates to the technical field of computers. The electronic equipment can respond to the situation that the application is switched from the foreground to the background to run, and a first page is determined from a plurality of pages distributed for the application in a memory of the electronic equipment; the method comprises the following steps: intensively storing objects which are dispersedly stored in different first pages and accessed by an application in one or more target pages, copying all the objects stored in the plurality of first pages to a storage area except a memory, and releasing the plurality of first pages, therefore, the memory space occupied by the objects which are not accessed by the application and stored in the first pages can be recycled. Therefore, the electronic equipment can obtain more available memories, so that the applications running in the foreground can have more sufficient memories to a certain extent, the applications can run more smoothly, and the user experience is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a memory management method, an electronic device, and a computer-readable storage medium. Background Art

[0002] With the development of technology, there are more and more types of applications. In order to improve the user experience, electronic devices can support applications running in the background. For example, a chat application running in the background can receive messages and notify users in time to improve communication efficiency. Another example is that a music application can play music in the background, allowing users to enjoy music while performing other tasks.

[0003] Internal memory can be referred to as memory, which is a storage device that can be directly addressed by the central processing unit (CPU) in an electronic device. In the prior art, when an application is running in the foreground or background, whether it is a third-party application or a system application, it is necessary to store the running data of the application in the storage area allocated by the electronic device for the application in the memory, so that the electronic device can access the running data of the application more quickly, thereby running the application at a smoother speed. However, due to hardware conditions, the capacity of the memory in an electronic device is limited.

[0004] As the time users spend using electronic devices increases, the number of applications running in the background may increase, and electronic devices generally run these applications in the background for a long time until the applications running in the background are closed, such as when the user manually closes the background application or the operating system closes the background application when cleaning up data. It is understandable that the more applications running in the background, the more memory will be occupied, resulting in less available memory capacity. In this way, when there are many applications running in the background in an electronic device, the application running in the foreground may not be able to run normally due to insufficient memory, resulting in a freeze phenomenon, and a poor user experience. Summary of the invention

[0005] The present application provides a memory management method, an electronic device, and a computer-readable storage medium, which can, to a certain extent, enable applications running in the foreground to have more sufficient memory usage, enable them to run more smoothly, and improve user experience.

[0006] In order to achieve the above objectives, this application adopts the following technical solutions:

[0007] In a first aspect, the present application provides a memory management method, which is applied to an electronic device, the method comprising: in response to an application switching from the foreground to the background, determining a first page from multiple pages allocated to the application in the memory of the electronic device; wherein the page allocated to the application is used to store objects corresponding to the functions of the application; in the case where there are multiple first pages, copying the first objects stored in the multiple first pages to a target page in the memory, and copying all the objects stored in the multiple first pages to a storage area other than the memory, and releasing the multiple first pages; wherein the first page is a page among the multiple pages that meets a condition, and the condition includes: the page includes a first object and a second object; the first object is an object accessed by the application within a first time period after the application switches from the foreground to the background, and the second object is an object not accessed by the application within the first time period.

[0008] In the above scheme, by centrally storing the objects accessed by the application that are scattered and stored in different pages in one or more pages, and releasing the pages that originally stored the accessed objects, the memory space occupied by the objects stored in these pages that are not accessed by the application can be recovered, and the storage space that can be reused in the memory becomes larger, that is, the remaining available capacity of the memory becomes larger. In this way, the electronic device can obtain more available memory, which can, to a certain extent, enable the application running in the foreground to have more sufficient memory usage, so that it can run more smoothly and improve the user experience.

[0009] In a possible implementation of the first aspect, the condition in the above solution may further include: the ratio of the size of the first object included in the page to the size of the page is less than a threshold. That is, if the ratio of the size of the first object included in the page to the size of the page is less than the threshold, the page is determined to be the first page. If the ratio of the size of the first object included in the page to the size of the page is greater than or equal to the threshold, no processing is performed on the page.

[0010] In a possible implementation of the first aspect, before acquiring the first page from a plurality of pages allocated to the application in the memory of the electronic device, the method further includes: determining a first object, that is, determining an object accessed by the application within a first time period after the application switches from the foreground to the background.

[0011] In a possible implementation of the first aspect, determining the first object includes: marking the read and write permissions of multiple pages as unreadable and unwritable; detecting whether there is an access violation event within a first time period; and determining the object corresponding to the physical address carried in the access violation event as the first object when the access violation event is detected. The access violation event is an event generated by accessing an object in a page when the read and write permissions of the page are unreadable and unwritable; and the generated event carries the physical address of the accessed object, so that when the access violation event is detected, the object corresponding to the physical address carried in the access violation event can be determined as the first object.

[0012] In a possible implementation of the first aspect, detecting whether there is an access violation event within a first time period includes: periodically detecting whether there is an access violation event within the first time period; the method also includes: in each detection, when an access violation event is detected, marking the read and write permissions of the page where the object corresponding to the physical address carried in the access event is located as readable and writable, and before starting the next detection, re-marking the read and write permissions of the page where the object corresponding to the physical address carried in the access event is located as unreadable and writable.

[0013] In the above scheme, the read and write permissions of the page where the object corresponding to the physical address carried in the access event is located are marked as read and write, so that the application can continue to operate normally. By periodically detecting whether there are access violation events, objects accessed by the application in the first time period can be collected as much as possible, thereby improving the acquisition rate of objects accessed by the application.

[0014] In a possible implementation of the first aspect, the method further includes: after the first time period, marking the read and write permissions of the plurality of pages as read and write enabled, so that the application can continue to operate normally.

[0015] In a possible implementation of the first aspect, the method also includes: storing the physical address of the first object in a preset queue; copying the first objects stored in multiple first pages to the target page of the memory, including: copying the first objects stored in multiple first pages to the target page of the memory according to the physical addresses of the first objects in the multiple first pages stored in the preset queue.

[0016] In the above scheme, the physical address of the first object is stored in a preset queue, so that the electronic device can obtain the first object according to the physical address of the first object in multiple first pages stored in the preset queue, and copy the first object stored in multiple first pages to the target page of the memory.

[0017] In a possible implementation of the first aspect, the first time period is a time period within a preset duration after the application switches from the foreground to the background, and the preset duration is pre-set; or; the first time period is a time period from the application switches from the foreground to the background to a target moment, and the target moment is determined based on a growth rate of the first object determined in two adjacent detections; or; the first time period is determined based on the target moment and the preset duration.

[0018] In a possible implementation of the first aspect, the target moment is determined based on the growth rate of the first object determined in two adjacent detections, including: the electronic device may compare the growth rate of the object accessed by the application obtained each time with the preset threshold 1. In the case where the growth rate of the object accessed by the application identified by the electronic device is less than or equal to the preset threshold 1, it can be considered that most of the objects accessed by the application in the background have been collected. The electronic device can terminate the confirmation of the accessed object to reduce the power consumption of the electronic device. That is, the target moment is the moment when the growth rate of the accessed object identified by the electronic device is less than or equal to the preset threshold 1. Correspondingly, the first time period is the time period between the moment when the application switches from the foreground to the background to the moment when the growth rate of the accessed object identified by the electronic device is less than or equal to the preset threshold 1.

[0019] In a possible implementation manner of the first aspect, the first time period is determined based on the target time and a preset duration, including:

[0020] If the target time is within the time period after the preset time from the moment the application switches from the foreground to the background, the first time period is the time period from the moment the application switches from the foreground to the background to the target time; if the target time exceeds the time period after the preset time from the moment the application switches from the foreground to the background, the first time period is the time period within the preset time from the moment the application switches from the foreground to the background.

[0021] In a possible implementation of the first aspect, before copying the first objects stored in the plurality of first pages to the target page of the memory, the method further includes: allocating the target page to the application based on the sizes of all the first objects stored in the plurality of first pages. The target page may include one or more pages, and the size of the target page satisfies this condition: the target page may include one or more pages, and the size of the target page satisfies this condition: the difference between the size of the target page and the size of all the first objects is less than the size of one page.

[0022] In a possible implementation manner of the first aspect, a calculation formula for a growth rate of accessed objects identified by an application is:

[0023] (The number of accessed objects identified by the application for the i+1th time - the number of accessed objects identified by the application for the ith time) / the time interval between the moment when the application starts to detect whether there are accessed objects for the i+1th time and the moment when the application starts to detect whether there are accessed objects for the ith time, where the i+1th detection and the ith detection are two adjacent detections.

[0024] In a possible implementation of the first aspect, all objects stored in the multiple first pages are copied to a storage area other than the memory, including: obtaining a target physical address of the target page; obtaining the first object based on the physical address of the first object in a preset queue; and storing the first object to the target page based on the target physical address.

[0025] In a possible implementation manner of the first aspect, the storage area other than the memory includes any one of a hard disk of the electronic device, a storage device connected to an interface of the electronic device, and a remote storage device.

[0026] In a possible implementation manner of the first aspect, the period may be once every 4 seconds, once every 5 seconds, or once every 6 seconds.

[0027] In a possible implementation manner of the first aspect, the preset time period may be any one of 4 minutes, 5 minutes, or 4 minutes to 5 minutes.

[0028] In a second aspect, the present application provides an electronic device, which includes at least: a memory and one or more processors. The memory is used to store computer instructions, and when the one or more processors execute the computer instructions, the electronic device executes any method as described in the first aspect above.

[0029] In a third aspect, the present application provides a computer-readable storage medium, which includes computer instructions. When the computer instructions are executed on an electronic device, the electronic device executes any method as described in the first aspect above.

[0030] In a fourth aspect, the present application provides a computer program product. When the computer program product is run on an electronic device, the electronic device executes any one of the methods in the first aspect above.

[0031] Among them, the technical effects brought about by any design method in the second to fourth aspects can refer to the technical effects brought about by different design methods in the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] Figure 1 A schematic diagram showing memory space allocated by an electronic device to an application;

[0033] Figure 2 A schematic diagram showing an electronic device executing the memory management method of the present application on the memory space allocated for application 1;

[0034] Figure 3 A schematic diagram showing an interface change of an electronic device switching an application from the foreground to the background in response to a user's operation of switching the application from the foreground to the background;

[0035] Figure 4 shows a schematic structural diagram of a mobile phone 100;

[0036] Figure 5 A schematic diagram of a memory management method is shown;

[0037] Figure 6 A schematic diagram showing three types of pages;

[0038] Figure 7 A schematic diagram showing page changes before and after execution of a memory management method is shown;

[0039] Figure 8 A schematic diagram showing page changes before and after execution of another memory management method is shown;

[0040] Fig. 9 A schematic diagram of a virtualization architecture of a mobile phone 100 is shown;

[0041] Fig.10 A schematic flow chart of a method for confirming a first object is shown. DETAILED DESCRIPTION

[0042] The technical solutions in the embodiments of the present application are described below in conjunction with the drawings in the embodiments of the present application. Among them, in the description of the embodiments of the present application, the terms used in the following embodiments are only for the purpose of describing specific embodiments, and are not intended to be used as limitations on the present application. As used in the specification and the appended claims of the present application, the singular expressions "a", "said", "above", "the" and "this" are intended to also include expressions such as "one or more", unless there is a clear contrary indication in the context. It should also be understood that in the following embodiments of the present application, "at least one", "one or more" refer to one or more (including two). The term "and / or" is used to describe the association relationship of associated objects, indicating that three relationships can exist; for example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the associated objects before and after are in an "or" relationship.

[0043] References to "one embodiment" or "some embodiments" etc. described in this specification mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Thus, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways. The term "connection" includes direct connection and indirect connection, unless otherwise specified. "First" and "second" are used for descriptive purposes only and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated.

[0044] In the embodiments of the present application, the words "exemplarily" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "exemplarily" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplarily" or "for example" is intended to present related concepts in a specific way.

[0045] In order to make the description of the following embodiments clear and concise, the relevant technical terms or technologies involved in this application are first briefly introduced:

[0046] (1) Page, or page. In the operating system of an electronic device, the memory is divided into storage areas of equal size (or small blocks). The physical address of each storage area is continuous. Each storage area is called a page. That is, each page is a continuous storage area of ​​fixed size in the memory. The size of a page is generally fixed, such as 4KB or larger (such as 8KB, 16KB, 32KB, etc.). "K" stands for kilo and "B" stands for byte. The Chinese meaning of 4KB is "4 kilobytes", 4KB=4×1024 bytes=4096 bytes. The size of the page depends on the operating system and hardware architecture of the electronic device.

[0047] Pages are the basic units for memory management by the operating system, that is, electronic devices usually manage memory in units of pages. For example, taking the allocation of memory space to an application as an example, the application can send a memory allocation request to the operating system to request the operating system to allocate memory space for the application. After the operating system receives the memory allocation request sent by the application, it checks whether the remaining available capacity in the memory satisfies the size of the memory space requested by the application. If the remaining available capacity in the memory satisfies the size of the memory space requested by the application, the operating system allocates one or more pages to the application. After the application obtains the allocated pages, it can store data in those pages of the memory. For example, Figure 1 FIG. 1 shows a schematic diagram of memory space allocated by an electronic device to an application. Figure 1 As shown, the electronic device allocates n pages to application 1, m pages to application 2, l pages to application 3, and o pages to application 4. Where n, m, l, and o are integers greater than or equal to 1.

[0048] (2) Objects: The objects in the embodiments of the present application are data used to support the application to implement functions. One object is used to support the application to implement a function, or multiple objects are used to support the application to implement a function. The application can implement the application function by accessing the object. For example, a chat application may include a "message" object, which contains the data required for the chat application to send and receive messages. The electronic device can implement the chat application's function of sending and receiving messages based on the "message" object.

[0049] Application objects are generally stored in pages allocated by the operating system for the application in memory. For example, continuing with the above example, Figure 1 As shown, the page 3 allocated by the operating system to the application 1 stores 4 objects of the application 1. These 4 objects can be used to support the application 1 to implement one function. Or these 4 objects are used to support the application 1 to implement multiple functions, for example, one object is used to support the application 1 to implement function 1, and the remaining 3 objects are used to support the application 1 to implement function 2.

[0050] It is understandable that the application can implement the application's functions (such as the functions of sending and receiving messages in a chat application) by accessing the objects stored in the page. The application's access to the objects stored in the page includes the application's read operation and / or write operation on the data of the object.

[0051] (3) Release a page. After the page is released, no data is stored in the page, and the page is in a reallocation state. In some embodiments, when an application no longer uses a page allocated by the electronic device to the application, the application can send a page release request for the page to the operating system. After receiving the page release request sent by the application, the operating system deletes all data stored in the page and marks the page as available. In this way, the page is in a reallocation state and can be used by other applications or processes.

[0052] As mentioned above, electronic devices manage memory in units of pages. Therefore, when releasing a page, the electronic device, such as the operating system, will not release part of the storage area in the page separately, but will release the entire page. Specifically, the electronic device can delete all data stored in the page and mark the page as available. For example, if a page stores multiple objects, the operating system will not release the storage area occupied by one or several of the multiple objects separately, but will delete all objects stored in the page and mark the page as available.

[0053] The memory management method provided in the embodiment of the present application is described in detail below in combination with specific scenarios and drawings.

[0054] As described in the background technology above, when there are many background applications in an electronic device, since the background applications occupy more memory, the foreground applications may not be able to run normally due to insufficient memory, resulting in freezes and poor user experience.

[0055] Specifically, one situation where background applications occupy more memory is: in the related art, when an electronic device releases memory, it will not release a certain object in the page separately, but release the entire page. As long as one of the objects stored in the page is accessed, the page will not be released. In this way, in an application, such as an application running in the background, the objects accessed within a period of time are stored in multiple different pages respectively, and these multiple pages will not be released. This may not only affect the operation of the foreground application because the background application occupies more memory, but also cause a waste of memory resources. For example, the size of a page is 4096 bytes. If the size of the object accessed by the application in the page is 50 bytes, and the size of the object not accessed by the application is 4046 bytes, this will cause the 4046-byte storage area occupied by the object not accessed by the application to be unable to be released, resulting in a waste of memory resources. If the size of the two objects accessed by the application is 50 bytes each and they are stored in two pages respectively, the size of the object not accessed by the application in the two pages is 2*4046 bytes. This will result in the 2*4046-byte storage area occupied by the objects not accessed by the application unable to be released, which may affect the operation of the foreground application and cause a waste of memory resources.

[0056] In order to solve this technical problem, an embodiment of the present application shows a memory management method. The method includes: within a period of time after the application switches to background operation, the electronic device can determine the objects accessed by the application. If the objects accessed by the application in the aforementioned time period (hereinafter referred to as accessed objects) are stored in different pages respectively, and other objects are also stored in these pages, and these other objects have not been accessed by the application in the aforementioned time period (hereinafter referred to as unaccessed objects), the electronic device can first store the accessed objects stored in these pages in a target page, and then copy all the data stored in these pages to a storage area other than the memory, and then release these pages.

[0057] Before executing the memory management method provided in the embodiment of the present application, there are some pages that store both accessed objects and unaccessed objects, so the memory space occupied by the unaccessed objects in these pages cannot be recovered (or released). Executing the memory management method provided in the embodiment of the present application, by integrating the above-mentioned accessed objects into one or more target pages, and releasing the pages that originally stored the accessed objects, the memory space occupied by the unaccessed objects in these pages can be recovered, and the remaining available capacity of the memory becomes larger. In this way, the electronic device can obtain more available memory, which can, to a certain extent, enable the application running in the foreground to have more sufficient memory usage, allowing it to run more smoothly and improve the user experience.

[0058] For example, Figure 1 The memory management method provided in the embodiment of the present application is explained by taking Application 1 in the example. Figure 2 FIG. 1 is a schematic diagram showing an electronic device executing the memory management method of the present application on the memory space allocated for application 1. Figure 2 As shown, n is 3, that is, the electronic device allocates 3 pages for application 1 to store objects of application 1.

[0059] like Figure 2As shown in (a), within a period of time after application 1 switches to background operation, the electronic device can determine that the objects accessed by the application are: object 0, object 1, object 2, and object 3, and objects 0, object 1, object 2, and object 3 are stored in different pages, respectively, and unaccessed objects are also stored in these pages. For example, object 1 is stored in page 1, objects 2 and 3 are stored in page 2, and object 0 is stored in page 3. Four objects are stored in page 1. During the aforementioned period, object 1 is accessed by the application, and the other three objects are not accessed by the application. Four objects are stored in page 2. During the aforementioned period, objects 2 and object 3 are accessed by the application, and the other two objects are not accessed by the application. Four objects are stored in page 3. During the aforementioned period, object 0 is accessed by the application, and the other three objects are not accessed by the application.

[0060] Then, if Figure 2 As shown in (b) in FIG. 1 , the electronic device can store object 0, object 1, object 2, and object 3 in a target page, and copy all data stored in page 1, page 2, and page 3 to a storage area other than the memory. Then, page 1, page 2, and page 3 are released. As an example, the target page and page 1, page 2, and page 3 are different storage areas.

[0061] Before executing the memory management method of the embodiment of the present application, pages 1, 2, and 3 store both accessed objects and unaccessed objects, so the memory space occupied by the unaccessed objects in pages 1, 2, and 3 cannot be reclaimed. Executing the memory management method of the embodiment of the present application, by integrating object 0, object 1, object 2, and object 3 into a target page, and releasing pages 1, 2, and 3 that originally stored the accessed objects, the memory space occupied by the unaccessed objects in pages 1, 2, and 3 can be reclaimed, and the remaining available capacity of the memory becomes larger. In this way, the electronic device can obtain more available memory, ensuring that the application running in the foreground has more sufficient memory usage, allowing it to run more smoothly and improve the user experience.

[0062] The electronic device may switch the application to the background in response to the user's operation of switching the application from the foreground to the background. The user's operation of switching the application from the foreground to the background may be a touch operation, a voice operation, or an air gesture operation, but is not limited thereto. The following takes the operation that triggers the application to switch from the foreground to the background as an example to introduce the interface change process of the electronic device switching the application from the foreground to the background in response to the user's operation of switching the application from the foreground to the background.

[0063] For example, Figure 3The figure shows a schematic diagram of the interface change of an electronic device when an application is switched from the foreground to the background in response to a user's operation of switching the application from the foreground to the background. Take the electronic device as a mobile phone as an example. Figure 3 As shown in (a) of FIG. 1 , the mobile phone 100 displays an interface 101, which includes icons of multiple applications, such as an icon 102 of a chat application and an icon of a reading application. In response to the user clicking the icon 102 of the chat application, the mobile phone 100 starts the chat application and performs the following operations: Figure 3 As shown in (b) of FIG. 1 , the mobile phone 100 can display the interface 103 of the chat application. In this way, the user can use various functions provided by the chat application. Later, when the user wants to switch the chat application to the background, the user can slide upward from the bottom on the display screen of the mobile phone 100. In response to the sliding operation, the mobile phone 100 switches the chat application to the background. In addition, the mobile phone 100 can also display the following Figure 3 The solution provided in the embodiment of the present application can be executed after the mobile phone 100 receives the above-mentioned operation of triggering the application to switch from the foreground to the background, or it can be executed after the mobile phone 100 detects that the application switches from the foreground to the background, and the embodiment of the present application does not make any specific restrictions here.

[0064] In the embodiment of the present application, the electronic device is an electronic device that supports the application to run in the foreground and the background. Specifically, the electronic device can be a portable electronic device or other suitable electronic device. For example, the electronic device can be a mobile phone, a tablet personal computer, a laptop computer, a personal digital assistant (PDA), a personal computer, a notebook computer, a vehicle-mounted device, etc.

[0065] The following uses a mobile phone as an example of an electronic device to illustrate the memory management method provided in an embodiment of the present application.

[0066] Figure 4 FIG. 1 shows a schematic diagram of the structure of the mobile phone 100. Figure 4As shown, the mobile phone 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor, a gyroscope sensor, a fingerprint sensor, a temperature sensor, etc.

[0067] It is to be understood that the structure illustrated in the embodiment of the present invention 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.

[0068] The internal memory 121 can be used to store computer executable program codes, which include instructions. The processor 110 executes various functions of the mobile phone 100 by running the instructions stored in the internal memory 121. In the embodiment of the present application, the internal memory 121 can also be called an internal memory, that is, a memory, and a page can be a storage area divided in the internal memory 121. The mobile phone 100 can implement the functions of the application (such as the function of sending and receiving messages in a chat application) by accessing the objects stored in the page.

[0069] The internal memory 121 has the advantage of fast access speed. The internal memory 121 usually adopts dynamic random access memory (DRAM). In addition to DRAM, the internal memory 121 can also be other random access memories, such as static random access memory (SRAM).

[0070] 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 external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function, such as storing music, video and other files in the external memory card.

[0071] 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 processing unit (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), etc. Among them, different processing units may be independent devices or integrated into one or more processors. Among them, the controller may be the nerve center and command center of the mobile phone 100. The controller may generate an operation control signal according to the instruction opcode and the timing signal to complete the control of fetching and executing instructions.

[0072] In an embodiment of the present application, within a period of time after the application switches to background operation, the processor 110 can determine the objects accessed by the application. If the objects accessed by the application during the aforementioned time period (hereinafter referred to as accessed objects) are stored in different pages respectively, and other objects are also stored in these pages, and these other objects are not accessed by the application during the aforementioned time period (hereinafter referred to as unaccessed objects), the processor 110 can first store the accessed objects stored in these pages in a target page, and then copy all the data stored in these pages to a storage area other than the memory, and then release these pages. In some embodiments, the storage area other than the memory can be an external memory connected to the external memory interface 120, or it can be a disk integrated inside the mobile phone 100.

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

[0074] The charging management module 140 is used to receive charging input from the charger. The power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140 to power the processor 110, the internal memory 121, the external memory, the display screen 194, the camera 193, and the wireless communication module 160.

[0075] The wireless communication function of the mobile phone 100 can be implemented through 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. Each antenna in the mobile phone 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve the utilization of the antenna. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In some other embodiments, the antenna can be used in combination with a tuning switch. 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.

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

[0077] The display screen 194 is used to display images, videos, etc. In some embodiments, the mobile phone 100 may include 1 or N display screens 194, where N is a positive integer greater than 1. In the embodiment of the present application, the application running in the foreground means that the interface of the application is displayed on the display screen 194 of the mobile phone 100, and the user can directly interact with the interface displayed on the display screen 194. The application running in the background means that the interface of the application is not displayed on the display screen 194, and the mobile phone 100 can execute some functions of the application without displaying the interface of the application.

[0078] The mobile phone 100 can realize the shooting function through the ISP, the camera 193, the video codec and the display screen 194.

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

[0080] The key 190 includes a power key, a volume key, etc. The key 190 may be a mechanical key. It may also be a touch key. The mobile phone 100 may receive key input and generate key signal input related to user settings and function control of the mobile phone 100. The motor 191 may generate a vibration prompt. The indicator 192 may be an indicator light, which may be used to indicate the charging status, power change, message, missed call, notification, etc.

[0081] Figure 5 A schematic diagram of a memory management method is shown, and the execution subject of the process may be an electronic device, such as the mobile phone 100 mentioned above, such as Figure 5 As shown, the process includes the following steps:

[0082] 501. In response to an application switching from a foreground to a background, determining a first object; wherein the first object is an object accessed by the application within a first time period.

[0083] After the application is started, one or more objects are created to support the application to implement corresponding functions. The objects created by the application can be stored in at least one page allocated in the memory of the mobile phone 100 for the application.

[0084] It is understandable that when the application is switched from the foreground to the background, the application can still implement some functions of the application by continuing to access the objects stored in the page.

[0085] In the embodiment of the present application, in response to the application switching from the foreground to the background, the description can be replaced by responding to the mobile phone 100 receiving an operation that triggers the application to switch from the foreground to the background, or it can be replaced by responding to the mobile phone 100 detecting that the application switches from the foreground to the background.

[0086] One property of an application when it is running in the background is that after the application is running in the background, as time goes by, the number of objects accessed by the application grows slowly or even stops growing, that is, no new objects are accessed after a period of time when the application switches to the background. This time period can be called the first time period. Based on this property, the mobile phone 100 can count the objects accessed by the application in the first time period in response to the application switching from the foreground to the background, and determine the objects accessed by the application in the first time period as the first objects. Among them, the specific implementation of identifying the objects accessed by the application is shown in the subsequent Fig.10 The embodiments shown will not be described in detail here for the time being.

[0087] In some embodiments, the first time period may be a time period after a preset time period starting from the moment when the application is switched from the foreground to the background.

[0088] The above-mentioned preset time length can be pre-set, such as the preset time length can be 4 minutes, 5 minutes, or any time length between 4 minutes and 5 minutes, and of course it can also be other time lengths.

[0089] In some other embodiments, the first time period may be a time period from the moment when the application switches from the foreground to the background to the target time, wherein the target time may be determined based on the growth rate of the accessed objects identified by the mobile phone 100 .

[0090] Exemplarily, the mobile phone 100 may periodically obtain objects accessed by the application and count the number of objects accessed by the application starting from the moment the application switches from the foreground to the background, and then the mobile phone 100 may compare the growth rate of the objects accessed by the application obtained each time with the preset threshold 1. In the case where the growth rate of the objects accessed by the application identified by the mobile phone 100 is less than or equal to the preset threshold 1, it can be considered that most of the objects accessed by the application in the background have been collected. The mobile phone 100 may terminate the confirmation of the accessed objects to reduce the power consumption of the mobile phone 100. That is, the target moment is the moment when the growth rate of the accessed objects identified by the mobile phone 100 is less than or equal to the preset threshold 1. Accordingly, the first time period is the time period between the moment when the application switches from the foreground to the background to the moment when the growth rate of the accessed objects identified by the mobile phone 100 is less than or equal to the preset threshold 1.

[0091] The calculation formula for the growth rate of the accessed objects identified by the mobile phone 100 is:

[0092] (The number of accessed objects obtained by the application at the i+1th time - the number of accessed objects obtained by the application at the i-th time) / the duration from the moment the application starts detecting whether there are accessed objects at the i+1th time to the moment the application starts detecting whether there are accessed objects at the i-th time, where the i+1th detection and the i-th detection are two adjacent detections.

[0093] In some other embodiments, the first time period may be determined by comparing the time period after the preset time period from the moment when the application is switched from the foreground to the background and the target time by the mobile phone 100. If the target time is within the time period after the preset time period from the moment when the application is switched from the foreground to the background, the first time period is the time period from the moment when the application is switched from the foreground to the background to the target time; if the target time exceeds the time period after the preset time period from the moment when the application is switched from the foreground to the background, the first time period is the time period within the preset time period from the moment when the application is switched from the foreground to the background.

[0094] In order to simplify the description, the objects accessed by the application in the first time period are referred to as accessed objects, and the objects not accessed by the application in the first time period are referred to as non-accessed objects. According to the storage conditions of accessed objects and non-accessed objects in the pages, the pages allocated to the application can be divided into three types of pages:

[0095] The first type of page is a page that stores accessed objects and unaccessed objects. The first type of page can be called a first page. Figure 6 A schematic diagram of three types of pages is shown. Figure 6As shown, page 1 is a first type of page, and page 1 is a page storing two accessed objects and two unaccessed objects.

[0096] The second type of page is a page in which all stored objects are accessed objects. The second type of page can be called a second page. Figure 6 As shown, page 2 is the second type of page, and the four objects stored in page 2 are all accessed objects.

[0097] The third type of page is a page in which all stored objects are unaccessed objects. The third type of page can be called a third page. Figure 6 As shown, page 3 is the third type of page, and the four objects stored in page 3 are all unaccessed objects.

[0098] Another property of an application when running in the background is that when the application is running in the background, the objects accessed by the application are generally stored in a plurality of different pages in a scattered manner, that is, when the application is running in the background, there will be a plurality of first pages (e.g., page 1) in the pages allocated to the application. As described above, a page of the type similar to the first page cannot be released due to the presence of an accessed object in the first page, thereby causing the memory space occupied by the unaccessed object stored in the first page to be unable to be released. Based on this property, the mobile phone 100 can execute the following steps 502-504 to release the memory space occupied by the unaccessed object in the first page.

[0099] 502. Determine a first page to be processed from a plurality of pages allocated to an application based on the first object.

[0100] The mobile phone 100 can determine the type of the page according to the distribution of the accessed objects and the unaccessed objects in the page. Specifically, in some embodiments, if the page allocated to the application stores the accessed objects and the unaccessed objects, the page is determined to be the first page. All the first pages determined in this way are the first pages to be processed in the subsequent step 503.

[0101] It can be understood that in some embodiments, if there are too many accessed objects in all the first pages determined based on the above method, in order to maintain the integrity of page management, no processing may be performed on the first page, and other first pages are the first pages to be processed in the subsequent step 503.

[0102] Specifically, if the ratio of the size of all accessed objects stored in the first page to the size of the page is greater than the preset threshold value 2, no processing is performed on this first page. Other first pages, that is, first pages in which the ratio of the size of all accessed objects stored in the first page to the size of the page is less than or equal to the preset threshold value 2, are the first pages to be processed in the subsequent step 503.

[0103] 503. When the number of the first pages to be processed is greater than or equal to 2, copy the objects accessed by the application in the first pages to be processed to the target page in the memory, copy all the data in the first pages to be processed to a storage area other than the memory, and release the first pages to be processed.

[0104] If the number of first pages to be processed is greater than or equal to 2, this means that the objects being accessed are sparsely distributed in the pages, the memory space occupied by the unaccessed objects is large, and the memory resources are wasted. In order to save memory, the mobile phone 100 can first store the accessed objects distributed in different pages in the target page, copy all the data stored in these pages to the storage area other than the memory, and release these pages.

[0105] As described above, the mobile phone 100 can access the objects in the page to realize the running of the application's functions in the background. Since the objects accessed by the application in the first time period are determined in advance, and these objects are more likely to be accessed later, and those objects that are not accessed by the application in the first time period are less likely to be accessed later, the first objects should continue to be stored in the memory so that the mobile phone 100 can efficiently access these objects, and the unaccessed objects can be copied to other storage areas, thereby releasing the memory space occupied by them.

[0106] In addition, as described above, the mobile phone 100 manages memory in units of pages. Therefore, the mobile phone 100 can first copy the accessed objects stored in the first page, that is, the first objects, to the target page, and copy all the data in the first page to a storage area other than the memory. Then, the mobile phone 100 releases the first page.

[0107] For example, Figure 7 FIG. 1 is a schematic diagram showing page changes before and after a memory management method is executed. Figure 7As shown in (a) in FIG, the pages allocated to application 1 include page 1, page 2, and page 3. By executing the above steps, it can be determined that page 2 and page 3 are first pages. For example, page 2 stores accessed object 4, and page 3 stores accessed object 5 and accessed object 6. It can be understood that the pages allocated to application 1 include two first pages, which means that the first objects are sparsely distributed in the pages allocated to application 1, and the memory space occupied by the unaccessed objects is large. Figure 7 As shown in (b), the mobile phone 100 can store objects 4, 5 and 6 stored in pages 2 and 3 in a target page of the memory, copy all data in pages 2 and 3 to a storage area other than the memory, and then release pages 2 and 3.

[0108] Before executing the memory management method provided in the embodiment of the present application, both accessed objects and unaccessed objects are stored in page 2 and page 3, so the memory space occupied by the unaccessed objects in page 2 and page 3 cannot be reclaimed. Executing the memory management method in the embodiment of the present application, by integrating object 0, object 1, object 2, object 3, object 4, object 5 and object 6 into a target page, and releasing page 2 and page 3 that originally stored the accessed objects, the two pages occupied by the unaccessed objects in page 2 and page 3 can be reclaimed, and the remaining available capacity of the memory becomes larger. In this way, the electronic device can obtain more available memory, ensuring that the application running in the foreground has more sufficient memory usage, allowing it to run more smoothly and improve the user experience.

[0109] The target page is a page allocated to the application by the operating system of the mobile phone 100 based on the size of the accessed objects in all the first pages to be processed. The target page may include one or more pages, and the size of the target page satisfies this condition: the difference between the size of the target page and the size of all the first objects is less than the size of one page.

[0110] Specifically, the application may send a memory allocation request to the operating system to request the operating system to allocate memory space for the application, and the memory allocation request carries information about the size of the accessed object in the first page to be processed. After receiving the memory allocation request sent by the application, the operating system allocates pages to the application based on the size of the accessed objects in all the first pages to be processed.

[0111] Specifically, in some embodiments, the operating system of the mobile phone 100 may divide the size of all accessed objects in the first page to be processed by the size of one page, and allocate pages to the application based on the division result.

[0112] If the division result is less than 1 or equal to 1, the number of target pages is 1, and the operating system of the mobile phone 100 allocates 1 page to the application, and the 1 page is the target page. Figure 2 As shown, the sizes of Object 0, Object 1, Object 2 and Object 3 are 4096 bytes, the size of a page is 4096 bytes, and the first two values ​​divided by 1 are 1, so the operating system of the mobile phone 100 allocates 1 page for the application, and this 1 page is the target page.

[0113] If the division result is greater than 1 and is an integer, the value of the division result is the number of target pages, and the operating system of the mobile phone 100 allocates a corresponding number of pages to the application, and these pages are the target pages.

[0114] If the division result is greater than 1 and is a decimal, the value obtained by adding 1 to the integer part of the division result is the number of target pages, and the operating system of the mobile phone 100 allocates a corresponding number of pages to the application, and these pages are the target pages.

[0115] When the number of first pages to be processed is 1, if all data in the first page to be processed is copied to a storage area other than the memory to release the first page, this processing of the first page to be processed will not save memory. Therefore, when the number of first pages to be processed is 1, no processing is performed on the first page to be processed.

[0116] For example, Figure 8 FIG. 1 is a schematic diagram showing page changes before and after a memory management method is executed. Figure 8 As shown in (a) in FIG. 1 , the pages allocated to the application are page 1, page 2, and page 3, page 1 is the second page, page 2 is the third page, and page 3 is the first page. The pages allocated to the application include only one first page. Figure 8 As shown in (b) in FIG. 1 , the mobile phone 100 does not perform any processing on the page 3. It can be understood that if the page is the second page, then the second page is not processed either. For example, Figure 8 As shown in (b) in FIG. 1 , no processing is performed on page 1. If the page is the third page, all data stored in the third page are copied to a storage area other than the memory, and then the third page is released, for example, Figure 8 As shown in (b), all data stored in page 2 is copied to a storage area other than the memory, and page 2 is released.

[0117] Copying the objects accessed by the application in the first page to be processed to the target page in the memory can be achieved by the following steps:

[0118] Step 1: Get the target physical address of the target page.

[0119] In some embodiments, the application may first send a memory allocation request to the operating system, and the memory allocation request is used to request to allocate a page for the first object. After the operating system receives the memory allocation request sent by the application, it will check whether the remaining available capacity in the memory meets the size of the memory requested to be allocated by the application. If the remaining available capacity in the memory meets the size of the memory requested to be allocated by the application, the operating system will allocate one or more pages to the application, such as sending the physical address of the allocated page to the application, and the one or more pages are the target pages. After the mobile phone 100 obtains the physical address of the page allocated to the application, it can store data in the page corresponding to the physical address.

[0120] Step 2: Based on the physical address of the object accessed by the application in the first page to be processed in the preset queue, obtain the object accessed by the application in the first page to be processed.

[0121] For an introduction to preset queues, see the following Fig.10 The embodiments shown will not be described in detail here for the time being.

[0122] Step 3: Store the object accessed by the application in the first page to be processed into the target page based on the target physical address.

[0123] In addition, the storage area other than the memory in the embodiment of the present application may be a swap area allocated to the virtual machine. The relationship between the virtual machine and the storage area other than the memory is described below.

[0124] Fig. 9 FIG. 1 shows a schematic diagram of a virtualization architecture of a mobile phone 100. Fig. 9 As shown, the mobile phone 100 includes a processor, a memory and a virtual machine.

[0125] With the help of virtualization technology, the mobile phone 100 can form a software module with an independent operating environment on the mobile phone 100. In the embodiment of the present application, the software module with an independent operating environment formed on the mobile phone 100 is referred to as a virtual machine. A virtual machine is a "complete computer" with complete hardware system functions that runs in a completely isolated environment, which is simulated by virtualization technology. All work that can be done in the entity of the mobile phone 100 can be achieved in the virtual machine. The virtual machine has components such as a processor (the processor is also called a virtual processor) and memory. The processor, memory and other components of the virtual machine are all virtualized by the processor, memory and other components of the mobile phone 100. An operating system is installed on the virtual machine, and the operating system on the virtual machine is independent of the operating system of the mobile phone 100 itself.

[0126] The processor includes a memory management unit (MMU), which is also called a paged memory management unit (PMMU). In an embodiment of the present application, the MMU can manage the memory space with pages as the granularity (i.e., paged memory management), and the MMU can use the garbage collection mechanism (GC) in the virtual machine to copy the accessed object stored in the first page to the target page, copy the data stored in the first page to a storage area other than the memory, and release the first page.

[0127] The garbage collection mechanism involves physical memory and virtual memory. Physical memory is the memory of the mobile phone 100. Virtual memory is the storage area other than the memory.

[0128] The virtual memory may be referred to as a swap area, which is usually located in a local storage device of the mobile phone 100. The local storage device of the mobile phone 100 may include a storage area integrated inside the mobile phone 100, or may include an interface with the mobile phone 100 (such as Figure 4 The storage area integrated inside the mobile phone 100 may be a hard disk of the mobile phone 100, etc. The hard disk of the mobile phone 100 refers to a hardware device for storing data, which usually exists in the form of a storage chip such as an embedded Multi Media Card (eMMC), a universal flash storage (UFS) or a non-volatile memory Express (NVMe).

[0129] In an embodiment of the present application, the virtual memory may also be located in a remote storage device, where the remote storage device refers to a storage device connected to the mobile phone 100 via a network, and the remote storage device may be a device corresponding to a private cloud or a public cloud.

[0130] A method for determining a first object based on an access violation event is exemplarily described below.

[0131] Fig.10 A schematic diagram of a process flow of a method for confirming a first object is shown. The execution subject of the process may be an electronic device, such as a mobile phone 100. Fig.10 As shown, the process includes the following steps:

[0132] 1001. In response to an application being switched from the foreground to the background, the read and write permissions of all pages allocated to the application are marked as unreadable and unwritable.

[0133] In the case where the read and write permissions of a page in the memory are not read and write, if an application accesses an object stored in the page, the object cannot be accessed because the read and write permissions of the page are not read and write, and an access violation event will be generated. The generated access violation event will carry the physical address of the accessed object, so that the mobile phone 100 can determine the object stored in the corresponding storage area corresponding to the physical address carried in the access violation event as the first object when an access violation event is detected.

[0134] Based on this, in an embodiment of the present application, when the application switches from the foreground to the background, the mobile phone 100 can set the read and write permissions of all pages allocated to the application to be non-readable and non-writable. In this way, if the application accesses the objects stored in these pages, an access violation event will be generated. Based on the access violation events generated within a period of time after the application switches from the foreground to the background, the mobile phone 100 can determine the above-mentioned first object. For specific implementation, please refer to the following steps 1002-1004.

[0135] 1002. Detect whether there is an access violation event. If there is an access violation event, determine the object corresponding to the physical address carried in the access violation event as the first object, and store the physical address of the first object in a preset queue.

[0136] In some embodiments, the preset queue may be a hot object queue (Hot Object Queue). A hot object queue generally refers to a queue for storing and managing objects that are frequently accessed or require priority processing (such as hot objects).

[0137] 1003. Mark the read / write permission of the page where the object corresponding to the physical address carried in the access violation event is located as read / write.

[0138] After mobile phone 100 stores the physical address carried in the access violation event in a preset queue, mobile phone 100 can mark the read and write permissions of the page where the object corresponding to the physical address carried in the access violation event is located as read and write, ensuring that the application can continue to execute.

[0139] 1004. Determine whether the time period from the moment when the application is switched to the background to the current moment exceeds the first time period.

[0140] As described in the previous embodiment, after the application switches from the foreground to the background, no new accessed objects will appear after a period of time, such as the first time period. Therefore, in some embodiments, the mobile phone 100 can determine whether the time period from the moment the application switches to the background to the current moment exceeds the first time period. If the time period from the moment the application switches to the background to the current moment exceeds the first time period, this indicates that basically no new accessed objects will appear, and the mobile phone 100 can stop determining the first object. Afterwards, the mobile phone 100 can mark the read and write permissions of all pages allocated to the application as read and write, so that the application can continue to execute, that is, the mobile phone 100 can execute 1005.

[0141] In some embodiments, when the first time period is a time period after a preset time period starting from the moment when the application switches from the foreground to the background, and the preset time period is pre-set, the mobile phone 100 can start counting the preset time period from the moment when the application switches to the background, and execute 1005 when the preset time period is reached.

[0142] In some embodiments, the first time period is a time period from the moment when the application switches from the foreground to the background to the target time, and the target time is determined based on the growth rate of the accessed objects identified by the mobile phone 100. The mobile phone 100 can periodically determine the number of accessed objects obtained from the moment when the application switches to the background, and execute 1005 when the growth rate of the accessed objects is less than or equal to the preset threshold 1. The formula for determining the growth rate of the accessed objects has been introduced above and will not be repeated here.

[0143] In some embodiments, the first time period can be determined by comparing the time period after the preset time period from the moment when the application switches from the foreground to the background and the target time by the mobile phone 100. Specifically, if the target time is within the time period after the preset time period from the moment when the application switches from the foreground to the background, the mobile phone 100 can periodically determine the number of accessed objects obtained from the moment when the application switches to the background, and execute 1005 when the growth rate of the accessed objects is less than or equal to the preset threshold value 1. If the target time exceeds the time period after the preset time period from the moment when the application switches from the foreground to the background, the first time period is the time period within the preset time period after the application switches from the foreground to the background, and the mobile phone 100 can periodically determine the number of accessed objects obtained from the moment when the application switches to the background, and execute 1005 when the preset time period is reached.

[0144] If the time period from the moment the application switches to the background to the current moment does not exceed the first time period, the mobile phone 100 can continue to determine the objects accessed by the application, such as the mobile phone 100 can re-execute steps 1001-1004 after a preset time. In the embodiment of the present application, the preset time can be 5 seconds, or 4 seconds, 4.5 seconds, 6 seconds, etc. The embodiment of the present application does not impose any specific restrictions on the preset time. In other words, within the first time period, the mobile phone 100 can collect the accessed objects at a fixed frequency. For example, the above steps 1001-1004 are executed once every 5 seconds to collect the objects accessed by the application during the period when the application exits and runs in the background.

[0145] Although the access to objects in the page by the application can only be collected once at a fixed frequency, since the pages allocated to the application only have a few objects accessed by the application, this method is sufficient to collect most of the objects accessed by the application to a certain extent.

[0146] 1005. Mark the read and write permissions of all pages allocated to the application as read and write.

[0147] Mark the read and write permissions of all pages allocated to the application as read and write so that the application can run normally.

[0148] The following introduces the proof data of saving memory after executing the memory management method provided in the embodiment of the present application.

[0149] Table 1 shows the memory capacity saved after multiple applications execute the memory management method provided by the embodiment of the present application. As shown in Table 1, each row in the table indicates an application, the ratio of the number of first pages to the total number of pages allocated to the application, and the memory capacity that can be saved after the application executes the memory management method provided by the embodiment of the present application. Among them, the first page in the table refers to a page in which the number of accessed objects stored is less than 5.

[0150] Table 1

[0151]

[0152] As shown in Table 1 above, after the mobile phone 100 executes the memory management method provided by the embodiment of the present application, when the existing application 1 is running in the background, 8.45MB of memory can be saved. When the existing application 2 is running in the background, 4.82MB of memory can be saved. When the existing application 3 is running in the background, 13.06MB of memory can be saved. When the existing application 4 is running in the background, 9.31MB of memory can be saved. Other applications are not described in detail.

[0153] It can be understood that the above-mentioned proof data can prove that the mobile phone 100 executes the memory management method provided in the embodiment of the present application, which can reduce the memory consumption of the application in the background and save memory resources.

[0154] In summary, after the mobile phone 100 executes the memory management method provided by the embodiment of the present application, on the one hand, it can save memory, reduce the memory consumption of the application in the background, save memory resources, and ensure that the application running in the foreground has sufficient memory usage, so that it runs more smoothly and improves the user experience. On the other hand, it can be understood that a page fault interruption means that the object to be accessed by the mobile phone 100 is not in the memory, and the mobile phone 100 needs to write the object stored in the storage area other than the memory into the memory before accessing it. When a page fault interruption occurs, the mobile phone 100 needs to read the object from the storage area outside the memory and write the object into the memory. This process is much slower than directly accessing the memory. Therefore, frequent page fault interruptions will cause the speed of the mobile phone 100 running the application to slow down. In the memory management method provided by the embodiment of the present application, the mobile phone 100 can store the first object distributed in different pages in a centralized manner to the target page, which reduces the number of page fault interruptions to a certain extent and improves the speed of the mobile phone 100 running the application. The mobile phone 100 can reduce the number of page fault interruptions to a certain extent and improve the speed of the mobile phone 100 running the application.

[0155] An embodiment of the present application also provides a computer storage medium, which includes computer instructions. When the computer instructions are executed on the above-mentioned terminal device, the terminal device executes each function or step executed by the mobile phone in the above-mentioned method embodiment.

[0156] The embodiment of the present application also provides a computer program product. When the computer program product is run on a computer, the computer is enabled to execute each function or step executed by the mobile phone in the above method embodiment.

[0157] It is understandable that the terminal device provided in the embodiment of the present application includes a hardware structure and / or software module corresponding to each function in order to realize the above functions. Those skilled in the art should easily realize that, in combination with the units and algorithm steps of each example described in the embodiment disclosed herein, the embodiment of the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the embodiment of the present application.

[0158] The embodiment of the present application can divide the functional modules of the above-mentioned terminal device according to the above-mentioned method example. For example, each functional module can be divided corresponding to each function, or two or more functions can be integrated into one processing module. The above-mentioned integrated module can be implemented in the form of hardware or in the form of software functional modules. It should be noted that the division of modules in the embodiment of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation.

[0159] Through the description of the above implementation methods, technical personnel in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

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

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

[0162] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0163] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium, including several instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor (processor) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.

[0164] The above contents are only specific implementation methods of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application shall be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims

1. A memory management method, characterized in that: Applied to electronic equipment, the method comprises: In response to the application switching from the foreground to the background, determining a first page from a plurality of pages allocated to the application in the memory of the electronic device; wherein the page allocated to the application is used to store objects corresponding to the functions of the application; In the case that there are multiple first pages, copy the first objects stored in the multiple first pages to the target page of the memory, copy all the objects stored in the multiple first pages to a storage area other than the memory, and release the multiple first pages; Among them, the first page is a page that meets the conditions among the multiple pages, and the conditions include: the page includes the first object and the second object; the first object is an object accessed by the application within a first time period after the application switches from the foreground to the background, and the second object is an object that is not accessed by the application within the first time period.

2. The method according to claim 1, characterized in that The conditions also include: A ratio of a size of a first object included in a page to a size of the page is smaller than a threshold.

3. The method according to claim 1 or 2, characterized in that: Before acquiring the first page from a plurality of pages allocated for the application in the memory of the electronic device, the method further includes: The first object is determined.

4. The method according to claim 3, characterized in that The determining the first object includes: Marking the read and write permissions of the plurality of pages as unreadable and unwritable; During the first time period, detecting whether there is an access violation event; When the access violation event is detected, the object corresponding to the physical address carried in the access violation event is determined as the first object.

5. The method according to claim 4, characterized in that The detecting whether there is an access violation event within the first time period includes: periodically detecting whether there is an access violation event within the first time period; The method also includes: in each detection, when the access violation event is detected, marking the read and write permissions of the page where the object corresponding to the physical address carried in the access violation event is located as readable and writable, and before starting the next detection, re-marking the read and write permissions of the page where the object corresponding to the physical address carried in the access violation event is located as unreadable and writable.

6. The method according to claim 4, characterized in that The method further comprises: After the first time period, the read and write permissions of the plurality of pages are marked as read and write enabled.

7. The method according to any one of claims 4 to 6, characterized in that: The method further comprises: storing the physical address of the first object in a preset queue; The copying of the first objects stored in the first pages to the target page of the memory includes: copying the first objects stored in the first pages to the target page of the memory according to the physical addresses of the first objects in the first pages stored in the preset queue.

8. The method according to any one of claims 4 to 6, characterized in that: The first time period is a time period within a preset time length after the application is switched from the foreground to the background, and the preset time length is preset; or; The first time period is a time period from when the application is switched from the foreground to the background to a target time, and the target time is determined based on a growth rate of the first object determined in two adjacent detections; or; The first time period is determined based on the target time and the preset duration.

9. The method according to any one of claims 1, 2, 5 and 6, characterized in that Before copying the first objects stored in the plurality of the first pages to the target page of the memory, the method further includes: The target page is allocated to the application based on the sizes of all the first objects stored in the plurality of the first pages.

10. An electronic device, characterized in that: The electronic device comprises at least a memory and one or more processors; the memory is used to store computer instructions, and when the one or more processors execute the computer instructions, the electronic device executes the method as claimed in any one of claims 1 to 9.

11. A computer-readable storage medium, characterized in that: The method comprises computer instructions, which, when executed on an electronic device, cause the electronic device to execute the method as claimed in any one of claims 1 to 9.

12. A computer program product, characterized in that When the computer program product is executed on an electronic device, the electronic device is caused to execute the method according to any one of claims 1 to 9.

Citation Information

Patent Citations

  • Memory management method and device and storage system

    CN109815005A

  • Garbage collection method of file system and related device

    CN115774516A

  • Object management method and device

    CN116737350A

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

    IN201814048951A

  • Memory management method and electronic device

    WO2024027544A1