Memory management method and electronic equipment

By monitoring and managing the number of interface components of the application, releasing memory resources occupied by interface components that exceed the threshold, solving the operational problems caused by the application's occupancy of too much memory resources and improving memory management efficiency and user experience.

CN119536978APending Publication Date: 2025-02-28HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311161842.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Priority Date
2023-08-29
Filing Date
2023-09-08
Publication Date
2025-02-28

AI Technical Summary

Technical Problem

When the proportion of memory resources occupied by the application is high, other applications can use less memory resources, resulting in problems such as lag in the application operation and unresponsiveness, and the average response time of the system to user operations becomes longer.

Method used

By monitoring the number of interface components of the application, when it exceeds the preset threshold, a certain number of memory resources occupied by the interface components are released to manage memory resources.

Benefits of technology

Effectively manage the memory resources occupied by applications in the background running state, improve the utilization efficiency and management efficiency of memory resources, and reduce the adverse impact of user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119536978A_ABST
    Figure CN119536978A_ABST
Patent Text Reader

Abstract

The invention provides a memory management method and electronic equipment, and when an application is switched from a foreground running state to a background running state, the electronic equipment can determine to manage memory resources occupied by the application according to the fact that the number of interface components contained in the application exceeds a preset threshold value. Memory management of the application is completed by releasing memory resources occupied by a certain number of interface components until the number of the interface components contained in the application does not exceed a preset threshold value. The memory management method provided by the invention is suitable for all applications installed in the electronic equipment, belongs to system level management, and memory resources occupied by the applications returning to the background can be managed in time, so that the background load of the applications can be reduced, the utilization efficiency and the management efficiency of the memory resources of the electronic equipment are improved, and the user experience is improved. Multiple applications can run smoothly at the same time, and the user experience is good.
Need to check novelty before this filing date? Find Prior Art

Description

[0001] This application claims priority to a Chinese patent application filed with the Chinese Patent Office on August 29, 2023, with application number 202311101987.1 and invention name “Memory Management Method and Electronic Device”, the entire contents of which are incorporated by reference in this application. Technical Field

[0002] The present application relates to the field of terminal device software, and in particular, to a memory management method and electronic device. Background Art

[0003] Memory is a hardware resource shared by applications running on electronic devices. Since memory resources are limited, when some applications occupy a higher proportion of memory resources, other applications will have less memory resources available. Less memory resources may cause problems such as application running stuck and unresponsiveness.

[0004] After the memory resources occupied by an application are recycled, if the user wants to use the application again, the system needs to reallocate memory resources to the application, and the average response time of the electronic device to the user's operation will be longer. Determining the appropriate time and method for recycling memory resources can shorten the average response time to user operations, reduce the adverse impact of the memory resource management process on user experience, and improve the management efficiency and utilization efficiency of memory resources. Summary of the invention

[0005] The present application provides a method for memory management. When an application switches from a foreground running state to a background running state, the electronic device can determine to manage the memory resources occupied by the application based on the number of interface components contained in the application exceeding a preset threshold. Memory management is completed by releasing the memory resources occupied by a certain number of interface components. The memory resources occupied by the application in the background running state can be managed in a timely manner, the utilization efficiency and management efficiency of the memory resources are high, and the user experience is good.

[0006] In a first aspect, a memory management method is provided, the method comprising: in response to an operation that triggers a first application to exit the background, obtaining the number of first interface components of the first application, the first interface component being used to create a window that displays the interface of the first application in the foreground; when the first application exits to the background and the number of first interface components is greater than a first threshold, releasing the memory occupied by P target interface components in the first interface components until the number of first interface components is less than or equal to the first threshold, where P is an integer greater than or equal to 1.

[0007] In some scenarios, responding to the operation of leaving the first application can also be understood as responding to an event in which the first application switches from a foreground running state to a background running state.

[0008] In a possible implementation, the first interface component may refer to an activity component in an Android system or a view component in an IOS system, etc.

[0009] In one possible implementation, the first threshold can be determined based on one or more of the total amount of memory resources of the electronic device, the total amount of applications running on the electronic device, the usage habits of the user of the electronic device, the attributes of the target application, and the usage scenario of the electronic device.

[0010] When leaving the first application, the first application goes to the background to run, and the interface of the first application is no longer displayed to the user. The probability that the interface corresponding to the interface component of the released memory resources is opened again by the user is small. At this time, the management of the memory resources occupied by the first application is not easily perceived by the user. The memory management method provided by the present technical solution is based on the user's habit of using electronic devices, or in other words, the memory management method provided by the present technical solution is more in line with the user's operational intuition. The implementation of the present technical solution is conducive to reducing the probability that the background running application causes the background load of the electronic device to be too high, the electronic device has good timeliness in recycling the memory resources of the background running application, and the memory resources of the electronic device are used efficiently.

[0011] In combination with the first aspect, in certain implementations of the first aspect, the method also includes: when the first application returns to the foreground, in response to an operation that triggers opening a new interface of the first application, reacquiring the number of first interface components; when the first application returns to the foreground and the number of reacquired first interface components is greater than a second threshold, releasing the memory occupied by Q target interface components in the first interface components until the number of first interface components is less than or equal to the second threshold, where Q is an integer greater than or equal to 1.

[0012] When a user opens a new interface in an application, the electronic device can determine whether to manage the memory resources occupied by the first application. The implementation of this technical solution is conducive to reducing the probability of memory expansion caused by the foreground running application and improving the utilization efficiency of the memory resources of the electronic device.

[0013] In combination with the first aspect, in some implementations of the first aspect, the second threshold is greater than the first threshold.

[0014] For applications in the foreground, the probability that their already opened user interfaces are opened again by users is higher. On the contrary, for applications in the background, the probability that their already opened user interfaces are opened again by users is relatively low. The second threshold is set to be greater than the first threshold, that is, the threshold value for triggering memory resource recycling for applications in the foreground is higher, and the threshold value for triggering memory resource recycling for applications in the background is lower. The implementation of this technical solution is conducive to reducing the extension of the average response time caused by the memory management process, and is conducive to improving the user experience.

[0015] In combination with the first aspect, in certain implementations of the first aspect, before releasing the memory occupied by P target interface components in the first interface component until the number of first interface components is less than or equal to a first threshold, the method also includes: determining a third interface component, the third interface component being the first interface component whose occupied memory can be released; and determining the target interface component from the third interface component.

[0016] Here, the memory occupied by the third interface component can be released, which can also be understood as that the third interface component has no data exchange with other processes or components, or that after the memory occupied by the third interface component is released, it will not affect the operation of other components or processes.

[0017] In this technical solution, the electronic device only manages and controls the interface components whose memory can be released, which is beneficial to reducing the adverse effects of the memory management method provided in this application on the operation of other uncontrolled applications.

