[go: up one dir, main page]

CN114020652B - Application program management method and electronic equipment - Google Patents

Application program management method and electronic equipment Download PDF

Info

Publication number
CN114020652B
CN114020652B CN202111157747.4A CN202111157747A CN114020652B CN 114020652 B CN114020652 B CN 114020652B CN 202111157747 A CN202111157747 A CN 202111157747A CN 114020652 B CN114020652 B CN 114020652B
Authority
CN
China
Prior art keywords
application
memory
application program
failure
virtual memory
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202111157747.4A
Other languages
Chinese (zh)
Other versions
CN114020652A (en
Inventor
肖名鹏
雒云
李鹏
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Honor Device Co Ltd
Original Assignee
Honor Device Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Honor Device Co Ltd filed Critical Honor Device Co Ltd
Priority to CN202111157747.4A priority Critical patent/CN114020652B/en
Priority to CN202211578199.7A priority patent/CN116107922A/en
Publication of CN114020652A publication Critical patent/CN114020652A/en
Application granted granted Critical
Publication of CN114020652B publication Critical patent/CN114020652B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/06Addressing a physical block of locations, e.g. base addressing, module addressing, memory dedication
    • G06F12/0646Configuration or reconfiguration
    • G06F12/0684Configuration or reconfiguration with feedback, e.g. presence or absence of unit detected by addressing, overflow detection
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5016Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The embodiment of the application provides a management method of an application program, which comprises the following steps: monitoring the application result of the graphic buffer area in the running process of the application program; if the application result of the image buffer area is application failure, analyzing the failure type according to the application result; if the failure type is memory mapping failure, acquiring the virtual memory occupation condition of the application program; if the virtual memory occupied by the application program exceeds a preset threshold value, starting a suicide recovery function of the application program to release the memory occupied by the application program, avoiding serious consequences such as system crash, deadlocking and the like caused by memory leakage, and reducing the influence on the use of a user.

Description

一种应用程序的管理方法及电子设备Application program management method and electronic device

技术领域technical field

本申请涉及电子领域,尤其涉及一种应用程序的管理方法及电子设备。The present application relates to the field of electronics, and in particular to an application program management method and electronic equipment.

背景技术Background technique

内存泄露(memory leak),是指应用程序中已动态分配的堆内存由于某种原因未释放或无法及时释放,造成系统内存的浪费的现象。Memory leak refers to the phenomenon that the dynamically allocated heap memory in the application is not released or cannot be released in time for some reason, resulting in the waste of system memory.

然而,由于内存泄露不是过错类错误,目前存在难检测、难定位的问题,最终就会导致内存溢出、应用程序运行异常甚至系统卡死等严重后果。However, since memory leaks are not fault-type errors, there are currently problems that are difficult to detect and locate, which will eventually lead to serious consequences such as memory overflow, abnormal operation of applications, and even system freezes.

发明内容Contents of the invention

本申请提供了一种应用程序的管理方法,可以避免目前由于内存泄漏导致的系统卡死的情况。This application provides a method for managing application programs, which can avoid the current system stuck situation caused by memory leaks.

第一方面,提供了一种应用程序的管理方法,包括:在应用程序运行过程中,监测图形缓冲区的申请结果;若图像缓冲区的申请结果为申请失败,则根据申请结果分析失败类型;若失败类型为内存映射失败,则获取应用程序的虚拟内存占用情况;若应用程序占用的虚拟内存超过预设阈值,则启动所述应用程序的自杀恢复功能。In the first aspect, an application management method is provided, including: monitoring the application result of the graphics buffer during the running of the application; if the application result of the image buffer is application failure, analyzing the failure type according to the application result; If the failure type is memory mapping failure, the virtual memory occupation of the application is obtained; if the virtual memory occupied by the application exceeds a preset threshold, the suicide recovery function of the application is started.

在应用程序运行过程中,为了绘制界面和保存绘制的数据,运行的进程会向系统内存申请图形缓冲区(graphicbuffer)。During the running of the application, in order to draw the interface and save the drawn data, the running process will apply for a graphics buffer (graphicbuffer) from the system memory.

示例性的,可以通过graphicbuffermapper申请进程间共享的图形缓冲区,也可以通过graphicbufferallocator进程接口申请应用程序使用的图形缓冲区。Exemplarily, a graphics buffer shared between processes may be applied for through graphicbuffermapper, and a graphics buffer used by an application may also be applied for through a graphicbufferallocator process interface.

由于向内存管理器申请图形缓冲区时有可能存在内存泄漏的情况,因此可以在应用程序的进程发起图形缓冲区申请时,启动内存申请监测功能来监测图形缓冲区的申请结果。Since there may be a memory leak when applying for a graphics buffer from the memory manager, when the application process initiates a graphics buffer application, the memory application monitoring function can be enabled to monitor the application result of the graphics buffer.

需要说明的是,也可以在应用程序开始运行时就启动内存申请监测功能,还可以实时获取应用程序的虚拟内存占用情况,在应用程序的虚拟内存占用超过某一数值时(这个数值可以根根据实际应用场景来设定,本申请对此不加以限制),开启内存申请监测功能,还可以是在应用程序的虚拟内存占用超过某一数值且该应用程序的进程发起图形缓冲区申请时才启动内存申请监测功能,当然还可以在其他情况下启动内存申请监测功能。It should be noted that the memory application monitoring function can also be enabled when the application starts running, and the virtual memory usage of the application can be obtained in real time. When the virtual memory usage of the application exceeds a certain value (this value can be determined according to It can be set according to the actual application scenario, which is not limited in this application), and the memory application monitoring function can be enabled. It can also be activated when the virtual memory occupation of the application exceeds a certain value and the process of the application initiates a graphics buffer application. Memory application monitoring function, of course, the memory application monitoring function can also be activated in other situations.

示例性的,上述开启内存申请监测可以包括:用户主动开启内存申请监测功能的方式、电子设备自动开启内存申请监测功能的方式以及默认开启内存申请监测功能的方式。Exemplarily, the above-mentioned enabling of the memory application monitoring may include: a manner in which the user actively enables the memory application monitoring function, a manner in which the electronic device automatically enables the memory application monitoring function, and a manner in which the memory application monitoring function is enabled by default.

上述图形缓冲区申请的申请结果包括申请成功和申请失败。The application result of the above graphics buffer application includes application success and application failure.

在系统可用内存满足该申请,且申请到的内存能够映射到该进程的虚拟内存的地址时,内存管理器会返回申请成功的结果。When the available memory of the system satisfies the application, and the applied memory can be mapped to the address of the virtual memory of the process, the memory manager will return the result of the successful application.

在系统可用内存过少(申请的图形缓冲区占用的内存大于系统可用内存)、申请到的内存无法映射到进程的虚拟内存的地址中以及其他异常情况时,内存管理器会返回申请失败的结果。When the available memory of the system is too small (the memory occupied by the requested graphics buffer is larger than the available memory of the system), the requested memory cannot be mapped to the address of the virtual memory of the process, or other abnormal conditions, the memory manager will return the result of the application failure .

其中,可以通过/proc/self/status函数来调出应用程序的虚拟内存占用情况。Among them, the virtual memory usage of the application can be called out through the /proc/self/status function.

其中,预设阈值可以根据应用程序来设置,例如对于32位的应用程序,上述预设阈值可以设置为3.7G。当然对于32位的应用程序,上述预设阈值可以设置为比3.7G低的某些数值,例如3.5G、3.2G等。Wherein, the preset threshold can be set according to the application program, for example, for a 32-bit application program, the above preset threshold can be set to 3.7G. Of course, for 32-bit applications, the above preset threshold can be set to some value lower than 3.7G, such as 3.5G, 3.2G and so on.

以上可以看出,通过监测应用程序的进程向系统内存申请图形缓冲区的情况,在内存申请失败且是由于虚拟内存占用过多的情况下,启动自杀恢复功能,以释放被该应用程序占用的内存,避免由于内存泄露导致系统崩溃、卡死等严重后果,减轻对用户使用的影响。It can be seen from the above that by monitoring the process of the application program to apply for a graphics buffer to the system memory, when the memory application fails due to excessive use of virtual memory, the suicide recovery function is activated to release the memory occupied by the application program. Memory, to avoid serious consequences such as system crashes and freezes caused by memory leaks, and reduce the impact on users.

在第一方面的一种可能的实现方式中,上述若应用程序占用的虚拟内存超过预设阈值,则启动自杀恢复功能,包括:应用程序占用的虚拟内存超过预设阈值时,结束所述应用程序的所有进程。In a possible implementation manner of the first aspect, if the virtual memory occupied by the application exceeds the preset threshold, starting the suicide recovery function includes: ending the application when the virtual memory occupied by the application exceeds the preset threshold All processes of the program.

在应用程序占用的虚拟内存超过预设阈值时,可以通过向进程管理器发送结束该应用程序的全部进程的命令,进程管理器响应于该命令,就会结束该应用程序的全部进程,释放被该应用程序占用的系统内存。When the virtual memory occupied by the application program exceeds the preset threshold, a command to end all processes of the application program can be sent to the process manager. In response to the command, the process manager will end all processes of the application program and release the System memory used by this application.

进程管理器中有系统当前正在运行的所有进程,通过进程管理器结束带有该应用程序名相关的所有进程,就能释放该应用程序占用的系统内存。The process manager contains all the processes currently running in the system, and the system memory occupied by the application can be released by ending all the processes related to the application name through the process manager.

上述对应用程序的自动查杀可以是直接结束该应用程序的所有进程,此时,电子设备的显示界面会直接跳到显示电子设备的主屏幕界面,即用户感受到该应用程序闪退。直接结束该应用程序的所有进程,就能够释放出该应用程序占用的全部内存,避免内存泄漏导致的系统崩溃卡死等严重后果。The above-mentioned automatic scanning and killing of the application program can directly end all processes of the application program. At this time, the display interface of the electronic device will directly jump to display the main screen interface of the electronic device, that is, the user feels that the application program has flashed back. Directly ending all processes of the application program can release all the memory occupied by the application program, avoiding serious consequences such as system crashes and freezing caused by memory leaks.

在第一方面的一种可能的实现方式中,上述若应用程序占用的虚拟内存超过预设阈值,则启动自杀恢复功能,包括:应用程序占用的虚拟内存超过预设阈值时,判断申请所述图形缓冲区的进程是否为所述应用程序的主进程;In a possible implementation of the first aspect, if the above-mentioned virtual memory occupied by the application exceeds the preset threshold, the suicide recovery function is activated, including: when the virtual memory occupied by the application exceeds the preset threshold, judging the Whether the process of the graphics buffer is the main process of the application program;

若申请所述图形缓冲区的进程是否为所述应用程序的主进程,则结束应用程序的全部进程后重新拉起该应用程序的主进程;否则,结束所述应用程序的所有进程。If the process applying for the graphics buffer is the main process of the application program, then restart the main process of the application program after ending all the processes of the application program; otherwise, end all the processes of the application program.

如果申请所述图形缓冲区的进程是该应用程序的主进程,那么电子设备显示的界面就是该应用程序的主显示界面,因此,在结束该应用程序的所有进程后自动拉起该应用程序的主进程,此时电子设备的显示界面会直接跳到该应用程序的主显示界面。If the process applying for the graphics buffer is the main process of the application, then the interface displayed by the electronic device is the main display interface of the application. The main process, at this time, the display interface of the electronic device will directly jump to the main display interface of the application program.

由于结束应用程序的进程后再次拉起该应用程序的主进程的间隔时间很短,因此用户对此无感知,只能感受到电子设备的显示界面又跳回该应用程序的主显示界面。此时用户不会感受到应用程序闪退,因此可以在释放被该应用程序占用的系统内存的同时避免对用户的使用造成影响,提升用户体验感。Since the time interval between launching the main process of the application program after the process of the application program is terminated is very short, the user is not aware of this, and can only feel that the display interface of the electronic device jumps back to the main display interface of the application program. At this time, the user will not experience the crash of the application program, so the system memory occupied by the application program can be released while the impact on the user's use can be avoided, and the user experience can be improved.

在第一方面的一种可能的实现方式中,在所述在应用程序运行过程中,监测图形缓冲区的申请结果之后,还包括:In a possible implementation manner of the first aspect, after monitoring the application result of the graphics buffer during the running of the application program, it further includes:

若图形缓冲区申请的申请结果为申请成功,则将申请到的内存映射到该进程的虚拟内存的地址中。If the application result of the graphics buffer application is that the application is successful, the applied memory is mapped to the address of the virtual memory of the process.

在图形缓冲区申请成功后(即系统将内存分配给该进程使用),需要将该图形缓冲区映射到该进程对应的虚拟内存的地址空间中,该进程才能进行界面的显示绘制。After the graphics buffer application is successful (that is, the system allocates memory to the process), the graphics buffer needs to be mapped to the address space of the virtual memory corresponding to the process, so that the process can display and draw the interface.

在第一方面的一种可能的实现方式中,上述应用程序的管理方法还包括:若失败类型不为内存映射失败,则输出与失败类型对应的异常日志。In a possible implementation manner of the first aspect, the above application management method further includes: if the failure type is not a memory mapping failure, outputting an exception log corresponding to the failure type.

上述申请失败时的失败类型可以包括系统可用内存过少、内存映射失败、其他异常情况等,此处不做限定。The failure types when the above application fails may include too little available memory in the system, memory mapping failure, other abnormal conditions, etc., which are not limited here.

在一些实施例中,电子设备可以根据内存管理器返回的申请结果来确定失败类型。例如可以通过分析申请结果对应的二进行编码来确定出失败类型。In some embodiments, the electronic device may determine the failure type according to the application result returned by the memory manager. For example, the type of failure can be determined by analyzing the code corresponding to the 2 of the application result.

示例性的,当申请结果包括两个字段,其中,第一个字段用于表示申请是否成功,第二个字段用于失败类型,表示读取第二字段的编码,并基于第二字段的编码就可以确定内存申请结果。Exemplarily, when the application result includes two fields, the first field is used to indicate whether the application is successful, and the second field is used for the type of failure, indicating that the code of the second field is read and based on the code of the second field The memory application result can be determined.

例如,申请结果为“01,001”,则读取第二字段的内容“001”,并根据预先确定的该编码对应的含义可知,失败类型为系统可用内存过少。又例如,申请结果为“01,010”,则读取到第二字段的内容为“010”,根据预先确定的编码对应的含义可知,失败类型为内存映射失败。For example, if the application result is "01,001", read the content "001" in the second field, and according to the predetermined meaning corresponding to the code, it can be known that the failure type is too little available memory in the system. For another example, if the application result is "01,010", the read content of the second field is "010". According to the meaning corresponding to the predetermined code, the failure type is a memory mapping failure.

又示例性的,当申请结果只包含一个字段,其中该字段的第2位至第4位用于表示失败类型,则读取第二位至第四位的编码,基于第二位至第四位的编码确定内存申请的申请结果。As another example, when the application result only contains one field, where the 2nd to 4th digits of the field are used to indicate the type of failure, then read the codes of the 2nd to 4th digits, based on the second to 4th digits The encoding of the bit determines the application result of the memory application.

例如,申请结果为“1001”,则读取第2位至第四位的编码“001”,并根据预先确定的该编码对应的含义可知,失败类型为系统可用内存过少。又例如,申请结果为“1010”,则读取第2位至第4位的编码“010”,根据预先确定的该编码对应的含义可知,失败类型为内存映射失败。For example, if the application result is "1001", read the code "001" from the second to the fourth digit, and according to the predetermined meaning corresponding to the code, it can be known that the failure type is too little available memory in the system. For another example, if the application result is "1010", read the code "010" from the 2nd to 4th digits. According to the predetermined meaning corresponding to the code, it can be known that the failure type is memory mapping failure.

又例如当申请结果返回为error并附带错误码时,可以通过错误码来确定失败类型。For another example, when the application result is returned as an error with an error code, the failure type can be determined through the error code.

由于失败类型不为内存映射失败,那么基本不会造成内存泄漏的情况,因此无需对应用程序进行任何操作,只需要输出与该失败类型对应的异常日志即可。Since the failure type is not a memory mapping failure, it will basically not cause a memory leak, so there is no need to perform any operations on the application, and only need to output the exception log corresponding to the failure type.

在一些实施例中,上述异常日志可以包括申请发起的进程名称、异常发生的时间和异常的内容等,异常的内容即包括申请图形缓冲区失败以及失败类型。示例性的,当失败类型为系统可用内存过少时,上述异常内容可以是A应用的B进程于xx时间由于系统内存过少申请图形缓冲区失败。In some embodiments, the above-mentioned exception log may include the name of the process initiated by the application, the time when the exception occurred, and the content of the exception. The content of the exception includes the failure to apply for the graphics buffer and the type of failure. Exemplarily, when the failure type is too little available memory in the system, the above abnormal content may be that process B of application A fails to apply for a graphics buffer at time xx due to too little system memory.

在一些实施例中,当失败类型是系统内存过少时,基于该异常日志,电子设备可以启动LMK机制。In some embodiments, when the failure type is too little system memory, based on the exception log, the electronic device can start the LMK mechanism.

在一些实施例中,上述异常日志可以保存在日志管理器中,电子设备可以通过日志管理器来读取该异常日志。In some embodiments, the above exception log may be stored in a log manager, and the electronic device may read the exception log through the log manager.

在第一方面的一种可能的实现方式中,上述应用程序的管理方法还包括:若应用程序占用的虚拟内存未超过预设阈值,则输出内存映射失败且虚拟内存未超过阈值的异常日志。In a possible implementation manner of the first aspect, the above application management method further includes: if the virtual memory occupied by the application does not exceed a preset threshold, outputting an exception log indicating that memory mapping fails and the virtual memory does not exceed the threshold.

由于应用程序占用的虚拟内存未超过预设阈值,也就是说,这不会导致内存泄漏,因此无需对应用程序进行任何操作,只需要输出内存映射失败且虚拟内存未超过阈值的异常日志。Since the virtual memory occupied by the application does not exceed the preset threshold, that is, it will not cause a memory leak, so there is no need to perform any operations on the application, only the exception log that the memory mapping fails and the virtual memory does not exceed the threshold needs to be output.

在第一方面的一种可能的实现方式中,上述应用程序的管理方法还包括:在结束所述应用程序的全部进程后,输出由于虚拟内存占用过高,结束所述应用程序的运行的异常日志。In a possible implementation manner of the first aspect, the above-mentioned application management method further includes: after ending all processes of the application, outputting an exception indicating that the operation of the application is terminated because the virtual memory usage is too high log.

以异常日志的形式记录由于虚拟内存占用过高,结束所述应用程序的运行的异常情况,便于用户查看。The abnormal situation of ending the operation of the application program due to excessive virtual memory usage is recorded in the form of an exception log, which is convenient for the user to view.

第二方面,本申请实施例提供一种电子设备,包括:In a second aspect, an embodiment of the present application provides an electronic device, including:

监测模块,用于在应用程序运行过程中,监测图形缓冲区的申请结果;The monitoring module is used to monitor the application result of the graphics buffer during the running of the application program;

分析模块,用于若图像缓冲区的申请结果为申请失败,则根据申请结果分析失败类型;The analysis module is used to analyze the failure type according to the application result if the application result of the image buffer is application failure;

获取模块,用于若失败类型为内存映射失败,则获取应用程序的虚拟内存占用情况;The obtaining module is used to obtain the virtual memory usage of the application if the failure type is a memory mapping failure;

自杀恢复模块,用于若应用程序占用的虚拟内存超过预设阈值,则启动所述应用程序的自杀恢复功能。The suicide recovery module is configured to start the suicide recovery function of the application program if the virtual memory occupied by the application program exceeds a preset threshold.

第三方面,本申请实施例提供一种电子设备,包括存储器、处理器以及存储在存储器中并可在处理器上运行的计算机程序,处理器执行计算机程序时实现如上述第一方面任一项的方法。In the third aspect, the embodiment of the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and operable on the processor. When the processor executes the computer program, any one of the above-mentioned first aspects can be realized. Methods.

第四方面,本申请实施例提供一种计算机可读存储介质,计算机可读存储介质存储有计算机程序,计算机程序被处理器执行时实现如上述第一方面任一项的方法。In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, where a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, the method according to any one of the above-mentioned first aspects is implemented.

第五方面,本申请实施例提供一种芯片系统,该芯片系统包括处理器,处理器与存储器耦合,处理器执行存储器中存储的计算机程序,以实现如上述第一方面任一项所述的方法。该芯片系统可以为单个芯片,或者多个芯片组成的芯片模组。In the fifth aspect, the embodiment of the present application provides a chip system, the chip system includes a processor, the processor is coupled with the memory, and the processor executes the computer program stored in the memory, so as to realize the above-mentioned any one of the first aspect. method. The chip system can be a single chip, or a chip module composed of multiple chips.

第六方面,本申请实施例提供一种计算机程序产品,当计算机程序产品在电子设备上运行时,使得电子设备执行上述第一方面任一项所述的方法。In a sixth aspect, an embodiment of the present application provides a computer program product, which, when the computer program product is run on an electronic device, causes the electronic device to execute the method described in any one of the above-mentioned first aspects.

可以理解的是,上述第二方面至第六方面的有益效果可以参见上述第一方面中的相关描述,在此不再赘述。It can be understood that, for the beneficial effects of the above-mentioned second aspect to the sixth aspect, reference can be made to the related description in the above-mentioned first aspect, which will not be repeated here.

附图说明Description of drawings

图1是本申请实施例提供的内存泄漏导致应用程序显示异常的示例性示意图。FIG. 1 is an exemplary schematic diagram of an abnormal display of an application program caused by a memory leak provided by an embodiment of the present application.

图2是本申请实施例提供的一种手机的硬件结构示意图。FIG. 2 is a schematic diagram of a hardware structure of a mobile phone provided by an embodiment of the present application.

图3是本申请实施例提供的一种手机的软件系统架构的示意图。FIG. 3 is a schematic diagram of a software system architecture of a mobile phone provided by an embodiment of the present application.

图4是本申请实施例提供的一些应用场景下的图形用户界面的示意图。Fig. 4 is a schematic diagram of a graphical user interface in some application scenarios provided by an embodiment of the present application.

图5是本申请实施例提供的一些开启内存申请监测功能过程中的图形用户界面的示意图。FIG. 5 is a schematic diagram of some graphical user interfaces during the process of enabling the memory application monitoring function provided by the embodiment of the present application.

图6是本申请实施例提供的一种应用程序管理方法的实现流程示意图。FIG. 6 is a schematic diagram of an implementation flow of an application program management method provided by an embodiment of the present application.

图7是本申请实施例提供的另一种应用程序管理方法的实现流程示意图。FIG. 7 is a schematic diagram of an implementation flow of another application program management method provided by the embodiment of the present application.

具体实施方式detailed description

需要说明的是,本申请实施例的实施方式部分使用的术语仅用于对本申请的具体实施例进行解释,而非旨在限定本申请。在本申请实施例的描述中,除非另有说明,“/”表示或的意思,例如,A/B可以表示A或B;本文中的“和/或”仅仅是一种描述关联物的关联关系,表示可以存在三种关系,例如,A和/或B,可以表示:单独存在A,同时存在A和B,单独存在B这三种情况。另外,在本申请实施例的描述中,除非另有说明,“多个”是指两个或多于两个,“至少一个”、“一个或多个”是指一个、两个或两个以上。It should be noted that the terms used in the implementation manners of the embodiments of the present application are only used to explain the specific embodiments of the present application, and are not intended to limit the present application. In the description of the embodiments of the present application, unless otherwise specified, "/" means or means, for example, A/B can mean A or B; "and/or" in this article is only a description of associations A relationship means that there may be three kinds of relationships, for example, A and/or B means: A exists alone, A and B exist simultaneously, and B exists alone. In addition, in the description of the embodiments of the present application, unless otherwise specified, "plurality" means two or more than two, "at least one", "one or more" means one, two or two above.

以下,术语“第一”、“第二”仅用于描述目的,而不能理解为指示或暗示相对重要性或者隐含指明所指示的技术特征的数量。由此,限定有“第一”、“第二”特征可以明示或者隐含地包括一个或者更多个该特征。Hereinafter, the terms "first" and "second" are used for descriptive purposes only, and cannot be understood as indicating or implying relative importance or implicitly specifying the quantity of indicated technical features. Thus, the definition of "first" and "second" features may expressly or implicitly include one or more of these features.

在本说明书中描述的参考“一个实施例”或“一些实施例”等意味着在本申请的一个或多个实施例中包括结合该实施例描述的特定特征、结构或特点。由此,在本说明书中的不同之处出现的语句“在一个实施例中”、“在一些实施例中”、“在其他一些实施例中”、“在另外一些实施例中”等不是必然都参考相同的实施例,而是意味着“一个或多个但不是所有的实施例”,除非是以其他方式另外特别强调。术语“包括”、“包含”、“具有”及它们的变形都意味着“包括但不限于”,除非是以其他方式另外特别强调。Reference to "one embodiment" or "some embodiments" or the like in this specification means that a particular feature, structure, or characteristic described in connection with the embodiment is included in one or more embodiments of the present application. Thus, appearances of the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in other embodiments," etc. in various places in this specification are not necessarily All refer to the same embodiment, but mean "one or more but not all embodiments" unless specifically stated otherwise. The terms "including", "comprising", "having" and variations thereof mean "including but not limited to", unless specifically stated otherwise.

为更好地理解本申请实施例,以下对实施例中可能涉及的术语或概念进行介绍。In order to better understand the embodiments of the present application, terms or concepts that may be involved in the embodiments are introduced below.

1.图形缓冲区(graphicbuffer)1. Graphics buffer (graphicbuffer)

用于应用程序的界面的显示绘制和保存显示绘制的数据。应用程序在运行过程中,需要先申请用于界面的显示绘制和保存显示绘制数据的图形缓冲区,具体的图形缓冲区可以从系统内存中分配,从系统内存中分配图形缓冲区后还需要将该图形缓冲区映射到该应用程序对应的虚拟内存的地址空间中,这样应用程序才可以正常运行。对于多进程的应用程序,每个进程在运行时都会先申请图形缓冲区,同样的,图形缓冲区申请成功后(即系统存在足够的内存分配给该进程使用),需要将该图形缓冲区映射到该进程对应的虚拟内存的地址空间中,使得该进程可以正常运行。It is used for display drawing of the interface of the application program and saves display drawing data. When the application is running, it needs to first apply for the graphics buffer for displaying the interface and saving the displaying data. The specific graphics buffer can be allocated from the system memory. After allocating the graphics buffer from the system memory, it needs to be allocated The graphics buffer is mapped to the address space of the virtual memory corresponding to the application program, so that the application program can run normally. For multi-process applications, each process will first apply for a graphics buffer when it is running. Similarly, after the graphics buffer application is successful (that is, the system has enough memory allocated to the process), the graphics buffer needs to be mapped to the address space of the virtual memory corresponding to the process, so that the process can run normally.

2.垃圾回收(garbage collection,GC)机制2. Garbage collection (GC) mechanism

将不使用的对象进行清除和回收,以释放内存的一种机制。在应用程序卡顿,响应速度慢的时候(此时内存占用过高。示例性的,对于32位应用程序来说,内存占用超过3G就会被判定为内存占用过高),虚拟机会触发垃圾回收(GC)机制。A mechanism to clear and recycle unused objects to release memory. When the application freezes and the response speed is slow (the memory usage is too high at this time. For example, for a 32-bit application, if the memory usage exceeds 3G, it will be judged as too high), the virtual machine will trigger garbage Recycling (GC) mechanism.

3.低内存查杀(low memory killer,LMK)机制3. Low memory killer (LMK) mechanism

一种Android系统的内存清理机制,系统定时检测应用程序的内存使用情况,在系统可用内存低时,触发LMK机制通过后台将优先级低的进程杀掉,以释放内存。具体地,通过进程的oom_adj值来判断进程的优先级,oom_adj值越小,则优先级越高,在触发LMK机制时该进程被杀掉的可能性越小。需要说明的是,前台进程的oom_adj值为0,即前台进程的优先级最高。A memory cleaning mechanism of the Android system. The system regularly detects the memory usage of the application program. When the available memory of the system is low, the LMK mechanism is triggered to kill the low-priority process through the background to release the memory. Specifically, the priority of a process is judged by the oom_adj value of the process. The smaller the oom_adj value, the higher the priority, and the less likely the process will be killed when the LMK mechanism is triggered. It should be noted that the oom_adj value of the foreground process is 0, that is, the priority of the foreground process is the highest.

4.虚拟内存(virtual set size,VSS)4. Virtual memory (virtual set size, VSS)

一个进程能访问的所有内存空间地址的大小。理论上,对于32位应用程序而言,最多能使用的虚拟内存为232,即4G。而实际应用中,系统会预留占用一小部分,因此一个对于32位应用程序而言,最多能使用的虚拟内存为3.7G,超过3.7G就会造成内存溢出。The size of all memory space addresses that a process can access. Theoretically, for 32-bit applications, the maximum virtual memory that can be used is 2 32 , that is, 4G. In actual application, the system will reserve a small part, so for a 32-bit application, the maximum virtual memory that can be used is 3.7G, and if it exceeds 3.7G, it will cause memory overflow.

5.内存溢出(out of memory,OOM)5. Memory overflow (out of memory, OOM)

系统中存在无法回收的内存或使用的内存过多,最终使得应用程序运行要用到的内存大于能提供的最大内存的现象,内存溢出的表现为应用程序的界面显示异常或应用程序闪退。There is unrecoverable memory or too much memory in the system, which eventually causes the memory used by the application to run larger than the maximum memory that can be provided. The memory overflow is manifested as an abnormal display of the application interface or a crash of the application.

在软件系统中,由于图片、对象、线程、文件、视图等资源的不当使用,使得资源没有及时释放,就会导致内存泄露,进而引发应用程序内存溢出,导致应用程序卡死,甚至系统卡死的情况。内存泄露大部分情况下都是一个积累的过程,在出现问题之前不会有征兆,因此很难被发现和定位。In a software system, due to the improper use of resources such as pictures, objects, threads, files, and views, the resources are not released in time, which will lead to memory leaks, which in turn will cause memory overflow of the application, causing the application to freeze, and even the system to freeze. Case. In most cases, memory leaks are a cumulative process, and there will be no symptoms before problems occur, so it is difficult to find and locate them.

实际应用中,内存泄露会导致以下情况:In practical applications, memory leaks can lead to the following situations:

1.应用程序卡顿、响应速度慢,触发垃圾回收机制,导致应用程序无反应(application not responding,ANR)或应用程序闪退。1. The application freezes and responds slowly, triggering the garbage collection mechanism, resulting in application not responding (ANR) or application flashback.

2.导致应用程序显示异常,应用程序的部分功能不可用等异常。2. Cause abnormal display of the application, unavailability of some functions of the application and other abnormalities.

示例性的,图1中的(a)为没有出现内存泄露时,应用程序A正常显示时的显示界面的示意图,如图1中的(b)所示,上述应用程序A发生内存泄露时出现的显示异常可以表现为出现乱码的情况;又例如图1中的(c)所示,上述应用程序A发生内存泄露时出现的显示异常可以表现为显示不完整的情况;又例如图1中的(d)所示,上述应用程序A发生内存泄露时出现的显示异常可以表现为部分功能无显示的情况,此时该部分功能就处于不可用的异常状态。Exemplarily, (a) in FIG. 1 is a schematic diagram of a display interface when application A is normally displayed when there is no memory leak. As shown in (b) in FIG. The abnormal display can be manifested as garbled characters; as shown in (c) in Figure 1, the abnormal display that occurs when the memory leak occurs in the above-mentioned application program A can be manifested as incomplete display; another example in Figure 1 As shown in (d), the display abnormality that occurs when the memory leak occurs in the above-mentioned application program A may be manifested as a situation where some functions are not displayed, and at this time, the part of the functions is in an abnormal state of being unavailable.

3.系统崩溃、卡死等异常。3. Abnormalities such as system crashes and freezes.

示例性的,当用户使用手机观看视频时,由于视频播放应用程序在播放视频的过程中,会持续申请内存且不释放,由于视频播放应用程序的最多能使用的虚拟内存是一定的,因此在达到该视频播放应用程序的虚拟内存的使用上限后,就无法将申请到的内存映射到该视频播放应用程序的虚拟内存中。与此同时,系统分配的内存会被标记为已使用,无法再分配给其他应用程序(进程)使用,而内存映射失败会导致应用程序继续向系统申请内存,由此导致内存泄露。而由于系统的可用内存低,因此会触发LMK机制,但是由于视频播放应用程序还在前台运行,因此其优先级较高,故该视频播放应用程序不会被杀进程,因此占用的内存也不会被释放,最终就会导致整个系统崩溃,卡死的异常情况。系统崩溃,卡死的时候需要用户强制重启手机才能恢复正常的使用,操作麻烦且会影响用户体验。Exemplarily, when a user uses a mobile phone to watch a video, since the video playback application will continue to apply for memory and not release it during the video playback process, since the maximum available virtual memory of the video playback application is certain, so in After the usage limit of the virtual memory of the video playing application is reached, the requested memory cannot be mapped to the virtual memory of the video playing application. At the same time, the memory allocated by the system will be marked as used and cannot be allocated to other applications (processes), and memory mapping failure will cause the application to continue to apply for memory from the system, resulting in memory leaks. And because the available memory of the system is low, the LMK mechanism will be triggered, but because the video playback application is still running in the foreground, its priority is higher, so the video playback application will not be killed, so the occupied memory will not It will be released, which will eventually cause the entire system to crash and be stuck in an abnormal situation. When the system crashes and freezes, the user needs to force restart the mobile phone to restore normal use, which is troublesome to operate and will affect the user experience.

在实际应用中,很多应用程序都是32位的应用程序,而在向系统申请系统内存时应用程序会通过不断调用graphicbufferallocator进程接口来申请内存。32位应用程序所能用的最大虚拟内存是4G,然而由于graphicbufferallocator进程是64位进程,在应用程序的虚拟内存超过4G时,还可以成功向系统申请到系统内存,而由于应用程序的虚拟内存已经超过4G了,因此无法将申请到的内存映射到虚拟内存中,导致该系统内存被申请但无法被使用,也无法被释放。而且在内存映射失败后,应用程序还会继续通过调用graphicbufferallocator接口申请内存,导致内存持续泄露,最终导致系统崩溃、卡死的异常情况。In practical applications, many applications are 32-bit applications, and when applying for system memory from the system, the application will apply for memory by continuously calling the graphicbufferallocator process interface. The maximum virtual memory that a 32-bit application can use is 4G. However, since the graphicbufferallocator process is a 64-bit process, when the virtual memory of the application exceeds 4G, it can still successfully apply for system memory from the system, and because the virtual memory of the application It has exceeded 4G, so the requested memory cannot be mapped to virtual memory, resulting in the system memory being requested but unable to be used, nor released. Moreover, after the memory mapping fails, the application will continue to apply for memory by calling the graphicbufferallocator interface, resulting in continuous memory leaks, which eventually lead to abnormal situations such as system crashes and freezing.

由以上说明可知,内存泄露一旦爆发问题,引发的情况是各种各样的,而且不易重现,也就是说内存泄露这个问题不好发现和解决,且内存泄露还会严重影响用户的使用。因而,如果能够在内存泄露导致异常情况的发生之前,先对可能导致内存泄露的应用程序进行处理,就能够避免出现系统崩溃、卡死等严重异常,减轻对用户使用的影响。From the above description, we can see that once a memory leak breaks out, it will cause a variety of situations, and it is not easy to reproduce. That is to say, the problem of memory leak is difficult to find and solve, and the memory leak will seriously affect the use of users. Therefore, if the application programs that may cause memory leaks can be processed before the memory leaks cause abnormal situations, serious abnormalities such as system crashes and freezes can be avoided, and the impact on users can be reduced.

针对上述问题以及用户需求,本申请实施例提供了一种应用程序的管理方法,通过监测应用程序的进程向系统内存申请图形缓冲区的情况,在内存申请失败且是由于虚拟内存占用过多的情况下,启动自杀恢复功能,结束该应用程序的所有进程,以释放被该应用程序占用的内存,避免由于内存泄露导致系统崩溃、卡死等严重后果,减轻对用户使用的影响。In view of the above-mentioned problems and user needs, the embodiment of the present application provides a management method of an application program. By monitoring the process of the application program to apply for a graphics buffer to the system memory, when the memory application fails and the virtual memory takes up too much In this case, activate the suicide recovery function to end all processes of the application to release the memory occupied by the application, avoid serious consequences such as system crashes and freezes caused by memory leaks, and reduce the impact on users.

下面将结合附图对本申请实施例提供的应用程序的管理方法进行详细阐述,以下描述中,为了说明而不是为了限定,提出了诸如特定系统结构、技术之类的具体细节,以便透彻理解本申请实施例。The application management method provided by the embodiment of the application will be described in detail below in conjunction with the accompanying drawings. In the following description, for the purpose of illustration rather than limitation, specific details such as specific system structure and technology are proposed in order to thoroughly understand the application Example.

上述应用程序的管理方法的执行主体可以是电子设备,例如可以是手机、可穿戴设备(如智能手表、智能手环、智能眼镜、智能首饰等)、平板电脑、车载设备、增强现实(augmented reality,AR)/虚拟现实(virtual reality,VR)设备、笔记本电脑、超级移动个人计算机(ultra-mobile personal computer,UMPC)、上网本、个人数字助理(personaldigital assistant,PDA)以及其他具有网络连接功能的电子设备。The execution subject of the above-mentioned application management method may be an electronic device, such as a mobile phone, a wearable device (such as a smart watch, a smart bracelet, smart glasses, smart jewelry, etc.), a tablet computer, a vehicle-mounted device, an augmented reality (augmented reality , AR)/virtual reality (virtual reality, VR) devices, laptops, ultra-mobile personal computers (UMPCs), netbooks, personal digital assistants (personal digital assistants, PDAs), and other electronic devices with network connectivity equipment.

上述电子设备的示例性实施例包括但不限于搭载

Figure BDA0003288920180000061
鸿蒙系统(Harmony OS)或者其他操作系统的设备。上述电子设备也可以是其他电子设备,诸如具有触敏表面(例如触控面板)的膝上型计算机(laptop)等,本申请实施例对电子设备的具体类型不做任何限制。Exemplary embodiments of the aforementioned electronic devices include, but are not limited to
Figure BDA0003288920180000061
Devices with Harmony OS or other operating systems. The foregoing electronic device may also be other electronic devices, such as a laptop computer (laptop) with a touch-sensitive surface (eg, a touch panel), and the embodiment of the present application does not impose any limitation on the specific type of the electronic device.

以上述电子设备为手机为例,如图2所示,为本申请实施例提供的一种手机的结构示意图。Taking the above-mentioned electronic device as a mobile phone as an example, as shown in FIG. 2 , it is a schematic structural diagram of a mobile phone provided in an embodiment of the present application.

图2示出了手机100的结构示意图。手机100可以包括处理器110,外部存储器接口120,内部存储器121,通用串行总线(universal serial bus,USB)接口130,充电管理模块140,电源管理模块141,电池142,天线11,天线12,移动通信模块150,无线通信模块160,音频模块170,传感器模块180,按键190,马达191,指示器192,摄像头193,显示屏194,以及用户标识模块(subscriber identification module,SIM)卡接口195等。其中传感器模块180可以包括压力传感器180A,陀螺仪传感器180B,气压传感器180C,磁传感器180D,加速度传感器180E,距离传感器180F,接近光传感器180G,指纹传感器180H,温度传感器180J,触摸传感器180K,环境光传感器180L,骨传导传感器180M等。FIG. 2 shows a schematic structural diagram of the mobile phone 100 . The mobile phone 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (universal serial bus, USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 11, an antenna 12, Mobile communication module 150, wireless communication module 160, audio module 170, sensor module 180, button 190, motor 191, indicator 192, camera 193, display screen 194, and subscriber identification module (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, bone conduction sensor 180M, etc.

可以理解的是,本发明实施例示意的结构并不构成对手机100的具体限定。在本申请另一些实施例中,手机100可以包括比图示更多或更少的部件,或者组合某些部件,或者拆分某些部件,或者不同的部件布置。图示的部件可以以硬件,软件或软件和硬件的组合实现。It can be understood that, the structure shown in the embodiment of the present invention does not constitute a specific limitation on the mobile phone 100 . In some other embodiments of the present application, the mobile phone 100 may include more or fewer components than shown in the figure, or combine certain components, or separate certain components, or arrange different components. The illustrated components can be realized in hardware, software or a combination of software and hardware.

处理器110可以包括一个或多个处理单元,例如:处理器110可以包括应用处理器(application processor,AP),调制解调处理器,图形处理器(graphics processingunit,GPU),图像信号处理器(image signal processor,ISP),控制器,存储器,视频编解码器,数字信号处理器(digital signal processor,DSP),基带处理器,和/或神经网络处理器(neural-network processing unit,NPU)等。其中,不同的处理单元可以是独立的器件,也可以集成在一个或多个处理器中。The processor 110 may include one or more processing units, for example: the processor 110 may include an application processor (application processor, AP), a modem processor, a graphics processing unit (graphics processing unit, GPU), an image signal processor ( image signal processor, ISP), controller, memory, video codec, digital signal processor (digital signal processor, DSP), baseband processor, and/or neural network processor (neural-network processing unit, NPU), etc. . Wherein, different processing units may be independent devices, or may be integrated in one or more processors.

其中,控制器可以是手机100的神经中枢和指挥中心。控制器可以根据指令操作码和时序信号,产生操作控制信号,完成取指令和执行指令的控制。Wherein, the controller may be the nerve center and command center of the mobile phone 100 . The controller can generate an operation control signal according to the instruction opcode and timing signal, and complete the control of fetching and executing the instruction.

处理器110中还可以设置存储器,用于存储指令和数据。在一些实施例中,处理器110中的存储器为高速缓冲存储器。该存储器可以保存处理器110刚用过或循环使用的指令或数据。如果处理器110需要再次使用该指令或数据,可从所述存储器中直接调用。避免了重复存取,减少了处理器110的等待时间,因而提高了系统的效率。A memory may also be provided in the processor 110 for storing instructions and data. In some embodiments, the memory in processor 110 is a cache memory. The memory may hold instructions or data that the processor 110 has just used or recycled. If the processor 110 needs to use the instruction or data again, it can be called directly from the memory. Repeated access is avoided, and the waiting time of the processor 110 is reduced, thereby improving the efficiency of the system.

示例性的,手机100的软件系统可以采用分层架构,事件驱动架构,微核架构,微服务架构,或云架构。本发明实施例以分层架构的Android系统为例,示例性说明手机100的软件结构。图3是本申请实施例的手机100的软件结构框图。Exemplarily, the software system of the mobile phone 100 may adopt a layered architecture, an event-driven architecture, a micro-kernel architecture, a micro-service architecture, or a cloud architecture. In the embodiment of the present invention, the software structure of the mobile phone 100 is illustrated by taking the Android system with a layered architecture as an example. FIG. 3 is a block diagram of the software structure of the mobile phone 100 according to the embodiment of the present application.

分层架构将软件分成若干个层,每一层都有清晰的角色和分工。层与层之间通过软件接口通信。在一些实施例中,将Android系统分为四层,从上至下分别为应用程序层,应用程序框架层,安卓运行时(Android runtime)和系统库,以及内核层。The layered architecture divides the software into several layers, and each layer has a clear role and division of labor. Layers communicate through software interfaces. In some embodiments, the Android system is divided into four layers, which are, from top to bottom, the application program layer, the application program framework layer, the Android runtime (Android runtime) and the system library, and the kernel layer.

应用程序层可以包括一系列应用程序包。如图3所示,应用程序包可以包括相机,图库,日历,通话,地图,导航,WLAN,蓝牙,视频,即时聊天等应用程序。The application layer can consist of a series of application packages. As shown in Figure 3, the application package can include applications such as camera, gallery, calendar, call, map, navigation, WLAN, bluetooth, video, and instant chat.

应用程序框架层为应用程序层的应用程序提供应用编程接口(applicationprogramming interface,API)和编程框架。应用程序框架层包括一些预先定义的函数。如图3所示,应用程序框架层可以包括窗口管理器,内容提供器,视图系统,进程管理器,通知管理器、自杀恢复管理模块等。The application framework layer provides an application programming interface (application programming interface, API) and a programming framework for applications in the application layer. The application framework layer includes some predefined functions. As shown in Figure 3, the application framework layer may include a window manager, a content provider, a view system, a process manager, a notification manager, a suicide recovery management module, and the like.

窗口管理器用于管理窗口程序。窗口管理器可以获取显示屏大小,判断是否有状态栏,锁定屏幕,截取屏幕等。A window manager is used to manage window programs. The window manager can get the size of the display screen, determine whether there is a status bar, lock the screen, capture the screen, etc.

内容提供器用来存放和获取数据,并使这些数据可以被应用程序访问。所述数据可以包括视频,图像,音频,拨打和接听的电话,浏览历史和书签,电话簿等。Content providers are used to store and retrieve data and make it accessible to applications. Said data may include video, images, audio, calls made and received, browsing history and bookmarks, phonebook, etc.

视图系统包括可视控件,例如显示文字的控件,显示图片的控件等。视图系统可用于构建应用程序。显示界面可以由一个或多个视图组成的。例如,包括短信通知图标的显示界面,可以包括显示文字的视图以及显示图片的视图。The view system includes visual controls, such as controls for displaying text, controls for displaying pictures, and so on. The view system can be used to build applications. A display interface can consist of one or more views. For example, a display interface including a text message notification icon may include a view for displaying text and a view for displaying pictures.

资源管理器为应用程序提供各种资源,比如本地化字符串,图标,图片,布局文件,视频文件等等。The resource manager provides various resources for the application, such as localized strings, icons, pictures, layout files, video files, and so on.

通知管理器使应用程序可以在状态栏中显示通知信息,可以用于传达告知类型的消息,可以短暂停留后自动消失,无需用户交互。比如通知管理器被用于告知下载完成,消息提醒等。通知管理器还可以是以图表或者滚动条文本形式出现在系统顶部状态栏的通知,例如后台运行的应用程序的通知,还可以是以对话窗口形式出现在屏幕上的通知。例如在状态栏提示文本信息,发出提示音,终端振动,指示灯闪烁等。The notification manager enables the application to display notification information in the status bar, which can be used to convey notification-type messages, and can automatically disappear after a short stay without user interaction. For example, the notification manager is used to notify the download completion, message reminder, etc. The notification manager can also be a notification that appears on the top status bar of the system in the form of a chart or scroll bar text, such as a notification of an application running in the background, or a notification that appears on the screen in the form of a dialog window. For example, prompting text information in the status bar, emitting a prompt sound, terminal vibration, and indicator light flashing, etc.

自杀恢复管理模块是在检测到运行的应用程序满足本申请实施例提到的自杀恢复条件时,启动对应用程序的自动查杀,以释放内存的应用程序管理机制。The suicide recovery management module is an application program management mechanism that automatically scans and kills the application program to release the memory when it detects that the running application program satisfies the suicide recovery condition mentioned in the embodiment of the present application.

在本申请实施例中,上述自杀恢复条件可以是内存申请失败,失败类型为虚拟内存映射失败,且该应用程序占用的虚拟内存超过预设阈值。In the embodiment of the present application, the above suicide recovery condition may be memory application failure, the failure type is virtual memory mapping failure, and the virtual memory occupied by the application exceeds a preset threshold.

在本申请实施例中,上述对应用程序的自动查杀可以是直接结束该应用程序的所有进程,此时,手机100的显示界面会直接跳到显示手机100的主屏幕界面,即用户感受到该应用程序闪退;上述对应用程序的自动查杀也可以是在结束该应用程序的所有进程后自动拉起该应用程序的主进程,此时手机100的显示界面会直接跳到该应用程序的主显示界面。由于结束应用程序的进程后再次拉起该应用程序的主进程的间隔时间很短,因此用户对此无感知,只能感受到手机100的显示界面又跳回该应用程序的主显示界面。In the embodiment of the present application, the above-mentioned automatic killing of the application program may directly end all processes of the application program. At this time, the display interface of the mobile phone 100 will directly jump to the main screen interface showing the mobile phone 100, that is, the user feels The application program flashes back; the above-mentioned automatic killing of the application program can also be to automatically pull up the main process of the application program after ending all processes of the application program. At this time, the display interface of the mobile phone 100 will directly jump to the application program main display interface. Since the interval time for pulling up the main process of the application program after the process of the application program is terminated is very short, the user has no perception of this, and can only feel that the display interface of the mobile phone 100 jumps back to the main display interface of the application program.

在本申请一些实施例中,自杀恢复管理模块还具备内存申请监测功能,能够在应用程序向系统内存发出内存申请时,自动启用内存申请监测功能,以监测该内存申请是否成功。In some embodiments of the present application, the suicide recovery management module also has a memory application monitoring function, which can automatically enable the memory application monitoring function when an application program sends a memory application to the system memory, so as to monitor whether the memory application is successful.

Android Runtime包括核心库和虚拟机。Android runtime负责安卓系统的调度和管理。Android Runtime includes core library and virtual machine. The Android runtime is responsible for the scheduling and management of the Android system.

核心库包含两部分:一部分是java语言需要调用的功能函数,另一部分是安卓的核心库。The core library consists of two parts: one part is the function function that the java language needs to call, and the other part is the core library of Android.

应用程序层和应用程序框架层运行在虚拟机中。虚拟机将应用程序层和应用程序框架层的java文件执行为二进制文件。虚拟机用于执行目标生命周期的管理,堆栈管理,线程管理,安全和异常的管理,以及垃圾回收等功能。The application layer and the application framework layer run in virtual machines. The virtual machine executes the java files of the application program layer and the application program framework layer as binary files. The virtual machine is used to perform functions such as target life cycle management, stack management, thread management, security and exception management, and garbage collection.

系统库可以包括多个功能模块。例如:表面管理器(surface manager),媒体库(Media Libraries),三维图形处理库(例如:OpenGL ES),2D图形引擎(例如:SGL)等。A system library can include multiple function modules. For example: surface manager (surface manager), media library (Media Libraries), 3D graphics processing library (eg: OpenGL ES), 2D graphics engine (eg: SGL), etc.

内核层是硬件和软件之间的层。内核层至少包含显示驱动,摄像头驱动,音频驱动,传感器驱动。The kernel layer is the layer between hardware and software. The kernel layer includes at least a display driver, a camera driver, an audio driver, and a sensor driver.

本申请实施例提供的应用程序的管理方法可以运行在应用程序框架层,即可以通过应用程序框架层中的自杀恢复管理模块来实现上述应用程序的管理方法。The application program management method provided by the embodiment of the present application can run in the application program framework layer, that is, the above application program management method can be implemented through the suicide recovery management module in the application program framework layer.

本申请实施例提供的应用程序的管理方法,可以适用于多种存在内存泄露的使用场景中。举例来说,本申请实施例提供的应用程序的管理方法能够应用在用户使用电子设备观看视频或者使用即时聊天软件查看推送文章等场景中。The application program management method provided by the embodiment of the present application can be applied to various usage scenarios where memory leaks exist. For example, the application management method provided by the embodiment of the present application can be applied to scenarios where a user watches a video using an electronic device or uses an instant chat software to view pushed articles.

例如,在用户使用即时聊天软件查看推送文章(可以是新闻推送的文章/视频等)时,应用程序的进程会向系统内存申请图形缓冲区,用于界面的显示绘制和保存显示绘制的数据。在应用程序的进程向系统内存发起图形缓冲区申请时,手机启动内存申请监测功能,并在监测到即时聊天软件满足自杀恢复条件时(此时图形缓冲区申请失败,失败类型为虚拟内存映射失败,且应用程序占用的虚拟内存超过预设阈值),启动自杀恢复,以使该应用程序释放内存,避免导致整个手机系统崩溃卡死的情况。For example, when a user uses an instant chat software to view a push article (it may be a news push article/video, etc.), the process of the application program will apply for a graphics buffer from the system memory for the display drawing of the interface and the storage of display drawing data. When the application process initiates a graphics buffer application to the system memory, the mobile phone starts the memory application monitoring function, and when it detects that the instant chat software meets the suicide recovery conditions (at this time, the graphics buffer application fails, and the failure type is virtual memory mapping failure. , and the virtual memory occupied by the application exceeds the preset threshold), start suicide recovery, so that the application can release memory, and avoid the situation that causes the entire mobile phone system to crash and freeze.

示例性的,如图4所示,为应用场景一中可能涉及的一些图形用户界面(graphicaluser interface,GUI)示意图。Exemplarily, as shown in FIG. 4 , it is a schematic diagram of some graphical user interfaces (graphical user interface, GUI) that may be involved in the first application scenario.

在一些实施例中,该即时聊天软件的界面包括主显示区域10(“信息”对应的界面),其他功能区域20(例如图4中的(a)中“通讯录”、“动态”等),子对话30。主显示区域10会显示多个子对话30,具体地,可以如图4中的(a)中的形式进行显示。用户要查看某一个子对话推送的文章时,可以通过点击该子对话对应的控件(例如联系人1的子对话),使得即时聊天软件的显示界面跳转到该子对话对应的显示界面(如图4中的(b)所示)。In some embodiments, the interface of the instant chat software includes a main display area 10 (the interface corresponding to "information"), and other functional areas 20 (such as "contacts", "dynamics" and the like in (a) of Figure 4 ) , subdialog 30. The main display area 10 will display a plurality of sub-dialogues 30, specifically, it may be displayed in the form of (a) in FIG. 4 . When the user wants to view the article pushed by a certain sub-dialogue, he can click the control corresponding to the sub-conversation (such as the sub-conversation of contact 1), so that the display interface of the instant chat software jumps to the display interface corresponding to the sub-conversation (such as (b) in Figure 4).

在一些实施例中,如图4中的(c)所示,当应用程序在运行过程中,例如用户点击某一个子对话进行对话的查看时,该子对话对应的进程需要申请图形缓冲区时,此时手机可以显示提示信息,提示用户是否要开启手机的内存申请监测功能,该提示信息例如为“该操作可以导致内存泄漏,是否开启内存申请监测功能,以保证系统正常运行?”。当手机接收到用户确认开启内存申请监测功能功能的操作(如用户点击图4中的(c)中所示的“确认”图标)时,可以开启内存申请监测功能,对进程申请图形缓冲区的过程进行监测。In some embodiments, as shown in (c) in Figure 4, when the application program is running, for example, when the user clicks on a certain sub-dialog to view the dialog, when the process corresponding to the sub-dialog needs to apply for a graphics buffer At this time, the mobile phone may display a prompt message, prompting the user whether to enable the memory application monitoring function of the mobile phone. The prompt message is, for example, "This operation may cause a memory leak. Do you want to enable the memory application monitoring function to ensure the normal operation of the system?". When the mobile phone receives the user's confirmation of enabling the operation of the memory application monitoring function (such as the user clicking the "confirm" icon shown in (c) in Figure 4), the memory application monitoring function can be enabled, and the memory application monitoring function can be applied to the process. The process is monitored.

在一些实施例中,手机在获取到图像缓冲区的申请结果后,若申请成功,则应用程序继续正常运行;若申请失败,则进一步分析申请失败的原因,若申请失败的原因是虚拟内存映射失败,则可以进一步获取应用程序已占用的虚拟内存的大小,并在应用程序已占用的虚拟内存的大小超过预设阈值时,启动自杀恢复功能。In some embodiments, after the mobile phone obtains the application result of the image buffer, if the application is successful, the application continues to run normally; if the application fails, the reason for the application failure is further analyzed. If it fails, the size of the virtual memory occupied by the application can be further obtained, and when the size of the virtual memory occupied by the application exceeds a preset threshold, the suicide recovery function is activated.

在一些实施例中,手机启动自杀恢复功能时,可以直接结束该应用程序的所有进程,此时手机的显示界面会跳回到手机的主屏幕界面(如图4中的(d)所示的界面)。In some embodiments, when the mobile phone starts the suicide recovery function, all processes of the application program can be ended directly, and at this time, the display interface of the mobile phone will jump back to the main screen interface of the mobile phone (as shown in (d) in Figure 4 interface).

或者,手机启动自杀恢复功能时,还可以在结束该应用程序的所有进程后,自动拉起该应用程序的主进程,使得手机的显示界面显示该应用程序的主显示界面(如图4中的(a)所示的界面)。Or, when the mobile phone starts the suicide recovery function, it can also automatically pull up the main process of the application program after ending all processes of the application program, so that the display interface of the mobile phone displays the main display interface of the application program (as shown in Figure 4 (a) shows the interface).

可以理解的,图4所示的界面仅为示例,本申请实施例对界面显示的具体内容(如提示信息的具体内容)、提示信息等的显示位置等不作限定。例如,为了不影响用户查看信息,图4中显示的提示信息也可以设置为在状态栏中提示,并显示信息标识提示用户有相关信息可供查看。当用户需要查看时,可以下拉状态栏点击相关信息进行查看。或者,也可以以小窗口的形式,将相关信息显示在即时聊天界面的如右下角或右上角位置等,以在提示用户的同时,减小对聊天内容的遮挡,降低对用户的影响。It can be understood that the interface shown in FIG. 4 is only an example, and the embodiment of the present application does not limit the specific content displayed on the interface (such as the specific content of the prompt information), the display position of the prompt information, and the like. For example, in order not to affect the user's viewing of information, the prompt information shown in FIG. 4 may also be set as a prompt in the status bar, and an information mark is displayed to remind the user that relevant information is available for viewing. When users need to view, they can pull down the status bar and click related information to view. Alternatively, relevant information may also be displayed in the form of a small window in the lower right corner or upper right corner of the instant chat interface, etc., so as to remind the user while reducing the occlusion of the chat content and reducing the impact on the user.

需要说明的是,手机启动内存申请监测功能的方式可以包括:用户主动开启内存申请监测功能的方式、手机自动开启内存申请监测功能的方式以及默认开启内存申请监测功能的方式。It should be noted that the ways for the mobile phone to activate the memory application monitoring function may include: a method for the user to actively enable the memory application monitoring function, a method for the mobile phone to automatically enable the memory application monitoring function, and a method for enabling the memory application monitoring function by default.

方式1,用户主动开启内存申请监测功能Method 1, the user actively enables the memory application monitoring function

示例性的,如图5所示,为本申请实施例提供的开启内存申请监测功能过程中涉及的一些图形用户界面示意图。这里以电子设备是手机为例。Exemplarily, as shown in FIG. 5 , it is a schematic diagram of some graphical user interfaces involved in the process of enabling the memory application monitoring function provided by the embodiment of the present application. Here, the electronic device is a mobile phone as an example.

在一些实施例中,当应用程序开始运行时,其进程在向系统内存发起创建图形缓冲区的申请时,手机可以提示用户开启内存申请监测功能。提示用户的方式例如可以通过界面显示提示信息的方式(如图4中的(c)所示),或者通过语音方式;或者通过界面显示提示信息结合语音方式等。In some embodiments, when the application program starts to run and its process initiates an application for creating a graphics buffer to the system memory, the mobile phone may prompt the user to enable the memory application monitoring function. The way of prompting the user may be, for example, the way of displaying prompt information on the interface (as shown in (c) in FIG. 4 ), or through voice; or through the combination of interface display and voice.

示例性的,如图5中的(a)所示,为手机的主屏幕界面示意图。该主屏幕界面可以包括应用图标显示区域51,用于显示多种类型的应用程序(application,App)图标,如时钟图标、日历图标、图库图标、备忘录图标、文件管理图标、电子邮件图标、音乐图标、计算器图标、录音机图标、运动健康图标、即时聊天图标、浏览器图标、设置图标等。多个应用程序图标下方可以有页面指示符显示区域52,该区域包括的页面指示符用于表明当前显示的页面与其他页面的位置关系。页面指示符的下方可以显示有托盘应用图标显示区域53,用于显示多个托盘应用图标,例如相机应用图标、通讯录应用图标、电话拨号应用图标、信息应用图标等。在另一些实施例中,手机主屏幕界面可以包括比图示更多或更少的应用程序图标或托盘应用图标,本申请对此不作限定。在该主屏幕界面的上方还可以显示有状态栏54,该状态栏54可以包括:移动通信信号(或称蜂窝信号)的一个或多个信号强度指示符,手机的电量指示符,时间指示符等。Exemplarily, as shown in (a) in FIG. 5 , it is a schematic diagram of a main screen interface of a mobile phone. The home screen interface may include an application icon display area 51 for displaying multiple types of application (application, App) icons, such as a clock icon, a calendar icon, a gallery icon, a memo icon, a file management icon, an email icon, a music icon, etc. icon, calculator icon, voice recorder icon, sports health icon, instant chat icon, browser icon, settings icon, etc. There may be a page indicator display area 52 under the multiple application program icons, and the page indicator included in the area is used to indicate the positional relationship between the currently displayed page and other pages. A tray application icon display area 53 may be displayed below the page indicator, for displaying a plurality of tray application icons, such as a camera application icon, an address book application icon, a phone dial application icon, an information application icon, and the like. In some other embodiments, the main screen interface of the mobile phone may include more or less application program icons or tray application icons than shown in the figure, which is not limited in this application. A status bar 54 can also be displayed on the top of the main screen interface, and the status bar 54 can include: one or more signal strength indicators of the mobile communication signal (or cellular signal), the battery indicator of the mobile phone, and the time indicator Wait.

在一些实施例中,手机可以接收用户针对设置图标的点击操作;响应于用户的点击操作,手机可以显示如图5中的(b)所示的设置详情界面。In some embodiments, the mobile phone can receive the user's click operation on the setting icon; in response to the user's click operation, the mobile phone can display the setting details interface as shown in (b) in FIG. 5 .

如图5中的(b)所示,设置详情界面可以包括多项业务的管理栏,例如无线和网络管理栏、蓝牙管理栏、桌面和壁纸管理栏、显示管理栏、声音管理栏、应用管理栏、电池管理栏、存储管理栏、安全和隐私管理栏等。在实际应用中,设置界面还可以包括比图示更多或更少类型的管理栏,本申请对此不做限定。As shown in (b) in Figure 5, the setting details interface may include multiple business management columns, such as wireless and network management columns, Bluetooth management columns, desktop and wallpaper management columns, display management columns, sound management columns, application management bar, battery management bar, storage management bar, security and privacy management bar, etc. In practical applications, the setting interface may also include more or fewer types of management columns than those shown in the illustration, which is not limited in this application.

在一些实施例中,手机可以接收用户针对应用管理栏的点击操作;响应于用户的点击操作,手机可以显示如图5中的(c)所示的应用程序管理界面。In some embodiments, the mobile phone may receive the user's click operation on the application management bar; in response to the user's click operation, the mobile phone may display the application program management interface as shown in (c) in FIG. 5 .

示例性的,应用程序界面可以包括多项业务管理栏,该业务例如包括:系统应用设置、应用监测管理、应用双开、授权管理等。每一项业务名称的后方,可以显示该业务对应的下一页指示符。Exemplarily, the application program interface may include a plurality of service management columns, and the services include, for example: system application setting, application monitoring management, application dual opening, authorization management, and the like. Behind each service name, a next page indicator corresponding to the service may be displayed.

在一些实施例中,如图5中的(c)所示,手机可以接收应用监测管理栏中下一页指示符的点击操作。响应于用户的点击操作,手机可以显示如图5中的(d)所示的应用监测管理界面。In some embodiments, as shown in (c) of FIG. 5 , the mobile phone may receive a click operation of the next page indicator in the application monitoring management bar. In response to the user's click operation, the mobile phone may display an application monitoring management interface as shown in (d) in FIG. 5 .

示例性的,如图5中的(d)所示,该应用监测管理界面可以包括内存申请监测功能的说明内容、开关控件、以及该内存申请监测功能下针对各个应用程序的个性化设置区域。其中,内存申请监测功能的说明内容用于介绍该内存申请监测功能,以使用户更加清楚该功能的作用。该说明内容例如可以是“开关开启内存申请监测功能后,系统会对正在运行的应用程序申请系统内存的结果进行监测,以及时发现内存泄露的情况”。在一些实施例中,内存申请监测功能介绍的下方区域,可以显示该内存申请监测功能对应的开关控件,以实现用户对该内存申请监测功能的开启或者关闭。Exemplarily, as shown in (d) of FIG. 5 , the application monitoring management interface may include description content of the memory application monitoring function, switch controls, and a personalized setting area for each application under the memory application monitoring function. Wherein, the description content of the memory application monitoring function is used to introduce the memory application monitoring function, so that the user can understand the function of the function more clearly. The content of the description may be, for example, "after the memory application monitoring function is turned on, the system will monitor the result of the running application program applying for system memory, so as to detect memory leaks in time". In some embodiments, the lower area of the introduction of the memory application monitoring function may display a switch control corresponding to the memory application monitoring function, so as to allow the user to enable or disable the memory application monitoring function.

应理解,通过针对不同应用程序可以独立设置控制内存申请监测功能开关的控件,这样可以使用户结合应用程序的特点,有选择性且更加贴合需求地使用该内存申请监测功能。通过这种方式,在考虑不同业务特点的基础上,使该功能得到更加合理的应用,避免内存申请监测功能对某些应用程序的进程造成干扰或中断,从而保障了用户的使用体验。It should be understood that by independently setting the controls for controlling the on/off of the memory application monitoring function for different applications, this enables the user to selectively use the memory application monitoring function in combination with the characteristics of the application programs and more in line with requirements. In this way, on the basis of considering different business characteristics, the function can be applied more reasonably, and the memory application monitoring function can avoid interference or interruption of the process of some application programs, thereby ensuring the user experience.

方式2,手机自动开启内存申请监测功能Method 2, the mobile phone automatically turns on the memory application monitoring function

在一种可能的实现方式中,当应用程序开始运行时,手机可以自动开启内存申请监测功能,也可以在应用程序的进程向系统内存发起内存申请(申请图形缓冲区)时,手机自动开启内存申请监测功能,对内存申请的情况进行监测。In a possible implementation, when the application starts running, the mobile phone can automatically enable the memory application monitoring function, or when the application process initiates a memory application to the system memory (applying for a graphics buffer), the mobile phone can automatically open the memory The application monitoring function monitors the status of the memory application.

可选地,当手机开启内存申请监测功能时,可以显示提示信息,以告知用户手机当前将执行申请监测功能。或者,还可以显示查询信息,以向用户询问是否确认手机执行内存申请监测功能(如图4中的(c)所示)。示例性的,该提示信息或查询信息可以在手机的状态栏中显示,或者在手机当前界面中显示,本申请对此不作限定。Optionally, when the memory application monitoring function is enabled on the mobile phone, a prompt message may be displayed to inform the user that the mobile phone will currently execute the application monitoring function. Alternatively, query information may also be displayed to ask the user whether to confirm that the mobile phone executes the memory application monitoring function (as shown in (c) in FIG. 4 ). Exemplarily, the prompt information or query information may be displayed in the status bar of the mobile phone, or displayed in the current interface of the mobile phone, which is not limited in this application.

应理解,该方式中手机自动开启内存申请监测功能的过程,对用户来说可以是无感知的。通过该方式内存申请监测功能,可以避免对当前运行的应用造成影响,如可以避免视频暂停等,从而保证用户体验。It should be understood that the process of the mobile phone automatically enabling the memory application monitoring function in this manner may be unaware to the user. In this way, the memory application monitoring function can avoid impacting the currently running applications, such as avoiding video pauses, etc., thereby ensuring user experience.

方式3,默认开启内存申请监测功能Method 3, the memory application monitoring function is enabled by default

在一种可能的实现方式中,在手机出厂前,可以将内存申请监测功能设置为默认开启状态,以实现在后续用户使用手机过程中,可以随时地进行内存申请的监测和管理。In a possible implementation, before the mobile phone leaves the factory, the memory application monitoring function can be set to be enabled by default, so that the memory application can be monitored and managed at any time during the subsequent use of the mobile phone by the user.

结合上述介绍的示例性开启方式,本申请实施例提供的内存申请监测的方法,可以以用户有感知的形式进程(如用户主动开启,或者向用户显示相关信息等),或者也可以以用户无感知的形式进行,本申请实施例对此不作限定。In combination with the exemplary opening methods described above, the memory application monitoring method provided by the embodiment of this application can be processed in a form that the user is aware of (for example, the user actively opens it, or displays relevant information to the user, etc.), or it can also be performed without the user. It is performed in the form of perception, which is not limited in this embodiment of the present application.

以上结合附图,对本申请实施例提供的应用程序的管理方法所适用的应用场景、对应功能的开启方式等进行了介绍。为更好地理解本申请实施例提供的信号强度预测的方法,以下结合附图对其具体实现过程进行示例性介绍。The application scenarios to which the application program management method provided in the embodiment of the present application is applicable, the way to enable corresponding functions, etc. are introduced above with reference to the accompanying drawings. In order to better understand the signal strength prediction method provided by the embodiment of the present application, the specific implementation process thereof is exemplarily introduced below with reference to the accompanying drawings.

示例性的,如图6所示,为本申请实施例提供的电子设备在执行本申请实施例提供的应用程序的管理方法的过程中电子设备的系统内的交互流程示意图。具体可以包括以下步骤:Exemplarily, as shown in FIG. 6 , it is a schematic diagram of an interaction flow within the system of the electronic device during the process of executing the application program management method provided by the embodiment of the present application by the electronic device provided in the embodiment of the present application. Specifically, the following steps may be included:

S601,在应用程序运行过程中,应用程序的进程向内存管理器申请图形缓冲区。S601. During the running of the application program, the process of the application program applies for a graphics buffer from the memory manager.

其中,上述应用程序可以是多进程的应用程序,也可以是单进程的应用程序。在实际应用中,为了提高运行速率,降低应用程序的冗余度,应用程序通常为多进程的应用程序,多个进程之间可以是主从关系。Wherein, the above-mentioned application program may be a multi-process application program or a single-process application program. In practical applications, in order to improve the running speed and reduce the redundancy of the application program, the application program is usually a multi-process application program, and a master-slave relationship can be established between multiple processes.

在应用程序运行过程中,为了绘制界面和保存绘制的数据,运行的进程会向内存管理器申请图形缓冲区(graphicbuffer),以Android系统为例,上述进程向内存管理器申请图形缓冲区可以使用以下方式:During the running of the application, in order to draw the interface and save the drawn data, the running process will apply for a graphics buffer (graphic buffer) from the memory manager. Taking the Android system as an example, the above process can apply for a graphic buffer to the memory manager. The following way:

方式1:通过graphicbuffermapper申请进程间共享的图形缓冲区。Method 1: Apply for a graphics buffer shared between processes through graphicbuffermapper.

Android系统提供了graphicbuffermapper工具类,该工具类为上层访问硬件抽象层(gralloc模块)中提供了接口。The Android system provides the graphicbuffermapper tool class, which provides an interface for the upper layer to access the hardware abstraction layer (gralloc module).

用户空间的应用程序在使用图形缓冲区时,需要先加载gralloc模块,并且获得一个gralloc设备和一个fb设备,有了gralloc设备之后,用户空间中的应用程序就可以申请分配一块图形缓冲区,并且将这块图形缓冲区映射到应用程序的地址空间中,以便可以向里面写入要绘制的画面的内容。最后,用户空间中的应用程序就通过fb设备来将已经准备好了的图形缓冲区渲染到帧缓冲区中去,即将图形缓冲区的内容绘制到显示屏中去,实现应用程序的界面显示。When the application in user space uses the graphics buffer, it needs to load the gralloc module first, and obtain a gralloc device and a fb device. After the gralloc device is available, the application in the user space can apply for the allocation of a graphics buffer, and Map this graphics buffer into the address space of the application program, so that the content of the picture to be drawn can be written into it. Finally, the application program in the user space renders the prepared graphics buffer to the frame buffer through the fb device, that is, draws the content of the graphics buffer to the display screen to realize the interface display of the application program.

方式2:通过graphicbufferallocator进程接口申请应用程序使用的图形缓冲区。Method 2: Apply for the graphics buffer used by the application through the graphicbufferallocator process interface.

Android系统还提供了graphicbufferallocator进程接口,通过graphicbufferallocator进程接口通用可以申请到图像缓冲区。The Android system also provides a graphicbufferallocator process interface, through which the image buffer can be commonly applied for.

S602,自杀恢复管理模块启动内存申请监测功能。S602, the suicide recovery management module starts a memory application monitoring function.

在此,自杀恢复管理模块在启动内存申请监测功能后,就会向内存管理器发送获取图形缓冲区申请的申请结果的指令。Here, after the suicide recovery management module starts the memory application monitoring function, it will send an instruction to obtain the application result of the graphics buffer application to the memory manager.

在一些实施例中,自杀恢复管理模块可以在应用程序开始运行时就启动内存申请监测功能,也可以在应用程序的进程向系统内存发起图形缓冲区申请时再启动内存申请监测功能,自杀恢复管理模块还可以实时获取应用程序的虚拟内存占用情况,在应用程序的虚拟内存占用超过某一数值时(这个数值可以根根据实际应用场景来设定,本申请对此不加以限制),开启内存申请监测功能,还可以是在应用程序的虚拟内存占用超过某一数值且该应用程序的进程发起图形缓冲区申请时才启动内存申请监测功能,当然还可以在其他情况下启动内存申请监测功能,本申请对此不加以赘述。In some embodiments, the suicide recovery management module can start the memory application monitoring function when the application program starts to run, and can also start the memory application monitoring function when the process of the application program initiates a graphics buffer application to the system memory. Suicide recovery management The module can also obtain the virtual memory usage of the application in real time. When the virtual memory usage of the application exceeds a certain value (this value can be set according to the actual application scenario, this application does not limit this), open the memory application The monitoring function can also start the memory application monitoring function when the virtual memory usage of the application exceeds a certain value and the application process initiates a graphics buffer application. Of course, the memory application monitoring function can also be activated under other circumstances. The application does not elaborate on this.

其中,上述启动内存申请监测功能的方式可以参见上述相关的内容,为避免重复,在此不再赘述。Wherein, the above-mentioned method of starting the memory application monitoring function can refer to the above-mentioned related content, and in order to avoid repetition, details are not repeated here.

在此,上述图形缓冲区申请的申请结果包括申请成功和申请失败。Here, the application results of the above graphics buffer application include application success and application failure.

申请结果可以以二进制编码的形式来表示。例如申请结果可以包括两个字段,一个字段用于表示申请是否成功,一个字段用于表示申请失败时对应的错误类型。示例性的,用于表示申请是否成功的字段包括2位,其中,00表示申请成功,01表示申请失败;用于表示申请失败时对应的失败类型包括3位,其中,001表示系统可用内存过少、010表示内存映射失败、011表示其他异常情况等(当第一个字段为00时对应的第二个字段为000)。Application results can be expressed in binary coded form. For example, the application result may include two fields, one field is used to indicate whether the application is successful, and the other field is used to indicate the corresponding error type when the application fails. Exemplarily, the field used to indicate whether the application is successful includes 2 bits, wherein 00 indicates that the application is successful, and 01 indicates that the application fails; the corresponding failure type used to indicate that the application fails includes 3 bits, wherein 001 indicates that the available memory of the system is too large. Less, 010 means memory mapping failure, 011 means other abnormal conditions, etc. (when the first field is 00, the corresponding second field is 000).

当然,上述申请结果也可以只包括一个字段,该字段即可以表示出申请是否成功,也可以表示在申请失败时对应的失败类型。示例性的,该字段包括4位,其中第一位用于表示申请是否成功,第二至第四位用于表示申请失败时对应的失败类型,例如0000就表示申请成功,1001就表示申请失败且失败类型为系统可用内存过少,1010就表示申请失败且失败类型为内存映射失败,1011就表示申请失败且失败类型为其他异常情况。Of course, the above application result may also include only one field, which can indicate whether the application is successful or not, and can also indicate the corresponding failure type when the application fails. Exemplarily, this field includes 4 bits, of which the first bit is used to indicate whether the application is successful, and the second to fourth bits are used to indicate the corresponding failure type when the application fails. For example, 0000 means that the application is successful, and 1001 means that the application is failed. And the failure type is too little available memory in the system, 1010 means that the application failed and the failure type is memory mapping failure, and 1011 means that the application failed and the failure type is other abnormal conditions.

当然,当申请成功时,可以返回no_error;当申请失败时,可以返回error,并附带错误码,通过错误码表示失败类型。Of course, when the application is successful, no_error can be returned; when the application fails, error can be returned with an error code, which indicates the type of failure.

可以理解的是,上述仅是申请结果的示例,上述申请结果还可以包含其他内容,例如返回的时间等,本申请对此不进行限制。It can be understood that the above is only an example of the application results, and the above application results may also include other content, such as the return time, etc., which is not limited in this application.

S603,内存管理器响应于上述获取图形缓冲区申请的申请结果的指令,将图像缓冲区申请的申请结果发送至自杀恢复管理模块。S603, the memory manager sends the application result of the image buffer application to the suicide recovery management module in response to the above instruction of acquiring the application result of the graphics buffer application.

具体地,应用程序的进程向系统内存发出图像缓冲区申请时,在系统可用内存满足该申请,且申请到的内存能够映射到该进程的虚拟内存的地址时,内存管理器会将申请成功的结果发送给到自杀恢复管理模块。Specifically, when the application process sends an image buffer application to the system memory, when the available memory of the system satisfies the application, and the applied memory can be mapped to the address of the virtual memory of the process, the memory manager will send the application successful Results are sent to the Suicide Recovery Management Module.

在系统可用内存过少(申请的图形缓冲区占用的内存大于系统可用内存)、申请到的内存无法映射到进程的虚拟内存的地址中以及其他异常情况时,内存管理器会将申请失败的结果发送给到自杀恢复管理模块。When the available memory of the system is too small (the memory occupied by the requested graphics buffer is larger than the available memory of the system), the requested memory cannot be mapped to the address of the virtual memory of the process, or other abnormal conditions, the memory manager will report the result of the application failure Sent to the Suicide Recovery Administration Module.

需要说明的是,如果应用程序的进程是通过S601中的方式2去申请图形缓冲区的,即通过graphicbufferallocator进程接口申请应用程序使用的图形缓冲区时,虽然对于该进程而言,图形缓冲区的申请是失败了,但是实际上内存管理器已经将其申请的图形缓冲区所需的内存分配给该进程了,而进程申请失败后会继续发起申请,这样就系统为其分配的内存(实际上没有被使用)就会越积累越多,最终导致系统内存不足,整机崩溃卡死的情况。It should be noted that if the application process applies for the graphics buffer through the method 2 in S601, that is, when applying for the graphics buffer used by the application through the graphicbufferallocator process interface, although for the process, the graphics buffer The application failed, but in fact the memory manager has allocated the memory required by the graphics buffer it applied for to the process, and the process will continue to initiate the application after the application fails, so that the memory allocated by the system (actually Not being used) will accumulate more and more, and eventually lead to insufficient system memory, and the whole machine crashes and freezes.

S604,自杀恢复管理模块检测到接收到的图形缓冲区申请的申请结果为申请成功,则自杀恢复管理模块发送映射指令给到应用程序。S604, the suicide recovery management module detects that the application result of the received graphics buffer application is successful, and then the suicide recovery management module sends a mapping instruction to the application program.

S605,应用程序响应于该映射指令,将申请到的内存映射到应用程序的进程的虚拟内存的地址中。S605, the application program maps the requested memory to the address of the virtual memory of the process of the application program in response to the mapping instruction.

当自杀恢复管理模块接收到内存管理器发送过来的申请结果后,通过分析申请结果对应的二进制编码就可以确定出图形缓冲区申请是否成功。示例性的,当申请结果包括两个字段,其中,第一个字段用于表示申请是否成功,读取该字段的编码,并基于该字段的编码就可以确定图形缓冲区申请结果。After the suicide recovery management module receives the application result sent by the memory manager, it can determine whether the graphics buffer application is successful by analyzing the binary code corresponding to the application result. Exemplarily, when the application result includes two fields, wherein the first field is used to indicate whether the application is successful, the code of this field is read, and the graphics buffer application result can be determined based on the code of this field.

例如,自杀恢复管理模块接收到的申请结果为“00,000”,则读取第一字段的内容“00”,并根据预先确定的该编码对应的含义可知,申请结果为申请成功。又例如,申请结果为“01,010”,则读取到第一字段的内容为“01”,根据预先确定的编码对应的含义可知,申请结果为申请失败。For example, if the application result received by the suicide recovery management module is "00,000", it reads the content "00" in the first field, and according to the predetermined meaning corresponding to the code, the application result is successful. For another example, if the application result is "01,010", then the read content of the first field is "01". According to the meaning corresponding to the predetermined code, the application result is application failure.

又示例性的,当申请结果只包含一个字段,其中该字段的第1位用于表示申请是否成功,则读取该位的编码,基于该位的编码确定内存申请的申请结果。As another example, when the application result contains only one field, where the first bit of the field is used to indicate whether the application is successful, the code of this bit is read, and the application result of the memory application is determined based on the code of this bit.

例如,申请结果为“0000”,则读取第一位的编码“0”,并根据预先确定的该编码对应的含义可知,申请结果为申请成功。又例如,申请结果为“1010”,则读取第一位的编码“1”,根据预先确定的该编码对应的含义可知,申请结果为申请失败。For example, if the application result is "0000", read the code "0" in the first digit, and according to the predetermined meaning corresponding to the code, it can be known that the application result is a successful application. For another example, if the application result is "1010", read the first code "1", and according to the predetermined meaning corresponding to the code, the application result is application failure.

其中,应用程序将申请到的内存映射到进程的虚拟内存的地址中的内存映射过程是常用的一种内存管理方法,具体的内存映射过程可以参见现有的方式来实现,本申请在此不加以赘述。Among them, the memory mapping process in which the application program maps the requested memory to the address of the virtual memory of the process is a commonly used memory management method. The specific memory mapping process can be implemented by referring to the existing methods, and this application does not describe it here. To repeat.

S606,自杀恢复管理模块检测到接收到的图形缓冲区申请的申请结果为申请失败,则根据申请结果分析失败类型。S606. The suicide recovery management module detects that the application result of the received graphics buffer application is application failure, and analyzes the failure type according to the application result.

自杀恢复管理模块确定内存申请的申请结果为申请失败的过程可以参见S604的描述,为避免重复,在此不加以赘述。The process for the suicide recovery management module to determine that the application result of the memory application is application failure can refer to the description of S604, and will not be repeated here to avoid repetition.

其中,上述申请失败时的失败类型可以包括系统可用内存过少、内存映射失败、其他异常情况等,此处不做限定。Wherein, the failure types when the above application fails may include too little available memory in the system, memory mapping failure, other abnormal conditions, etc., which are not limited here.

在一些实施例中,自杀恢复管理模块可以根据内存管理器返回的申请结果来确定失败类型。例如可以通过分析申请结果对应的二进行编码来确定出失败类型。In some embodiments, the suicide recovery management module can determine the failure type according to the application result returned by the memory manager. For example, the type of failure can be determined by analyzing the code corresponding to the 2 of the application result.

示例性的,当申请结果包括两个字段,其中,第一个字段用于表示申请是否成功,第二个字段用于失败类型,表示读取第二字段的编码,并基于第二字段的编码就可以确定内存申请结果。Exemplarily, when the application result includes two fields, the first field is used to indicate whether the application is successful, and the second field is used for the type of failure, indicating that the code of the second field is read and based on the code of the second field The memory application result can be determined.

例如,申请结果为“01,001”,则读取第二字段的内容“001”,并根据预先确定的该编码对应的含义可知,失败类型为系统可用内存过少。又例如,申请结果为“01,010”,则读取到第二字段的内容为“010”,根据预先确定的编码对应的含义可知,失败类型为内存映射失败。For example, if the application result is "01,001", read the content "001" in the second field, and according to the predetermined meaning corresponding to the code, it can be known that the failure type is too little available memory in the system. For another example, if the application result is "01,010", the read content of the second field is "010". According to the meaning corresponding to the predetermined code, the failure type is a memory mapping failure.

又示例性的,当申请结果只包含一个字段,其中该字段的第2位至第4位用于表示失败类型,则读取第二位至第四位的编码,基于第二位至第四位的编码确定内存申请的申请结果。As another example, when the application result only contains one field, where the 2nd to 4th digits of the field are used to indicate the type of failure, then read the codes of the 2nd to 4th digits, based on the second to 4th digits The encoding of the bit determines the application result of the memory application.

例如,申请结果为“1001”,则读取第2位至第四位的编码“001”,并根据预先确定的该编码对应的含义可知,失败类型为系统可用内存过少。又例如,申请结果为“1010”,则读取第2位至第4位的编码“010”,根据预先确定的该编码对应的含义可知,失败类型为内存映射失败。For example, if the application result is "1001", read the code "001" from the second to the fourth digit, and according to the predetermined meaning corresponding to the code, it can be known that the failure type is too little available memory in the system. For another example, if the application result is "1010", read the code "010" from the 2nd to 4th digits. According to the predetermined meaning corresponding to the code, it can be known that the failure type is memory mapping failure.

又例如当申请结果返回为error并附带错误码时,可以通过错误码来确定失败类型。For another example, when the application result is returned as an error with an error code, the failure type can be determined through the error code.

S607,自杀恢复管理模块在确定失败类型不为内存映射失败的情况下,发送第一异常日志输出指令给到日志管理器。S607. The suicide recovery management module sends a first exception log output instruction to the log manager when determining that the failure type is not a memory mapping failure.

判断失败类型的相关内容可以参见S606的描述,在此不加以赘述。For the related content of judging the failure type, refer to the description of S606, which will not be repeated here.

S608,日志管理器响应于该第一异常日志输出指令,生成并保存与失败类型对应的异常日志。S608. The log manager generates and saves an exception log corresponding to the failure type in response to the first exception log output instruction.

在此,上述第一异常日志输出指令用于指示日志管理器生成并保存与失败类型对应的异常日志。Here, the above-mentioned first exception log output instruction is used to instruct the log manager to generate and save the exception log corresponding to the failure type.

由于失败类型不为内存映射失败,那么基本不会造成内存泄漏的情况,因此无需对应用程序进行任何操作,只需要控制日志管理器生成并保存与该失败类型对应的异常日志即可,以便用户知悉该图形缓冲区申请失败的失败类型,以及其他相关信息(例如申请时间、申请主体(即哪个应用程序的哪个进程提交的申请)等)。Since the failure type is not a memory mapping failure, it will basically not cause memory leaks, so there is no need to perform any operations on the application, only need to control the log manager to generate and save the exception log corresponding to the failure type, so that users Know the failure type of the graphics buffer application failure, and other related information (such as application time, application subject (that is, which process of which application program submitted the application), etc.).

在一些实施例中,上述异常日志可以包括申请发起的进程名称、异常发生的时间和异常的内容等,异常的内容即包括申请图形缓冲区失败以及失败类型。示例性的,当失败类型为系统可用内存过少时,上述异常内容可以是A应用的B进程于xx时间由于系统内存过少申请图形缓冲区失败。In some embodiments, the above-mentioned exception log may include the name of the process initiated by the application, the time when the exception occurred, and the content of the exception. The content of the exception includes the failure to apply for the graphics buffer and the type of failure. Exemplarily, when the failure type is too little available memory in the system, the above abnormal content may be that process B of application A fails to apply for a graphics buffer at time xx due to too little system memory.

在一些实施例中,当失败类型是系统内存过少时,基于该异常日志,电子设备可以启动LMK机制。In some embodiments, when the failure type is too little system memory, based on the exception log, the electronic device can start the LMK mechanism.

在一些实施例中,上述异常日志可以保存在日志管理器中,电子设备可以通过日志管理器来读取该异常日志。In some embodiments, the above exception log may be stored in a log manager, and the electronic device may read the exception log through the log manager.

S609,自杀恢复管理模块在确定失败类型为内存映射失败的情况下,获取应用程序的虚拟内存占用情况。S609. The suicide recovery management module obtains the virtual memory occupation of the application program in the case that the failure type is determined to be a memory mapping failure.

当失败类型为内存映射失败时,很大概率是因为该应用程序的虚拟内存占用过多了,这种情况很容易导致系统内存泄漏,为了确定是否是由于虚拟内存占用过多,此时可以获取该应用程序的虚拟内存使用情况,继而分析出是否存在内存泄漏的风险。When the failure type is memory mapping failure, it is very likely that the virtual memory of the application is too much, which can easily lead to system memory leaks. In order to determine whether it is due to too much virtual memory, you can obtain The application's virtual memory usage, and then analyze whether there is a risk of memory leaks.

在一些实施例中,自杀恢复管理模块可以通过/proc/self/status函数来调出应用程序的虚拟内存占用情况。在确定了内存申请失败且失败类型为内存映射失败后,自动调用/proc/self/status函数,就可以获取到该应用程序当前的虚拟内存占用情况。In some embodiments, the suicide recovery management module can call out the virtual memory usage of the application through the /proc/self/status function. After it is determined that the memory application fails and the failure type is a memory mapping failure, the /proc/self/status function is automatically called to obtain the current virtual memory usage of the application.

S610,自杀恢复管理模块判断应用程序占用的虚拟内存是否超过预设阈值。S610. The suicide recovery management module determines whether the virtual memory occupied by the application exceeds a preset threshold.

其中,预设阈值可以根据应用程序来设置,例如对于32位的应用程序,上述预设阈值可以设置为3.7G。当然对于32位的应用程序,上述预设阈值可以设置为比3.7G低的某些数值,例如3.5G、3.2G等。Wherein, the preset threshold can be set according to the application program, for example, for a 32-bit application program, the above preset threshold can be set to 3.7G. Of course, for 32-bit applications, the above preset threshold can be set to some value lower than 3.7G, such as 3.5G, 3.2G and so on.

S611,自杀恢复管理模块在确定应用程序占用的虚拟内存未超过预设阈值的情况下,发送第二异常日志输出指令给到日志管理器。S611. The suicide recovery management module sends a second exception log output instruction to the log manager when it is determined that the virtual memory occupied by the application program does not exceed a preset threshold.

S612,日志管理器响应于该第二异常日志输出指令,生成并保存内存映射失败且虚拟内存未超过阈值的异常日志。S612. In response to the second exception log output instruction, the log manager generates and saves an exception log indicating that the memory mapping fails and the virtual memory does not exceed the threshold.

在此,上述第一异常日志输出指令用于指示日志管理器生成并保存内存映射失败且虚拟内存未超过阈值的异常日志。Here, the above-mentioned first exception log output instruction is used to instruct the log manager to generate and save the exception log in which the memory mapping fails and the virtual memory does not exceed the threshold.

在此,由于应用程序占用的虚拟内存未超过预设阈值,也就是说,这不会导致内存泄漏,因此无需对应用程序进行任何操作,只需要通过日志管理器生成并保存内存映射失败且虚拟内存未超过阈值的异常日志。Here, since the virtual memory occupied by the application does not exceed the preset threshold, that is to say, this will not cause a memory leak, there is no need to perform any operations on the application except to generate and save the memory map through the log manager. Exception logs that the memory does not exceed the threshold.

S613,自杀恢复管理模块在确定应用程序占用的虚拟内存超过预设阈值的情况下,发送启动自杀恢复功能的指令给到进程管理器。S613. The suicide recovery management module sends an instruction to start the suicide recovery function to the process manager when it is determined that the virtual memory occupied by the application exceeds a preset threshold.

S614,进程管理器响应于该启动自杀恢复功能的指令,结束应用程序的所有进程。S614, the process manager terminates all processes of the application program in response to the instruction for starting the suicide recovery function.

在一些实施例中,在应用程序占用的虚拟内存超过预设阈值时,自杀恢复管理模块可以通过向进程管理器发送启动自杀恢复功能的指令,该指令用于指示进程管理器结束该应用程序的全部进程,释放被该应用程序占用的系统内存。In some embodiments, when the virtual memory occupied by the application program exceeds the preset threshold, the suicide recovery management module may send an instruction to the process manager to start the suicide recovery function, and the instruction is used to instruct the process manager to terminate the application program. All processes, frees system memory occupied by the application.

进程管理器中有系统当前正在运行的所有进程,通过进程管理器结束带有该应用程序名相关的所有进程,就能释放该应用程序占用的系统内存。The process manager contains all the processes currently running in the system, and the system memory occupied by the application can be released by ending all the processes related to the application name through the process manager.

在一些实施例中,电子设备启动自杀恢复功能时,可以直接结束该应用程序的所有进程,此时电子设备的显示界面会跳回到电子设备的主屏幕界面,即用户感受到应用程序闪退。In some embodiments, when the electronic device activates the suicide recovery function, all processes of the application program can be terminated directly. At this time, the display interface of the electronic device will jump back to the main screen interface of the electronic device, that is, the user feels that the application program has flashed back. .

在一些实施例中,进程管理器在结束该应用程序的全部进程后,日志管理器还可以生成并保存由于虚拟内存占用过高,结束该应用程序的运行的异常日志。In some embodiments, after the process manager terminates all processes of the application program, the log manager may also generate and save an exception log indicating that the application program is terminated due to high virtual memory usage.

根据本申请实施例提供的应用程序管理方法,通过监测应用程序的进程向内存管理器申请图形缓冲区的情况,在内存申请失败且是由于虚拟内存占用过多的情况下,启动自杀恢复功能,结束该应用程序的所有进程,以释放被该应用程序占用的内存,避免由于内存泄露导致系统崩溃、卡死等严重后果,减轻对用户使用的影响。According to the application program management method provided by the embodiment of the present application, by monitoring the application process of the application program to the memory manager for the graphics buffer, when the memory application fails due to excessive virtual memory usage, the suicide recovery function is activated, End all processes of the application to release the memory occupied by the application, avoid serious consequences such as system crashes and freezes caused by memory leaks, and reduce the impact on users.

上述实施例会使得应用程序直接闪退,导致用户侧感受不佳,为了减轻对用户使用的影响,本申请另一实施例还提供了一种应用程序管理方法,如图7所示,为本申请实施例提供的电子设备在执行本申请实施例提供的应用程序的管理方法的过程中电子设备的系统内另一的交互流程示意图。具体可以包括以下步骤:The above embodiment will cause the application program to crash directly, resulting in poor experience on the user side. In order to reduce the impact on the user's use, another embodiment of the present application also provides an application program management method, as shown in Figure 7, which is the The embodiment provides a schematic diagram of another interaction flow in the system of the electronic device when the electronic device executes the application program management method provided in the embodiment of the present application. Specifically, the following steps may be included:

S701~S712的内容可以参见S601~S612的内容,为避免重复,在此不加以赘述。For the content of S701-S712, refer to the content of S601-S612, and to avoid repetition, details are not repeated here.

S713,自杀恢复管理模块在确定应用程序占用的虚拟内存超过预设阈值的情况下,判断发起图形缓冲器申请的进程是否为主进程。S713. The suicide recovery management module determines whether the process that initiates the graphics buffer application is the main process when it is determined that the virtual memory occupied by the application exceeds a preset threshold.

在此,自杀恢复管理模块可以通过进程的ID确定发起图形缓冲器申请的进程(当前运行的进程)是否是主进程。Here, the suicide recovery management module may determine whether the process (currently running process) that initiates the graphics buffer application is the main process through the ID of the process.

每个进程都有自己的ID,而且主进程的ID与子进程的ID明显不同,因此,通过进程的ID就可以确定出其是主进程还是子进程。Each process has its own ID, and the ID of the main process is obviously different from the ID of the child process. Therefore, it can be determined whether it is the main process or the child process through the ID of the process.

S714,自杀恢复管理模块在确定发起图形缓冲器申请的进程不为主进程的情况下,发送结束该应用程序的全部进程的指令给到进程管理器。S714, when the suicide recovery management module determines that the process that initiates the graphics buffer application is not the main process, sends an instruction to terminate all processes of the application program to the process manager.

S715,进程管理器响应于上述结束该应用程序的全部进程的指令,结束应用程序的所有进程。S715. The process manager terminates all processes of the application program in response to the instruction to terminate all processes of the application program.

由于发起图形缓冲器申请的进程不是主进程,故此时电子设备显示的界面也不是该应用程序的主进程的显示界面,可能是经过用户多次操作后才进入到的页面,电子设备也无法重现该页面,因此,电子设备只会通过进程管理器结束该应用程序的全部进程以释放被其占用的系统内存。Since the process that initiates the graphics buffer application is not the main process, the interface displayed by the electronic device at this time is not the display interface of the main process of the application program. It may be a page that the user enters after multiple operations, and the electronic device cannot reset Therefore, the electronic device will only end all processes of the application program through the process manager to release the system memory occupied by it.

结束应用程序的全部进程的实现过程可以参见S614的描述,为避免重复,在此不加以赘述。For the implementation process of terminating all the processes of the application program, refer to the description of S614, and to avoid repetition, details are not repeated here.

S716,自杀恢复管理模块在确定发起图形缓冲器申请的进程为主进程的情况下,发送结束应用程序的全部进程后重新拉起该应用程序的主进程的指令给到进程管理器。S716. In the case that the suicide recovery management module determines that the process that initiates the graphics buffer application is the main process, send an instruction to the process manager to restart all the processes of the application program and restart the main process of the application program.

S717,进程管理器响应于上述结束应用程序的全部进程后重新拉起该应用程序的主进程的指令,结束应用程序的全部进程后重新拉起该应用程序的主进程。S717, the process manager responds to the above instruction to restart the main process of the application program after ending all the processes of the application program, and restarts the main process of the application program after ending all the processes of the application program.

由于发起图形缓冲器申请的进程是该应用程序的主进程,故此时电子设备显示的界面就是该应用程序的主显示界面,因此,在结束该应用程序的所有进程后自动拉起该应用程序的主进程,此时电子设备的显示界面会直接跳到该应用程序的主显示界面。Since the process that initiates the graphics buffer application is the main process of the application program, the interface displayed by the electronic device is the main display interface of the application program at this time. The main process, at this time, the display interface of the electronic device will directly jump to the main display interface of the application program.

由于结束应用程序的进程后再次拉起该应用程序的主进程的间隔时间很短,因此用户对此无感知,只能感受到电子设备的显示界面又跳回该应用程序的主显示界面。此时用户不会感受到应用程序闪退,因此可以在释放被该应用程序占用的系统内存的同时避免对用户的使用造成影响,提升用户体验感。Since the time interval between launching the main process of the application program after the process of the application program is terminated is very short, the user is not aware of this, and can only feel that the display interface of the electronic device jumps back to the main display interface of the application program. At this time, the user will not experience the crash of the application program, so the system memory occupied by the application program can be released while the impact on the user's use can be avoided, and the user experience can be improved.

本申请实施例还提供了一种计算机可读存储介质,该计算机可读存储介质中存储有指令,当其在计算机或处理器上运行时,使得计算机或处理器执行上述任一个方法中的一个或多个步骤。The embodiment of the present application also provides a computer-readable storage medium, the computer-readable storage medium stores instructions, and when it is run on a computer or a processor, the computer or the processor executes one of the above-mentioned methods or multiple steps.

本申请实施例还提供了一种包含指令的计算机程序产品。当该计算机程序产品在计算机或处理器上运行时,使得计算机或处理器执行上述任一个方法中的一个或多个步骤。The embodiment of the present application also provides a computer program product including instructions. When the computer program product is run on the computer or the processor, the computer or the processor is made to perform one or more steps in any one of the above methods.

本申请实施例还提供了一种包含指令的芯片系统。当该指令在计算机或处理器上运行时,使得计算机或处理器执行上述任一个方法中的一个或多个步骤。The embodiment of the present application also provides a chip system including instructions. When the instruction is executed on the computer or the processor, the computer or the processor is caused to perform one or more steps in any one of the above-mentioned methods.

在上述实施例中,可以全部或部分地通过软件、硬件、固件或者其任意组合来实现。当使用软件实现时,可以全部或部分地以计算机程序产品的形式实现。所述计算机程序产品包括一个或多个计算机指令。在计算机上加载和执行所述计算机程序指令时,全部或部分地产生按照本申请实施例所述的流程或功能。所述计算机可以是通用计算机、专用计算机、计算机网络、或者其他可编程装置。所述计算机指令可以存储在计算机可读存储介质中,或者通过所述计算机可读存储介质进行传输。所述计算机指令可以从一个网站站点、计算机、服务器或数据中心通过有线(例如同轴电缆、光纤、数字用户线)或无线(例如红外、无线、微波等)方式向另一个网站站点、计算机、服务器或数据中心进行传输。所述计算机可读存储介质可以是计算机能够存取的任何可用介质或者是包含一个或多个可用介质集成的服务器、数据中心等数据存储设备。所述可用介质可以是磁性介质,(例如,软盘、硬盘、磁带)、光介质(例如,DVD)、或者半导体介质(例如,固态硬盘(solid state disk,SSD))等。In the above embodiments, all or part of them may be implemented by software, hardware, firmware or any combination thereof. When implemented using software, it may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on the computer, the processes or functions according to the embodiments of the present application will be generated in whole or in part. The computer can be a general purpose computer, a special purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in or transmitted via a computer-readable storage medium. The computer instructions may be transmitted from one web site, computer, server, or data center to another web site, computer, server or data center for transmission. The computer-readable storage medium may be any available medium that can be accessed by a computer, or a data storage device such as a server or a data center integrated with one or more available media. The available medium may be a magnetic medium (for example, a floppy disk, a hard disk, or a magnetic tape), an optical medium (for example, DVD), or a semiconductor medium (for example, a solid state disk (solid state disk, SSD)) and the like.

本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,该流程可以由计算机程序来指令相关的硬件完成,该程序可存储于计算机可读取存储介质中,该程序在执行时,可包括如上述各方法实施例的流程。而前述的存储介质包括:ROM或随机存储记忆体RAM、磁碟或者光盘等各种可存储程序代码的介质。Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments are realized. The processes can be completed by computer programs to instruct related hardware. The programs can be stored in computer-readable storage media. When the programs are executed , may include the processes of the foregoing method embodiments. The aforementioned storage medium includes: ROM or random access memory RAM, magnetic disk or optical disk, and other various media that can store program codes.

以上所述,仅为本申请实施例的具体实施方式,但本申请实施例的保护范围并不局限于此,任何在本申请实施例揭露的技术范围内的变化或替换,都应涵盖在本申请实施例的保护范围之内。因此,本申请实施例的保护范围应以所述权利要求的保护范围为准。The above is only the specific implementation of the embodiment of the application, but the protection scope of the embodiment of the application is not limited thereto, and any changes or replacements within the technical scope disclosed in the embodiment of the application shall be covered by this application. Within the scope of protection of the application examples. Therefore, the protection scope of the embodiments of the present application should be based on the protection scope of the claims.

Claims (10)

1. A method for managing an application program, comprising:
monitoring the application result of the graphic buffer area in the running process of the application program;
if the application result of the image buffer area is application failure, analyzing the failure type according to the application result;
if the failure type is memory mapping failure, acquiring the virtual memory occupation condition of the application program;
and if the virtual memory occupied by the application program exceeds a preset threshold value, starting a suicide recovery function of the application program.
2. The method for managing an application according to claim 1, wherein if the virtual memory occupied by the application exceeds a preset threshold, the method for starting a suicide recovery function includes:
and when the virtual memory occupied by the application program exceeds a preset threshold value, ending all processes of the application program.
3. The method for managing application programs according to claim 1, wherein if the virtual memory occupied by the application program exceeds a preset threshold, the method for starting suicide recovery function comprises:
when the virtual memory occupied by the application program exceeds a preset threshold value, judging whether the process applying for the graphic buffer area is a main process of the application program;
if the process applying for the graphic buffer area is the main process of the application program, finishing all the processes of the application program and then re-pulling up the main process of the application program; otherwise, all processes of the application program are ended.
4. The method for managing an application program according to claim 1, wherein after monitoring the application result of the graphics buffer during the running of the application program, the method further comprises:
and if the application result of the graphic buffer area application is successful, mapping the applied memory to the address of the virtual memory of the process.
5. A method for managing an application program according to any one of claims 1 to 4, further comprising:
and if the failure type is not the memory mapping failure, outputting an abnormal log corresponding to the failure type.
6. A method for managing an application program according to claim 1, further comprising:
and if the virtual memory occupied by the application program does not exceed the preset threshold, outputting an abnormal log which fails in memory mapping and does not exceed the threshold.
7. A method for managing an application program according to claim 2 or 3, further comprising:
and after finishing all processes of the application program, outputting an abnormal log for finishing the operation of the application program due to overhigh virtual memory occupation.
8. The method for managing application programs according to claim 1, wherein the monitoring of the application result of the graphics buffer during the running of the application program comprises:
when the process of the application program initiates the application of the graphic buffer area, the memory application monitoring function is started to obtain the application result of the graphic buffer area.
9. An electronic device, comprising a processor and a memory, the processor and the memory being coupled, the memory being configured to store a computer program which, when executed by the processor, causes the electronic device to carry out the steps of the method of any one of claims 1 to 8.
10. A computer-readable storage medium, characterized in that the computer-readable storage medium comprises a computer program which, when run on a computer, causes the computer to carry out the steps of the method according to any one of claims 1 to 8.
CN202111157747.4A 2021-09-30 2021-09-30 Application program management method and electronic equipment Active CN114020652B (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202111157747.4A CN114020652B (en) 2021-09-30 2021-09-30 Application program management method and electronic equipment
CN202211578199.7A CN116107922A (en) 2021-09-30 2021-09-30 Application program management method and electronic device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111157747.4A CN114020652B (en) 2021-09-30 2021-09-30 Application program management method and electronic equipment

Related Child Applications (1)

Application Number Title Priority Date Filing Date
CN202211578199.7A Division CN116107922A (en) 2021-09-30 2021-09-30 Application program management method and electronic device

Publications (2)

Publication Number Publication Date
CN114020652A CN114020652A (en) 2022-02-08
CN114020652B true CN114020652B (en) 2022-12-30

Family

ID=80055410

Family Applications (2)

Application Number Title Priority Date Filing Date
CN202211578199.7A Pending CN116107922A (en) 2021-09-30 2021-09-30 Application program management method and electronic device
CN202111157747.4A Active CN114020652B (en) 2021-09-30 2021-09-30 Application program management method and electronic equipment

Family Applications Before (1)

Application Number Title Priority Date Filing Date
CN202211578199.7A Pending CN116107922A (en) 2021-09-30 2021-09-30 Application program management method and electronic device

Country Status (1)

Country Link
CN (2) CN116107922A (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115309547B (en) * 2022-07-31 2023-08-29 荣耀终端有限公司 Method and device for processing asynchronous binder call
CN115543864A (en) * 2022-09-30 2022-12-30 荣耀终端有限公司 Memory garbage recycling method and electronic equipment
CN116737358B (en) * 2022-10-28 2024-05-17 荣耀终端有限公司 Memory refreshing method and electronic device
CN116074578A (en) * 2022-12-26 2023-05-05 天翼数字生活科技有限公司 A mobile terminal video playback method, device, equipment and readable storage medium

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103324500A (en) * 2013-05-06 2013-09-25 广州市动景计算机科技有限公司 Method and device for recycling internal memory
CN105893269A (en) * 2016-03-31 2016-08-24 武汉虹信技术服务有限责任公司 Memory management method used in Linux system
CN107329892A (en) * 2017-06-07 2017-11-07 珠海市杰理科技股份有限公司 Drive method of testing, device, storage medium and its computer equipment
CN111274060A (en) * 2020-02-10 2020-06-12 广州虎牙科技有限公司 Method, device, equipment and storage medium for determining memory abnormity
CN113010279A (en) * 2021-02-20 2021-06-22 北京字节跳动网络技术有限公司 Application program process processing method and device for mobile terminal and electronic equipment
EP3859525A1 (en) * 2020-01-31 2021-08-04 Kove IP, LLC External memory as an extension to local primary memory
CN113434288A (en) * 2021-06-16 2021-09-24 荣耀终端有限公司 Memory management method and electronic equipment

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7484065B2 (en) * 2004-04-20 2009-01-27 Hewlett-Packard Development Company, L.P. Selective memory allocation
CN106339250B (en) * 2016-08-19 2019-09-27 郭笃刚 A kind of management method of computer virtual memory
CN112162818B (en) * 2020-09-16 2023-04-07 Oppo(重庆)智能科技有限公司 Virtual memory allocation method and device, electronic equipment and storage medium

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103324500A (en) * 2013-05-06 2013-09-25 广州市动景计算机科技有限公司 Method and device for recycling internal memory
CN105893269A (en) * 2016-03-31 2016-08-24 武汉虹信技术服务有限责任公司 Memory management method used in Linux system
CN107329892A (en) * 2017-06-07 2017-11-07 珠海市杰理科技股份有限公司 Drive method of testing, device, storage medium and its computer equipment
EP3859525A1 (en) * 2020-01-31 2021-08-04 Kove IP, LLC External memory as an extension to local primary memory
CN111274060A (en) * 2020-02-10 2020-06-12 广州虎牙科技有限公司 Method, device, equipment and storage medium for determining memory abnormity
CN113010279A (en) * 2021-02-20 2021-06-22 北京字节跳动网络技术有限公司 Application program process processing method and device for mobile terminal and electronic equipment
CN113434288A (en) * 2021-06-16 2021-09-24 荣耀终端有限公司 Memory management method and electronic equipment

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
Scalable GPU Virtualization with Dynamic Sharing of Graphics Memory Space;M.Xue et al.;《IEEE Transactions on Parallel and Distributed》;20180801;第29卷(第8期);第1823-1836页 *
嵌入式图形系统μC/GUI 的动态内存分配的研究;杨少春 等;《计算机技术与发展》;20060831;第16卷(第8期);第91-93页 *

Also Published As

Publication number Publication date
CN116107922A (en) 2023-05-12
CN114020652A (en) 2022-02-08

Similar Documents

Publication Publication Date Title
CN114020652B (en) Application program management method and electronic equipment
US11803451B2 (en) Application exception recovery
US20240231890A1 (en) Memory management method and electronic device
EP3971818A1 (en) Picture processing method and apparatus
CN114489917B (en) Processing method, electronic device and readable storage medium for abnormal exit of application program
CN113973150B (en) Screen locking interface display method of electronic equipment and electronic equipment
CN115292199B (en) Video memory leakage processing method and related device
CN115525453A (en) Multi-screen collaborative interrupt processing method and electronic equipment
CN112732434A (en) Application management method and device
CN113412480B (en) Mounting processing method, mounting processing device, electronic equipment and computer readable storage medium
CN115686334A (en) Operation control method, electronic device and readable storage medium
CN113138940A (en) Memory recovery method and device, electronic equipment and storage medium
CN116541180B (en) Memory allocation method, electronic equipment and storage medium
CN114490442B (en) File fragment adjusting method and electronic equipment
CN115017487B (en) Switching method for login account of electronic equipment and electronic equipment
CN116700818A (en) Application program running method and electronic equipment
CN113032130A (en) System exception handling method and device
CN117094876B (en) Data processing method, electronic device and readable storage medium
CN111813574A (en) Picture compression method and device, storage medium and electronic equipment
CN116361012B (en) Memory page allocation method and electronic equipment
CN116700817B (en) Application program running method and electronic equipment
CN117130767B (en) Method for recycling memory, electronic device and storage medium
CN115686338B (en) Screen splitting method and electronic equipment
CN117707715B (en) Application management method and electronic device
CN118092742A (en) Card data processing method, electronic device, electronic device and computer-readable storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CP03 Change of name, title or address
CP03 Change of name, title or address

Address after: Unit 3401, unit a, building 6, Shenye Zhongcheng, No. 8089, Hongli West Road, Donghai community, Xiangmihu street, Futian District, Shenzhen, Guangdong 518040

Patentee after: Honor Terminal Co.,Ltd.

Country or region after: China

Address before: 3401, unit a, building 6, Shenye Zhongcheng, No. 8089, Hongli West Road, Donghai community, Xiangmihu street, Futian District, Shenzhen, Guangdong

Patentee before: Honor Device Co.,Ltd.

Country or region before: China