[0018] In combination with the first aspect, in certain implementations of the first aspect, determining a target interface component from among the third interface components includes: determining an identifier of the third interface component, the identifier being used to indicate the length of a time interval between a time when the third interface component was last accessed and a current time; determining the target interface component based on the identifier, the target interface component being the N third interface components with the longest intervals between a time when the third interface component was last accessed and a current time, where N is an integer greater than or equal to 1.

[0019] For interface components whose last visit time is longer than the current time, they can be considered as interface components with a lower probability of being visited again by users. For interface components whose last visit time is shorter than the current time, they can be considered as interface components with a higher probability of being visited again by users.

[0020] In this technical solution, the electronic device can give priority to releasing the memory resources occupied by interface components that are less likely to be visited by users again. The implementation of this solution is conducive to improving the efficiency of memory resource utilization while reducing the adverse impact on user experience.

[0021] In combination with the first aspect, in certain implementations of the first aspect, the target interface component does not include the M first interface components that are accessed after the first application is started, where M is an integer greater than or equal to 1.

[0022] In a possible implementation, the target interface component does not include an interface component for displaying a main interface of the first application.

[0023] Here, the M first interface components accessed first after the first application is started can also be referred to as reserved interface components. The reserved interface components can be understood as interface components that the user needs to access frequently when using the first application, and accordingly, the interface corresponding to the reserved interface components can be understood as the interface that the user needs to open frequently when using the first application.

[0024] In a possible implementation, the target interface component is used to display the M+1th to M+Nth interfaces that are first displayed after the first application is started.

[0025] The setting of retaining interface components can isolate the memory of components that users need to access frequently from the management objects during the memory management process. Electronic devices will not frequently release or load the memory resources occupied by the retained interface components, which is beneficial to improving the efficiency of memory management and enhancing the user experience.

[0026] In combination with the first aspect, in some implementations of the first aspect, the target interface component is in a stopped state.

[0027] The target interface component is in a stopped state, which can also be understood as the user interface corresponding to the target interface component being invisible to the user in some scenarios. A component in a stopped state can stop refreshing the user interface, stop running animations, or stop other visible visual content.

[0028] In combination with the first aspect, in some implementations of the first aspect, the target interface component can be destroyed.

[0029] The stopped interface components and the destructible interface components will not exchange data with other components, processes, etc. In other words, releasing the memory occupied by the stopped interface components and the destructible interface components will not have an adverse effect on the first application or even other applications.

[0030] In combination with the first aspect, in some implementations of the first aspect, the target interface component is not in a terminating state.

[0031] For the interface component that is ending, the memory it occupies will be released after the current time. Selecting the interface component that is not ending can help reduce the probability of the memory occupied by the target interface component being repeatedly released, resulting in reduced program running efficiency or even errors. To a certain extent, it can reduce the adverse effects of the memory management method provided in this application on applications running on electronic devices.

[0032] In combination with the first aspect, in certain implementations of the first aspect, the time interval between the time when the target interface component was last accessed and the current time is greater than or equal to the first duration.

[0033] The longer the interval between the time when the user accessed the interface component and the current time, the lower the probability that the interface component will be accessed by the user again, while the interface component that the user just accessed is likely to be accessed by the user again in the next period of time. Not releasing the memory occupied by the interface component that the user just accessed is conducive to improving the management efficiency of the memory resources of the electronic device, helping to reduce the probability that the electronic device repeatedly allocates memory resources for components corresponding to the same user interface, and helping to reduce the adverse effects of memory management on the user's use of the electronic device.

[0034] In combination with the first aspect, in certain implementations of the first aspect, the method also includes: displaying the interface of a second application, the second application is different from the first application; in response to an operation that triggers the second application to exit the background, obtaining the number of second interface components of the second application, the second interface components being used to create a window that displays the interface of the second application in the foreground; when the second application exits to the background and the number of second interface components is greater than a first threshold, releasing the memory occupied by R target interface components in the second interface components until the number of second interface components is less than or equal to the first threshold, where R is an integer greater than or equal to 1.

[0035] In a possible implementation, the electronic device may obtain the number of the second interface components and the number of the aforementioned first interface components from the WindowProcessController component of the system.

[0036] The memory management method provided in the present application can be applied to multiple applications on an electronic device and belongs to system-level management. The electronic device can obtain information of multiple applications, has high management efficiency, and has a wide range of application scenarios.

[0037] In combination with the first aspect, in certain implementations of the first aspect, after the memory occupied by the target interface component is released, the number of first interface components is greater than or equal to a third threshold, and the third threshold is less than the first threshold.

[0038] In one possible implementation, the third threshold can be determined based on one or more of the total amount of memory resources of the electronic device, the total amount of applications running on the electronic device, the usage habits of the user of the electronic device, the attributes of the target application, and the usage scenario of the electronic device.

[0039] By setting a lower limit for the number of interface components to be managed for the first application, for interface components whose number is less than or equal to the third threshold, the electronic device does not release the memory resources occupied by these interface components, and the memory resources occupied by these interface components do not need to be reloaded. The implementation of this technical solution is conducive to improving the efficiency of memory management.

[0040] In combination with the first aspect, in some implementations of the first aspect, P is an integer greater than or equal to 2.

[0041] When electronic devices manage and control the resources occupied by target interface components, they need to occupy the system's lock resources. In this technical solution, electronic devices can manage the memory resources occupied by multiple target interface components at one time, which reduces the frequency of electronic devices occupying system lock resources, and helps to reduce the adverse effects of memory management on the operation of other applications running on electronic devices.

[0042] The beneficial effects and detailed descriptions of the following technical solutions can be referred to the relevant descriptions in the first aspect, and for the sake of brevity, they are not elaborated below.

[0043] In a second aspect, a memory management device is provided, which includes an acquisition module and a processing module. The acquisition module is used to: in response to an operation of leaving a first application, acquire the number of first interface components, the first interface components being used to create a window that displays the interface of the first application; the processing module is used to: when the number of first interface components is greater than a first threshold, release the memory occupied by P target interface components in the first interface components until the number of first interface components is less than or equal to the first threshold, where P is an integer greater than or equal to 1.

[0044] In combination with the second aspect, in certain implementations of the second aspect, the acquisition module is also used to: in response to the operation of returning to the first application and opening a new interface, re-acquire the number of first interface components; the processing module is also used to: when the number of first interface components is greater than a second threshold, release the memory occupied by Q target interface components in the first interface components until the number of first interface components is less than or equal to the second threshold, where Q is an integer greater than or equal to 1.

[0045] In combination with the second aspect, in some implementations of the second aspect, the second threshold is greater than the first threshold.

[0046] In combination with the second aspect, in certain implementations of the second aspect, the processing module is also used to: display the interface of the second application; the acquisition module is also used to: in response to an operation of leaving the second application, obtain the number of second interface components, the second interface components being used to create a window displaying the interface of the second application; the processing module is also used to: when the number of second interface components is greater than a first threshold, release the memory occupied by R target interface components in the second interface components until the number of second interface components is less than or equal to the first threshold, where R is an integer greater than or equal to 1.

[0047] In combination with the second aspect, in certain implementations of the second aspect, the processing module is also used to: determine a third interface component before releasing the memory occupied by P target interface components in the first interface component until the number of first interface components is less than or equal to a first threshold, the third interface component being the first interface component whose occupied memory can be released; and determine the target interface component from the third interface component.

[0048] In combination with the second aspect, in certain implementations of the second aspect, the processing module is specifically used to: determine an identifier of the third interface component, the identifier being used to indicate the length of the time interval between the time of the last visit to the third interface component and the current time; determine the target interface component based on the identifier, the target interface component being the N third interface components with the longest interval between the time of the last visit and the current time, where N is an integer greater than or equal to 1.

[0049] In combination with the second aspect, in certain implementations of the second aspect, the target interface component does not include the M first interface components that are accessed after the first application is started, where M is an integer greater than or equal to 1.

[0050] In combination with the second aspect, in some implementations of the second aspect, the target interface component is in a stopped state.

[0051] In combination with the second aspect, in some implementations of the second aspect, the target interface component can be destroyed.

[0052] In combination with the second aspect, in some implementations of the second aspect, the target interface component is not in a terminating state.

[0053] In combination with the second aspect, in certain implementations of the second aspect, the time interval between the time when the target interface component was last accessed and the current time is greater than or equal to the first duration.

[0054] In combination with the second aspect, in certain implementations of the second aspect, after the memory occupied by the target interface component is released, the number of first interface components is greater than or equal to a third threshold, and the third threshold is less than the first threshold.

[0055] In combination with the second aspect, in some implementations of the second aspect, P is an integer greater than or equal to 2.

[0056] According to a third aspect, an electronic device is provided, comprising a processor and a memory, the memory being used to store program instructions, the processor being used to: in response to an operation of leaving a first application, obtain the number of first interface components, the first interface component being used to create a window for displaying the interface of the first application; and, when the number of first interface components is greater than a first threshold, release the memory occupied by P target interface components in the first interface components until the number of first interface components is less than or equal to the first threshold, where P is an integer greater than or equal to 1.

[0057] In combination with the third aspect, in certain implementations of the third aspect, the processor is also used to: in response to an operation of returning to the first application and opening a new interface, reacquire the number of first interface components; when the number of first interface components is greater than a second threshold, release the memory occupied by Q target interface components in the first interface components until the number of first interface components is less than or equal to the second threshold, where Q is an integer greater than or equal to 1.

[0058] In combination with the third aspect, in some implementations of the third aspect, the second threshold is greater than the first threshold.

[0059] In combination with the third aspect, in certain implementations of the third aspect, the processor is also used to: display the interface of the second application; in response to an operation of leaving the second application, obtain the number of second interface components, the second interface components being used to create a window displaying the interface of the second application; when the number of second interface components is greater than a first threshold, release the memory occupied by R target interface components in the second interface components until the number of second interface components is less than or equal to the first threshold, where R is an integer greater than or equal to 1.

[0060] In combination with the third aspect, in certain implementations of the third aspect, the processor is also used to: determine a third interface component before releasing the memory occupied by P target interface components in the first interface component until the number of first interface components is less than or equal to a first threshold, the third interface component being the first interface component whose occupied memory can be released; and determine the target interface component from the third interface component.

[0061] In combination with the third aspect, in certain implementations of the third aspect, the processor is specifically used to: determine an identifier of the third interface component, the identifier being used to indicate the length of the time interval between the last time the third interface component was accessed and the current time; determine a target interface component based on the identifier, the target interface component being the N third interface components with the longest interval between the last time the third interface component was accessed and the current time, where N is an integer greater than or equal to 1.

[0062] In combination with the third aspect, in certain implementations of the third aspect, the target interface component does not include the M first interface components that are accessed after the first application is started, where M is an integer greater than or equal to 1.

[0063] In combination with the third aspect, in certain implementations of the third aspect, the target interface component is in a stopped state.

[0064] In combination with the third aspect, in certain implementations of the third aspect, the target interface component can be destroyed.

[0065] In combination with the third aspect, in certain implementations of the third aspect, the target interface component is not in a terminating state.

[0066] In combination with the third aspect, in certain implementations of the third aspect, the time interval between the time when the target interface component was last accessed and the current time is greater than or equal to the first duration.

[0067] In combination with the third aspect, in certain implementations of the third aspect, after the memory occupied by the target interface component is released, the number of first interface components is greater than or equal to a third threshold, and the third threshold is less than the first threshold.

[0068] In combination with the third aspect, in certain implementations of the third aspect, P is an integer greater than or equal to 2.

[0069] According to a fourth aspect, a computer program product is provided. The computer program product comprises a computer program code. When the computer program code is run on a computer, the method in the first aspect and any possible implementation manner thereof is executed.

[0070] In a fifth aspect, a computer-readable storage medium is provided, which stores a computer program code. When the computer program code runs on a computer, the method in the first aspect and any possible implementation thereof is executed.

[0071] In a sixth aspect, a chip is provided, comprising a processor for reading instructions stored in a memory, wherein when the processor executes the instructions, the chip implements the method in the first aspect and any possible implementation thereof. BRIEF DESCRIPTION OF THE DRAWINGS

[0072] Figure 1 It is a schematic diagram of the hardware architecture of an electronic device applicable to an embodiment of the present application.

[0073] Figure 2 It is a schematic diagram of the software architecture of an electronic device applicable to an embodiment of the present application.

[0074] Figure 3 It is a schematic diagram of a graphical user interface provided in an embodiment of the present application.

[0075] Figure 4 It is a schematic diagram of a memory management method provided in an embodiment of the present application.

[0076] Figure 5 It is a schematic diagram of another memory management method provided in an embodiment of the present application.

[0077] Figure 6 It is a schematic diagram of a memory management device provided in an embodiment of the present application.

[0078] Figure 7 It is a schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0079] The technical solution in this application will be described below in conjunction with the accompanying drawings.

[0080] 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 "one", "a kind of", "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, two or more. The term "and / or" is used to describe the association relationship of associated objects, indicating that three relationships may 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 objects associated before and after are in an "or" relationship.

[0081] References to "one embodiment" or "some embodiments" etc. described in this specification mean that a particular feature, structure or characteristic described in conjunction with the embodiment is included in one or more embodiments of the present application. Thus, the phrases "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear at 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.

[0082] The method provided in the embodiments of the present application can be applied to electronic devices such as mobile phones, tablet computers, wearable devices, vehicle-mounted devices, augmented reality (AR) / virtual reality (VR) devices, laptop computers, ultra-mobile personal computers (UMPCs), netbooks, personal digital assistants (PDAs), etc. The embodiments of the present application do not impose any restrictions on the specific types of electronic devices.

[0083] For example, Figure 1 1 shows a schematic diagram of the structure of the electronic device 100. The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. 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.

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

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

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

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

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

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

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

[0091] The charging management module 140 is used to receive charging input from a charger, where the charger can be a wireless charger or a wired charger.

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

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

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

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

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

[0097] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 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.

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

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

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

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

[0102] The software system of the electronic device 100 may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. The embodiment of the present application takes the Android system of the layered architecture as an example to exemplify the software structure of the electronic device 100.

[0103] Figure 2 1 is a software structure diagram of the electronic device 100 of the embodiment of the present application. The layered architecture divides the software into several layers, 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 four layers, from top to bottom, namely, the application layer, the application framework layer, the Android runtime (Android runtime) and the system library, and the kernel layer. The application layer can include a series of application packages.

[0104] like Figure 2 As shown, the application package may include camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message and other applications.

[0105] The application framework layer provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer includes some predefined functions.

[0106] like Figure 2 As shown, the application framework layer may include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, and the like.

[0107] The window manager is used to manage window programs. The window manager can obtain the display screen size, determine whether there is a status bar, lock the screen, capture the screen, etc.

[0108] Content providers are used to store and retrieve data and make it accessible to applications. The data may include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.

[0109] The view system includes visual controls, such as controls for displaying text, controls for displaying images, etc. The view system can be used to build applications. A display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying images.

[0110] The phone manager is used to provide communication functions of the electronic device 100, such as management of call status (including connecting, hanging up, etc.).

[0111] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.

[0112] The notification manager enables applications to display notification information in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of a chart or scroll bar text, such as notifications of applications running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is displayed in the status bar, a prompt sound is emitted, an electronic device vibrates, an indicator light flashes, etc.

[0113] Android runtime includes core libraries and virtual machines. Android runtime is responsible for scheduling and management of the Android system.

[0114] The core library consists of two parts: one part is the function that needs to be called by the Java language, and the other part is the Android core library.

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

[0116] The system library may include multiple functional modules, such as surface manager, media libraries, 3D graphics processing library (such as OpenGL ES), 2D graphics engine (such as SGL), etc.

[0117] The surface manager is used to manage the display subsystem and provide the fusion of 2D and 3D layers for multiple applications.

[0118] The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.

[0119] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.

[0120] A 2D graphics engine is a drawing engine for 2D drawings.

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

[0122] It should be understood that the technical solutions in the embodiments of the present application can be used in Android, IOS, Hongmeng and other systems.

[0123] Before formally introducing the embodiments of the present application, some terms and definitions that may be used in the following contents are first explained.

[0124] Memory management is a form of resource management applied to computer memory. The basic requirement of memory management is to provide methods to dynamically allocate parts of memory according to program requests and release them for reuse when they are no longer needed.

[0125] Memory recycling refers to the operating system releasing recyclable memory.

[0126] Memory bloat refers to the phenomenon that memory consumption increases significantly in a short period of time. Compared with memory leak, memory bloat is usually more sensitive to time. Generally speaking, memory bloat is caused by poor memory management of the application and loading too much memory in a short period of time. For example, when an application loads a large number of unnecessary data objects into memory, these data are neither used by the application nor released from memory.

[0127] Activity is a component used to represent the presentation layer of an Android application, for example, what the user sees on the display. An Android application can include multiple activities, and multiple activities can be switched between while the application is running. Almost all activities can interact with the user. Activities can be used to create a window that can present a user interface. This window can be a floating window, a multi-window mode, or a window embedded in other windows.

[0128] A large number of applications can be run on the operating system of an electronic device, and these applications can share the software and hardware resources of the electronic device. For example, in some scenarios, when the electronic device cannot provide enough memory resources to run application A, the electronic device will recycle the allocated memory resources. In the process of memory resource recycling, the electronic device may recycle all the memory resources occupied by application B that the user has opened, that is, close application B. When the user wants to use application B again, the electronic device needs to reallocate memory resources to application B, and it is difficult for the user to continue the operation in the state when leaving application B. The electronic device has low efficiency in allocating and recycling memory resources, and has a long response time to user operations.

[0129] In order to improve the management efficiency of electronic devices for memory resources and shorten the response time of electronic devices to user operations, the present application provides a memory management method, which is now introduced as follows.

[0130] Figure 3 The figure shows a schematic diagram of a first interface 300 of a first application (hereinafter referred to as the first application) running on an electronic device. The first interface 300 includes a playback area 310 and a display area 320, wherein the playback area 310 is used to play the target video selected by the user, and the display area 320 is used to display recommended videos related to the target video. In response to operations such as clicking and sliding on the playback area 310, the electronic device can perform operations such as playing, pausing, and fast-forwarding the target video. In response to a selection operation on any recommended video (for example, recommended video 1) displayed in the display area 320, the electronic device can display a second interface. The second interface is similar to the first interface 300, and also includes a playback area and a display area, wherein the playback area 310 is used to play recommended video 1, and the display area is used to display recommended videos related to recommended video 1.

[0131] When the electronic device displays the first interface 300, the electronic device will allocate a part of the memory resources (for example, the first memory) to the first application from the memory resources. When the electronic device jumps from the first interface 300 to open the second interface in response to the user's operation, the electronic device will allocate a new part of the memory resources (for example, the second memory) to the first application from the memory resources. Here, the first memory and the second memory do not belong to the same part of the memory resources. Similarly, the user can also open the third interface from the second interface, and the electronic device needs to allocate memory resources corresponding to the third interface to the first application. However, when the electronic device displays the second interface, the probability of the user opening the first interface again is low, and the probability of the first memory corresponding to the first interface being accessed again is low; when the electronic device displays the third interface, the probability of the user opening the second interface or the first interface again is even lower, and the probability of the first memory corresponding to the first interface and the second memory corresponding to the second interface being accessed again is low. In this case, it is possible to consider releasing the first memory and / or the second memory.

[0132] In other scenarios, the user leaves the first application and returns to the desktop application or switches from the first application to another application (such as the second application). The first application switches from the foreground running state to the background running state, and all user interfaces opened by the first application are invisible. In this case, the probability of the user opening the first interface, the second interface, or the third interface of the first application again may also be relatively low, and the memory resources corresponding to these interfaces of the first application may also be considered for release.

[0133] In different operating systems, the user interface of an application may be presented by different components. In other words, for different operating systems, the components used to present the user interface are different. In the Android system or the Android open source project (AOSP), the activity component provides a window in which different user interfaces of an application are drawn. In IOS, a view is a basic element of an application's user interface, and different user interfaces of an application can be presented through different views. In the following embodiments, the memory management method provided in this application is described by taking Android or AOSP as an example, and the memory management method provided in this application under IOS or other operating systems can be executed for reference.

[0134] Figure 4 A memory management method provided in an embodiment of the present application is shown, and the electronic device can manage the memory resources occupied by the foreground application by controlling the number of activities corresponding to the application in the foreground running state.

[0135] S110: Detecting a new creation activity of a first application.

[0136] The first application may refer to an application that needs to perform memory management, and the newly created activity of the first application may refer to a new activity added to a task stack by a running process of the first application.

[0137] In some examples, in response to an operation of opening a new interface on the interface of the first application, the first application newly creates an activity.

[0138] In some examples, the electronic device can determine whether the first application has created a new activity by detecting whether there is a new activity in the task stack. In some examples, the electronic device can also determine whether the first application has created a new activity by detecting whether a new interface of the first application is displayed. The electronic device can also determine whether the first application has created a new activity in other ways, which are not limited in this application.

[0139] In the case of a new creation activity of the first application, the electronic device can manage the memory resources occupied by the first application, that is, execute S120 and subsequent operations. This management operation is conducive to reducing the probability of memory expansion caused by the continuous creation of new activities by the first application in the foreground running state, and is conducive to improving the utilization efficiency of the memory resources of the electronic device.

[0140] S120: Determine the number of all activities of the first application.

[0141] In order to achieve effective management of memory resources occupied by the first application, the electronic device can set the maximum number of activities that the first application in the foreground running state can contain (first upper limit value). When the first application is in the foreground running state and the number of activities contained in its task stack exceeds the first upper limit value, the electronic device can release the memory resources occupied by a certain number of activities of the first application to reduce the foreground load caused by the first application.

[0142] The first upper limit value is set to control the memory resources occupied by the first application by controlling the number of activities corresponding to the first application. The first upper limit value can be a preset fixed value, and the first upper limit value can be a value that can be dynamically adjusted according to the operating state of the electronic device. In the case where the first upper limit value is a fixed value, the memory management solution is relatively simple. In the case where the first upper limit value is a variable value that can be adjusted, the memory management solution is more flexible and can improve the efficiency of memory resource management to a certain extent.

[0143] The first upper limit value can be determined based on one or more of the total amount of memory resources of the electronic device, the total amount of applications running on the electronic device, the usage habits of the user of the electronic device, the attributes of the first application, and the usage scenario of the electronic device.

[0144] Exemplarily, when the total amount of applications running on the electronic device is constant, the greater the total amount of memory resources of the electronic device, the greater the value of the first upper limit value can be. When the total amount of memory resources of the electronic device is constant, the fewer the number of applications running on the electronic device, the higher the upper limit of the memory resources that can be occupied by the first application, that is, the greater the first upper limit value can be.

[0145] For example, for two electronic devices A and B with the same total amount of memory resources, the user uses the first application less frequently on electronic device A and more frequently on electronic device B. In this case, the first upper limit value corresponding to the first application on electronic device A may be smaller, and the first upper limit value corresponding to the first application on electronic device B may be larger.

[0146] Exemplarily, the electronic device may classify different applications running on the electronic device, for example, including games, instant messaging, information, and videos. The upper limit values ​​of the memory resources that can be occupied by different types of applications may be different. For example, for game applications, the probability that a user repeatedly opens multiple different interfaces within a time period is high, and the first upper limit value corresponding to the game application may be large; for information applications, the probability that a user repeatedly opens different interfaces within a time period is low, and the first upper limit value corresponding to the information application may be small.

[0147] Exemplarily, when an electronic device simultaneously runs a music playback application and a video playback application, the first upper limit value of the music playback application may be higher when the music playback application is in the foreground and the video playback application is in the background, relative to a case where the video playback application is in the foreground and the music playback application is in the background.

[0148] In some examples, the first upper limit value is the same for all applications running on the electronic device, which is conducive to the electronic device to uniformly manage all applications from the system level. In some examples, different first upper limits can be set for different applications running on the electronic device, which is conducive to achieving performance optimization for specific applications.

[0149] When the number of all activities of the first application exceeds the first upper limit, the electronic device may release the memory resources occupied by the activities of the first application by executing S130 and subsequent steps.

[0150] When the number of all activities of the first application does not exceed the first upper limit, the electronic device may not continue to execute S130 and subsequent steps, or in other words, the electronic device may continue to execute S110 to detect whether the first application has newly created an activity.

[0151] In some scenarios, the first upper limit value can be understood as the upper limit of the memory resources that can be occupied by the first application. The more memory resources that the first application can occupy, the more activities that the first application can include.

[0152] S130, determining candidate activities.

[0153] For the first application that needs to be managed, the electronic device can traverse all activities in the task stack of the first application, and obtain all activities in the task stack that are in an inactive state as candidate activities that may be managed.

[0154] Candidate activities or inactive activities can also be referred to as activities that can release memory resources. Whether the memory resources occupied by activities in the task stack can be released or whether an activity in the task stack is a candidate activity can be determined based on the properties or status of the activity.

[0155] In some examples, the candidate activity may refer to an activity in a STOPPED state.

[0156] The candidate activity is in a stopped state. In some scenarios, it can also be understood that the user interface corresponding to the candidate activity is no longer visible to the user. The activity in the stopped state can stop refreshing the user interface, stop running animations, or stop other visible visual content.

[0157] In some examples, the candidate activity may refer to a destructible activity, or in other words, the return value of the isDetroyable() function of the candidate activity is true.

[0158] Exemplarily, if the candidate activity is not in the terminating state or the candidate activity has a running process, the return value of the isDestroyable() function of the candidate activity is true.

[0159] Activities in a stopped state and destructible activities will not exchange data with other activities, processes, etc. In other words, releasing the memory resources occupied by activities in a stopped state and destructible activities will not have an adverse effect on the first application or even other applications.

[0160] In some examples, the candidate activity may refer to an activity that is not ending, or in other words, the return value of the isFinishing() function of the candidate activity is false.

[0161] Exemplarily, in a case where the electronic device has called a finish() method to end the candidate activity, the return value of the isFinishing() function of the candidate activity is true.

[0162] For activities that are ending, the memory resources they occupy will be released after the current time. Selecting activities that are not ending as candidate activities helps reduce the probability of memory resources occupied by candidate activities being repeatedly released, resulting in reduced program running efficiency or even errors. To a certain extent, it can reduce the adverse effects of the memory management method provided in this application on applications running on electronic devices.

[0163] In some examples, the candidate activity may refer to an activity whose time interval between the last access time and the current time is greater than or equal to a preset threshold.

[0164] The longer the interval between the time when the user accesses the activity and the current time, the lower the probability that the activity will be accessed by the user again, while the activity that the user has just accessed is likely to be accessed by the user again in the next period of time. Not taking the activity that the user has just accessed as a candidate activity is conducive to improving the management efficiency of the memory management method provided by the present application, is conducive to reducing the probability that the electronic device repeatedly allocates memory resources for activities corresponding to the same user interface, and is conducive to reducing the adverse effects of memory management on the user's use of the electronic device.

[0165] In some examples, the candidate activity may be determined according to one or more of the above conditions. For example, the candidate activity may refer to an activity that is in a stopped state, destructible, not ending, and the length of the last access time is greater than or equal to a preset time.

[0166] S140, determining a target activity.

[0167] In some examples, for one or more candidate activities determined in S130, the electronic device may sort these activities in the order of user access time (such as in a z-order manner), with the candidate activities most recently accessed by the user being arranged at a later position, and the candidate activities accessed earliest by the user being arranged at an earlier position.

[0168] In some examples, the target activity may be n candidate activities ranked top among m candidate activities, where m and n are both natural numbers, and m≥n.

[0169] In some examples, the plurality of candidate activities may include a reserved activity, or in other words, some of the plurality of candidate activities will not be determined as target activities, and memory resources will not be released. For example, the reserved activity may be an activity corresponding to the main interface of the first application, an activity corresponding to the first s user interfaces accessed by the user after opening the first application, and the like.

[0170] As an example, the electronic device may determine the reserved number s, and after sorting multiple candidate activities, each candidate activity has a corresponding sequence number, and the electronic device will not determine the activities whose sequence numbers are less than or equal to s as target activities. For example, s=5, and the candidate activities are numbered starting from 1, then the electronic device will not determine the candidate activities with sequence numbers 1, 2, 3, 4, and 5 as target activities.

[0171] S150, releasing memory resources occupied by the target activity.

[0172] In some examples, the electronic device may set a first lower limit value for the first application, and the first lower limit value may be used to indicate the number of activities of the first application in the foreground running state during the memory management process for which memory resources may not be released.

[0173] In some examples, the aforementioned number of reserved activities may be used to indicate the first lower limit value herein.

[0174] In some examples, the first lower limit value is the same for all applications running on the electronic device, which is conducive to the electronic device to uniformly manage all applications from the system level. In some examples, different first lower limits can be set for different applications running on the electronic device, which is conducive to achieving performance optimization for specific applications.

[0175] As explained above, different electronic devices, different operating scenarios and other factors determine different first upper limits, and the first lower limit is determined in a similar manner to the first upper limit. Specifically, the first lower limit can be determined based on one or more of the total amount of electronic device memory resources, the total amount of applications running on the electronic device, the usage habits of the electronic device user, the attributes of the first application, and the usage scenario of the electronic device.

[0176] Exemplarily, when the total amount of applications running on the electronic device is constant, the greater the total amount of memory resources of the electronic device, the greater the value of the first lower limit can be. When the total amount of memory resources of the electronic device is constant, the fewer the number of applications running on the electronic device, the higher the upper limit of the memory resources that can be occupied by the first application, that is, the greater the first lower limit can be.

[0177] For example, for two electronic devices A and B having the same total amount of memory resources, the user uses the first application less frequently on electronic device A and more frequently on electronic device B. In this case, the first lower limit value corresponding to the first application on electronic device A may be smaller, and the first lower limit value corresponding to the first application on electronic device B may be larger.

[0178] Exemplarily, the electronic device may classify different applications running on the electronic device, for example, including games, instant messaging, information, videos, etc. The upper limit of the memory resources that can be occupied by different types of applications may be different. For example, for game applications, the probability of users repeatedly opening multiple different interfaces within a time period is relatively high, and the first lower limit corresponding to game applications may be relatively high; for information applications, the probability of users repeatedly opening different interfaces within a time period is relatively low, and the first lower limit corresponding to information applications may be relatively low.

[0179] Exemplarily, when an electronic device simultaneously runs a music player application and a video player application, relative to a case where the video player application is running in the foreground and the music player application is running in the background, when the music player application is running in the foreground and the video player application is running in the background, the lower limit value of the music player application can be higher.

[0180] In a possible implementation, the electronic device may determine one of the first upper limit value and the first lower limit value and a difference between the first upper limit value and the first lower limit value, thereby determining the other of the first upper limit value and the first lower limit value.

[0181] The number of activities that the electronic device can release occupying memory resources can be any value of the difference between the candidate activities currently corresponding to the first application and the first lower limit. For ease of explanation, A represents the aforementioned first upper limit, B represents the first lower limit, C0 represents the number of current activities corresponding to the first application, C1 represents the number of candidate activities, C2 represents the number of target activities, and C3 represents the number of target activities for which memory resources need to be released.

[0182] It is easy to know that A>B, C0≥C1≥C2≥C3.

[0183] In the case of C0≥A, the electronic device may perform the aforementioned S120 and subsequent operations. C1 refers to the number of activities that meet the conditions for releasing memory resources. In order to reduce the impact of memory management on the user's normal use of the first application, the electronic device may determine one or more reserved activities, that is, determine C2 target activities from C1 candidate activities for memory resource release.

[0184] In one possible case, after C0 activities release C2 activities, the number of remaining activities is greater than or equal to the first lower limit value, then the electronic device can release the memory resources occupied by C2 target activities. In other words, in this case, C2=C3.

[0185] In a possible case, after C0 activities release C2 activities, the number of remaining activities is less than the first lower limit, then the electronic device can select only C3 from C2 target activities to release memory resources. Here, C3 is equal to the difference between C2 and the first lower limit.

[0186] After determining the number of target activities for which memory resources need to be released and the target activities for which memory resources need to be released, the electronic device can release the memory resources occupied by the corresponding target activities. Exemplarily, the electronic device can call the destroyImmediately method or the finishIfPossible method to complete the release of the memory resources occupied by the target activities.

[0187] In some examples, the electronic device may release memory resources occupied by multiple target activities at one time. For example, the number of target activities for which the electronic device releases memory resources at one time is the difference between the first upper limit and the first lower limit.

[0188] Compared with releasing the memory resources occupied by one target activity each time, the electronic device can release the memory resources occupied by multiple target activities at one time through multiple releases, thereby reducing the occupation of the lock resources of the window system by the memory management method provided in the present application during the execution of memory management, which is beneficial to reducing the adverse effects of memory management on the operation of other applications on the electronic device.

[0189] Figure 5 The figure shows another memory management method provided by an embodiment of the present application. When an application switches from a foreground running state to a background running state, the electronic device can manage the total amount of memory resources occupied by the application by releasing the memory resources occupied by the application's activities based on a threshold of the number of background activities corresponding to the application.

[0190] S210: Detecting that the first application is switched from a foreground running state to a background running state.

[0191] In some examples, the electronic device can determine the foreground and background running states of the first application according to whether the activity of the first application is visible to the user. Specifically, if the activity corresponding to the first application is visible to the user, the first application is determined to be in the foreground running state. If the activity corresponding to the first application is not visible to the user, the first application is determined to be in the background running state.

[0192] The activity of the first application can be displayed in full screen, or can be displayed in combination with other applications through windows, or can be displayed in a floating window, and this application does not impose any restrictions on this.

[0193] When the first application switches from the foreground running state to the background running state, the electronic device can display a second application different from the first application, or in other words, the second application is in the foreground running state when the first application retreats to the background. When the second application opens a new interface or creates a new activity, the electronic device can manage the memory resources occupied by the second application in the foreground running state according to the number of activities contained in the second application. For specific management methods, please refer to Figure 4 For the sake of brevity, the relevant descriptions in the illustrated embodiments are not repeated here.

[0194] The electronic device can manage multiple different applications in different operating states. The management method belongs to system-level management and is applicable to a variety of different applications.

[0195] S220: Determine the number of all activities of the first application.

[0196] In order to reduce the memory resources occupied by the first application running in the background, the electronic device can set the maximum number of activities that the first application running in the background can contain (a second upper limit value). When the number of activities corresponding to the first application exceeds this maximum value, the electronic device can release the memory resources occupied by a certain number of activities of the first application to reduce the background load caused by the first application.

[0197] In some examples, the second upper limit value may be a preset fixed value, and the second upper limit value may be a value that can be dynamically adjusted according to the operating state of the electronic device. The second upper limit value may be determined according to one or more of the total amount of memory resources of the electronic device, the total amount of applications running on the electronic device, the usage habits of the user of the electronic device, the attributes of the first application, and the usage scenario of the electronic device.

[0198] The method for determining the second upper limit is similar to the method for determining the first upper limit. For details, please refer to Figure 4 For the sake of brevity, the relevant contents in the illustrated embodiment are not described in detail here.

[0199] In some examples, the second upper limit value is the same for all applications running on the electronic device, which is conducive to the electronic device to uniformly manage all applications from the system level. In some examples, different second upper limits can be set for different applications running on the electronic device, which is conducive to achieving performance optimization for specific applications.

[0200] In some examples, after the first application enters the background and runs for a period of time, it can enter the foreground and run again. When the first application creates a new activity, the electronic device can manage the memory resources occupied by the first application in the foreground according to the number of activities contained in the first application. For specific management methods, please refer to Figure 4 For the sake of brevity, the relevant descriptions in the illustrated embodiments are not repeated here.

[0201] It should be noted that the upper limit of the number of activities that can be included in the first application in the foreground running state may be different from the upper limit of the number of activities that can be included in the first application in the background running state. Figure 4 The first upper limit value in the illustrated embodiment and the second upper limit value in this embodiment may be different.

[0202] In some examples, the first upper limit value may be greater than the second upper limit value. For an application running in the foreground, the probability that the user switches between multiple interfaces of the application is greater, while for an application running in the background, the probability that the user switches between multiple interfaces of the application is smaller. By setting the first upper limit value to a larger value and the second upper limit value to a smaller value, the probability of affecting the user experience when the electronic device performs memory management is smaller, or in other words, this setting method is conducive to improving the efficiency of memory management of the electronic device.

[0203] S230, determining an inactive activity.

[0204] To improve the efficiency of memory management and reduce the adverse effects of memory management on user experience, the electronic device may determine the activities whose occupied memory can be released from all activities of the first application, and give priority to releasing the memory occupied by these activities in the subsequent memory release process. In some examples, these activities whose memory can be released may be referred to as inactive activities.

[0205] In some examples, an inactive activity may refer to an activity that is in a STOPPED state.

[0206] In some examples, the return value of the isDetroyable() function of an inactive activity is true.

[0207] In some examples, the return value of the isFinishing() function of an inactive activity is false.

[0208] In some examples, the inactive activity may refer to an activity in which the time interval between the last access time and the current time is greater than or equal to a preset threshold.

[0209] In some examples, the inactive activity may be determined according to one or more of the above conditions. For example, the inactive activity may refer to an activity that is in a stopped state, destructible, not ending, and the last access time length is greater than or equal to a preset time length.

[0210] In some examples, the electronic device may record these inactive activities in the same array (eg, called an inactive activity array), and manage the inactive activities by managing the members in the array, thereby improving management efficiency.

[0211] Description of inactive activities Figure 4 The relevant description in S130 in the illustrated embodiment is similar and will not be repeated here for the sake of brevity.

[0212] S240, determining a target activity.

[0213] In some examples, the electronic device may sort all members in the inactive activity array determined in S230 according to the order of user access time, arranging the inactive activities most recently accessed by the user at a later position and the inactive activities accessed earliest by the user at an earlier position.

[0214] In some examples, the target activity may be n top-ranked inactive activities among m inactive activities, where m and n are both natural numbers, and m≥n.

[0215] In some examples, the plurality of inactive activities may include a reserved activity, or in other words, some of the plurality of inactive activities will not be determined as target activities, and memory resources will not be released.

[0216] S250, releasing the memory resources occupied by the target activity.

[0217] After the memory resources occupied by the activity are released, if the user accesses the activity again, the system needs to allocate memory resources for the activity again, and the response time of the electronic device to the user's operation of accessing the activity is prolonged.

[0218] In order to shorten the response time, reduce the user's waiting time, and improve the user experience. In some examples, the electronic device can set the number of activities that can be included when the first application is in the background running state (the second lower limit value). For activities within the second lower limit value, the electronic device may not release the memory resources occupied by these activities. When the user needs to access these activities, the electronic device can quickly process the memory resources occupied by these activities and complete operations such as displaying the user interface corresponding to these activities.

[0219] In some examples, the aforementioned number of reserved activities may be used to indicate the second lower limit value here.

[0220] In some examples, the second lower limit value is the same for all applications running on the electronic device, which is conducive to the electronic device to uniformly manage all applications from the system level. In some examples, different second lower limits can be set for different applications running on the electronic device, which is conducive to achieving performance optimization for specific applications.

[0221] The method for determining the second lower limit value is Figure 4 The method for determining the first lower limit value in the illustrated embodiment is similar, and specific reference may be made to the relevant content in S150 . For the sake of brevity, it will not be described here in detail.

[0222] It should be noted that the lower limit of the number of activities that can be included in the first application in the foreground running state may be different from the lower limit of the number of activities that can be included in the first application in the background running state. Figure 4 The first lower limit value in the illustrated embodiment and the second lower limit value in this embodiment may be different.

[0223] In some examples, the first lower limit value may be greater than the second lower limit value. For an application running in the foreground, the probability that the user switches between multiple interfaces of the application is greater, while for an application running in the background, the probability that the user switches between multiple interfaces of the application is smaller. By setting the first lower limit value to a larger value and the second lower limit value to a smaller value, the probability of affecting the user experience when the electronic device performs memory management is smaller, or in other words, this setting method is conducive to improving the efficiency of memory management of the electronic device.

[0224] In some examples, the electronic device may call a destroyImmediately method or a finishIfPossible method to release memory resources occupied by the activity.

[0225] Based on similar principles, Figure 6 As shown, the embodiment of the present application further provides a memory management device 600, which can have the functions of the electronic device in the above method embodiment, and can be used to execute the steps performed by the functions of the electronic device in the above method embodiment. The function can be implemented by hardware, or by software or hardware executing corresponding software implementation. The hardware or software includes one or more modules corresponding to the above functions.

[0226] In a possible implementation, the memory management device 600 may include an acquisition module 610 and a processing module 620 , and the acquisition module 610 and the processing module 620 are coupled to each other.

[0227] The acquisition module 610 can be used to support the electronic device to obtain the user's input, such as executing Figure 3The user's operation on the image user interface displayed on the electronic device is received.

[0228] The processing module 620 is used to support the electronic device to execute the processing actions in the above method embodiment, such as determining the target activity, releasing the memory resources occupied by the target activity, etc.

[0229] Optionally, the memory management device 600 may further include a storage unit 630 for storing program codes and data of the memory management device 600 .

[0230] Figure 7 An electronic device 700 provided in an embodiment of the present application, as shown in the figure, includes: at least one processor 710 and a transceiver 720. The processor 710 is coupled to a memory and is used to execute instructions stored in the memory to control the transceiver 720 to send and / or receive signals.

[0231] Optionally, the electronic device 700 further includes a memory 730 for storing instructions.

[0232] In some embodiments, the processor 710 and the memory 730 may be combined into a processing device, and the processor 710 is used to execute the program code stored in the memory 730 to implement the above functions. In specific implementation, the memory 730 may also be integrated into the processor 710 or independent of the processor 710.

[0233] In some embodiments, the transceiver 720 may include a receiver (or receiver) and a transmitter (or transmitter).

[0234] The transceiver 720 may further include an antenna, and the number of antennas may be one or more. The transceiver 720 may be a communication interface or an interface circuit.

[0235] When the electronic device 700 is a chip, the chip includes a transceiver module and a processing module, wherein the transceiver module may be an input / output circuit or a communication interface; and the processing module may be a processor or a microprocessor or an integrated circuit integrated on the chip.

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

[0237] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0238] In the several embodiments provided in the present application, it should be understood that the disclosed systems, 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 units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

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

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

[0241] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in the various embodiments of the present application. The aforementioned storage media include: various media that can store program codes, such as USB flash drives, mobile hard disks, read-only memories (ROM), random access memories (RAM), magnetic disks or optical disks.

[0242] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A memory management method, characterized in that: include: In response to an operation of triggering the first application to exit the background, obtaining the number of first interface components of the first application, the first interface components being used to create a window for displaying the interface of the first application in the foreground; When the first application retreats to the background and the number of the first interface components is greater than a first threshold, the memory occupied by P target interface components in the first interface components is released until the number of the first interface components is less than or equal to the first threshold, where P is an integer greater than or equal to 1.

2. The method according to claim 1, characterized in that: The method further comprises: When the first application returns to the foreground, in response to an operation of triggering opening a new interface of the first application, reacquiring the number of the first interface components; When the first application returns to the foreground and the number of the first interface components reacquired is greater than a second threshold, the memory occupied by Q target interface components in the first interface components is released until the number of the first interface components is less than or equal to the second threshold, where Q is an integer greater than or equal to 1.

3. The method according to claim 2, characterized in that The second threshold is greater than the first threshold.

4. The method according to any one of claims 1 to 3, characterized in that Before releasing the memory occupied by P target interface components in the first interface component until the number of the first interface components is less than or equal to the first threshold, the method further includes: Determining a third interface component, where the third interface component is the first interface component whose occupied memory can be released; The target interface component is determined from the third interface components.

5. The method according to claim 4, characterized in that The determining the target interface component from the third interface component includes: Determine an identifier of the third interface component, where the identifier is used to indicate the length of a time interval between a time when the third interface component was last accessed and a current time; The target interface component is determined according to the identifier, and the target interface component is the N third interface components whose interval between the last access time and the current time is the longest, where N is an integer greater than or equal to 1.

6. The method according to claim 5, characterized in that The target interface component does not include the M first interface components that are accessed first after the first application is started, where M is an integer greater than or equal to 1.

7. The method according to any one of claims 1 to 6, characterized in that The target interface component is in a stopped state.

8. The method according to any one of claims 1 to 7, characterized in that The target interface component can be destroyed.

9. The method according to claim 7 or 8, characterized in that: The target interface component is not in the ending state.

10. The method according to any one of claims 7 to 9, characterized in that The time interval between the last time the target interface component was accessed and the current time is greater than or equal to the first time duration.

11. The method according to any one of claims 1 to 10, characterized in that The method further comprises: Displaying an interface of a second application, where the second application is different from the first application; In response to an operation that triggers the second application to exit the background, obtaining the number of second interface components of the second application, where the second interface components are used to create a window that displays the interface of the second application in the foreground; When the second application retreats to the background and the number of the second interface components is greater than the first threshold, the memory occupied by R target interface components in the second interface components is released until the number of the second interface components is less than or equal to the first threshold, where R is an integer greater than or equal to 1.

12. The method according to any one of claims 1 to 11, characterized in that After the memory occupied by the target interface component is released, the number of the first interface components is greater than or equal to a third threshold, and the third threshold is less than the first threshold.

13. The method according to any one of claims 1 to 12, characterized in that P is an integer greater than or equal to 2.

14. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory is used to store program instructions, and the processor is used to call the program instructions to execute the method according to any one of claims 1 to 13.

15. A memory management device, characterized in that: The invention comprises modules for implementing the method according to any one of claims 1 to 13.

16. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed by a computer, the method according to any one of claims 1 to 13 is implemented.

17. A chip, characterized in that: The chip comprises a processor and a memory, wherein the processor is used to read instructions stored in the memory, and when the processor executes the instructions, the chip implements the method according to any one of claims 1 to 13.