Memory reclamation methods, apparatuses, computer-readable storage media, and electronic devices
By proactively checking memory usage after the browser starts and gradually reclaiming memory based on page browsing time, the issues of lagging browser memory management and abnormal exits are resolved, improving user experience and memory management efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-14
- Publication Date
- 2026-03-06
AI Technical Summary
In existing browser memory management solutions, the memory reclamation mechanism is passive and lagging, resulting in a poor user experience when memory is abnormal. Furthermore, it cannot actively detect memory out-of-bounds or wild pointer abnormalities, causing the browser to lag or crash.
After the target application starts, memory usage information is obtained through proactive memory checking logic to determine whether there are any abnormalities in system memory usage. The occupied memory is gradually reclaimed based on the browsing time of the running page, and memory reclamation is triggered reasonably in combination with passive system callback notifications.
It improves memory management efficiency, reduces browser lag, enhances user experience, prevents abnormal browser exits, and provides a more granular memory reclamation mechanism.
Smart Images

Figure CN115794664B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of Internet technology, and more specifically, to a memory reclamation method, apparatus, computer-readable storage medium, and electronic device. Background Technology
[0002] With societal progress and the development of the internet, more and more users are accessing the information and data they need online. Browsing web pages has become a frequent activity for users. However, users often encounter problems due to abnormal browser memory usage, such as excessive memory consumption leading to blank screens or browser lag.
[0003] In some solutions, existing browsers passively trigger memory reclamation when memory usage is high, only initiating the reclamation mechanism when memory consumption is excessive. This approach is slow or may not trigger reclamation at all, leading to abnormal browser exits. Furthermore, even when reclamation is triggered, the granularity of memory resource reclamation is coarse, often reclaiming all cached webpage resources at once. This means that when users revisit webpages, the browser reloads the pages, resulting in slower browser response times. Therefore, current solutions are inefficient in memory reclamation management when browser memory usage is abnormal, leading to a poor user experience. Summary of the Invention
[0004] The main objective of this application is to provide a memory reclamation method, apparatus, computer-readable storage medium, and electronic device to solve the problem of low efficiency and poor user experience in memory reclamation management when browser memory malfunctions in the prior art.
[0005] According to one aspect of the present invention, a memory reclamation method is provided, comprising: when a target application has been started, executing memory check logic, wherein the memory check logic refers to logic for obtaining memory usage information of the target application at least when the target application has just started or when the target application has been running for a target time period, wherein the memory usage information refers to the system memory usage of the target application during runtime; determining whether the target application has system memory usage anomalies based on the memory usage information of the target application; and, if the target application has system memory usage anomalies, reclaiming the memory occupied by the running pages of the target application sequentially based on the browsing time of the running pages of the target application.
[0006] Optionally, when the target application has been started, the memory check logic is executed, including: when the target application has been started, generating a callback interface, using the callback interface to call and execute the memory check logic; when the target application has been started, obtaining the target time period, and executing the memory check logic periodically according to the target time period; when the target application has been started and a predetermined operation is detected, executing the memory check logic, wherein the predetermined operation includes at least a selection operation on the running page of the target application.
[0007] Optionally, determining whether the target application has abnormal system memory usage based on the memory usage information of the target application includes: obtaining the total system memory; determining the usage corresponding to the memory usage information of the target application during runtime, wherein the usage refers to the usage of the total system memory occupied by the target application during runtime; and determining whether the target application has abnormal system memory usage based on the usage.
[0008] Optionally, determining whether the target application has abnormal system memory usage based on the usage includes: determining that the target application does not have abnormal system memory usage when the usage is less than a first usage; determining that the target application has abnormal system memory usage and assigning an abnormality level of a first abnormality level when the usage is greater than or equal to the first usage and less than a second usage; and determining that the target application has abnormal system memory usage and assigning an abnormality level of a second abnormality level when the usage is greater than or equal to the second usage, wherein the degree of abnormality of the first abnormality level is less than the degree of abnormality of the second abnormality level.
[0009] Optionally, according to the browsing time of the running pages of the target application, the memory occupied by the running pages of the target application is reclaimed sequentially, including: sorting the browsing times of the running pages of the target application in a predetermined order to construct a first queue, wherein one element in the first queue corresponds to page-related information of one running page, and the browsing time of the running page corresponding to the Nth element is earlier than the browsing time of the running page corresponding to the (N-1)th element; constructing a second queue according to the first queue, wherein at least one element in the second queue corresponds to page-related information of one running page; and reclaiming the memory occupied by the elements in the second queue sequentially from the tail of the queue to the head of the queue.
[0010] Optionally, constructing a second queue based on the first queue includes: obtaining first page-related information and second page-related information of target elements in the first queue, wherein the first page-related information refers to page-related information corresponding to the non-visible area of the target running page corresponding to the target element, and the second page-related information refers to page-related information corresponding to the visible area of the target running page corresponding to the target element, wherein the visible area refers to the area of the target running page displaying a predetermined identifier; and constructing the second queue by adopting the order of the Nth element corresponding to the first page-related information and the (N-1)th element corresponding to the second page-related information.
[0011] Optionally, the occupied memory of the elements in the second queue is reclaimed sequentially from the tail of the queue to the head of the queue, including: obtaining all the elements in the second queue; storing the elements in the second queue whose occupied memory needs to be reclaimed into a third queue in sequence to obtain the third queue; and reclaiming the occupied memory of the elements in the third queue in sequence from the tail of the queue to the head of the queue.
[0012] Optionally, the occupied memory of elements in the third queue is reclaimed sequentially from the tail to the head of the queue, including: determining whether the page-related information corresponding to the last element in the third queue has a non-zero value; if the page-related information corresponding to the last element in the third queue does not have a non-zero value, delaying the reclamation of the occupied memory of the page-related information corresponding to the last element in the third queue; if the page-related information corresponding to the last element in the third queue has a non-zero value, taking the last element in the third queue as the first element of the fourth queue to obtain the fourth queue, and not reclaiming the occupied memory of all elements in the fourth queue; and reclaiming the occupied memory of all elements in the fourth queue when it is detected that the target application has been closed.
[0013] According to another aspect of the present invention, a memory reclamation apparatus is also provided, comprising: an execution unit, configured to execute memory check logic when a target application has been started, the memory check logic referring to logic for obtaining memory usage information of the target application at least when the target application has just started or when the target application has been running for a target time period, the memory usage information referring to the system memory usage of the target application during runtime; a determination unit, configured to determine whether the target application has an abnormal system memory usage based on the memory usage information of the target application; and a reclamation unit, configured to, when the target application has an abnormal system memory usage, sequentially reclaim the memory occupied by the running page of the target application according to the browsing time of the running page of the target application.
[0014] According to another aspect of the present invention, a computer-readable storage medium is also provided, the computer-readable storage medium including a stored program, wherein the program executes any one of the methods described.
[0015] According to another aspect of the present invention, an electronic device is also provided, comprising: one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs include methods for performing any one of the methods described.
[0016] In this embodiment of the invention, firstly, with the target application already running, memory check logic is executed. Then, based on the target application's memory usage information, it is determined whether the target application has any abnormal system memory usage. Finally, if the target application has abnormal system memory usage, the memory occupied by the target application's running pages is reclaimed sequentially based on the browsing time of the running pages. This solution proactively checks the target application's memory usage information to determine if there are any abnormal system memory usages, and reclaims memory according to the browsing time of the running pages. This allows for gradual memory reclamation, thereby improving the efficiency of memory checks and enhancing the user experience. Attached Figure Description
[0017] The accompanying drawings, which form part of this application, are used to provide a further understanding of this application. The illustrative embodiments and descriptions of this application are used to explain this application and do not constitute an undue limitation of this application. In the drawings:
[0018] Figure 1 The diagram illustrates the process of memory reclamation in some schemes;
[0019] Figure 2 A schematic flowchart of a memory reclamation method according to an embodiment of this application is shown;
[0020] Figure 3 A schematic diagram of a memory reclamation device according to an embodiment of this application is shown;
[0021] Figure 4 A flowchart illustrating another memory reclamation method according to an embodiment of this application is shown. Detailed Implementation
[0022] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.
[0023] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0024] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate for the embodiments of this application described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0025] It should be understood that when an element (such as a layer, film, region, or substrate) is described as being "on" another element, the element may be directly on the other element, or there may be an intermediate element present. Furthermore, in the specification and claims, when an element is described as being "connected" to another element, the element may be "directly connected" to the other element, or "connected" to the other element via a third element.
[0026] For ease of description, the following explains some of the nouns or terms used in the embodiments of this application:
[0027] Excessive memory usage (insufficient memory): This refers to a situation where the client requests too much memory, potentially leading to insufficient memory on the client side. It is generally caused by factors such as excessive memory allocation, memory leaks, resource overloading, and pointer exceptions.
[0028] Webpage caching: For browsers, webpage caching involves copying and storing a previously requested webpage resource (such as HTML pages, images, and JavaScript data) in the browser. Recently accessed pages have more resources stored in memory. When a user revisits a historical webpage, the browser doesn't download the page again but directly uses the locally cached version. The advantage of this technique is that it improves webpage loading speed, thus enhancing the user experience; the disadvantage is that it consumes memory or disk storage space, slowing down the computer's performance.
[0029] Memory out of bounds: The browser requests a block of memory from the operating system, but when using this memory, the browser exceeds the scope of the requested memory.
[0030] Dangling pointer: When the first module in the browser requests a block of memory from the operating system, and the second module also uses that memory area, and the first module releases the memory without notifying the second module in time, the second module will use the memory area that has been released by the first module. At this time, the operating system will throw a dangling pointer exception and exit the browser directly.
[0031] Users often encounter problems when using a browser, such as being unable to browse web pages normally due to abnormal browser memory usage, resulting in a blank webpage, browser lag or even freezing, memory overflow, and abnormal browser exit.
[0032] Regarding excessive memory usage leading to browser crashes, existing browser management solutions based on open-source browser (e.g., Blink) frameworks lack two key advantages. First, they lack a practical solution for proactively detecting excessive memory usage. Detection only occurs when memory anomalies arise, which is delayed. In some operating systems, this is even worse, where insufficient memory is not detected, causing the browser to crash and exit abruptly. Second, they fail to gradually reclaim cached historical webpage resources, instead reclaiming all cached resources at once. Currently, there is no truly feasible solution for browser crashes caused by memory overflow.
[0033] In some solutions, the target application's memory management scheme has significant flaws, leading to prominent memory anomalies. The existing memory management process, such as... Figure 1As shown, the operating system defines memory-related callback notifications, which trigger a memory reclamation mechanism when memory usage is too high, releasing all cached resources of running pages and thus freeing up memory resources.
[0034] The current memory management process is as follows:
[0035] (1) When the target application starts, the target application will register a callback interface with the operating system to indicate excessive memory usage. When the target application uses too much memory, the general operating system will call this interface (but in some non-standard operating systems, such as Tongxin UOS, there is no such callback notification) to notify the target application to release memory.
[0036] (2) After receiving the operating system's memory release notification, the target application will immediately release all cached historical running pages, and the memory release granularity is very large.
[0037] (3) It will directly release the memory resources corresponding to the running page. It will release all cached resources stored in memory for all historical running pages that are not currently displayed. Cached resources include: decoded data of images of historical running pages, DOM tree structure, layout tree structure, PaintLayer tree structure parsed from historical running pages, drawing data used for screen rendering and display, font cache, memory resources occupied by software or hardware renderers, memory resources held by the corresponding V8 objects, etc.
[0038] Therefore, current memory management methods have the following drawbacks:
[0039] (1) The memory reclamation mechanism has a relatively simple triggering condition: Existing target applications trigger a memory reclamation mechanism when memory usage is high, which relies entirely on the operating system's callback notification when memory usage is high. This triggering mechanism is passive. The operating system's callback is generally quite delayed, and in some non-standard operating systems (such as Tongxin UOS), the system's callback notification to the target application when memory usage is high has been removed. This can lead to the target application's memory reclamation mechanism not being triggered in a timely manner, or even not being triggered at all, resulting in memory shortage issues. Moreover, current solutions are all passive triggering mechanisms and do not have an active mechanism to trigger reclamation when memory usage is high. When memory usage is too high, the target application may experience lag or even freeze, and the user will not be able to operate the target application. At the same time, excessive memory usage may cause the target application to exit abnormally.
[0040] (2) Coarse-grained memory reclamation: Currently, in applications with high memory usage, the granularity of memory reclamation is coarse, reclaiming all cached resources of historical running pages at once. This coarse-grained reclamation method is simple to implement, but it affects the user's web browsing experience. For example, when a user performs forward or backward operations, the target application will reload the running page, resulting in a slow response; in scenarios where users browse multiple tabs, switching to other tabs will also cause the target application to reload the running page, resulting in a slow response. When the granularity of memory reclamation is coarse, the target application may lag or even freeze, making it unusable for the user.
[0041] (3) Inability to proactively detect memory out-of-bounds or dangling pointer exceptions: Existing memory management schemes for target applications cannot detect memory out-of-bounds or dangling pointer exceptions. If a memory out-of-bounds or dangling pointer exception occurs while the user is browsing the target application's page, the target application can only exit abnormally, severely impacting the user experience. Furthermore, for such issues, the call stack information at the time of the exception does not reflect the problematic code logic; it generally indicates a memory problem occurred in previously executed code logic, making it difficult for developers to analyze and locate code issues. When a memory out-of-bounds or dangling pointer exception occurs, the user cannot operate the target application, and the target application will exit abnormally.
[0042] As mentioned in the background section, existing technologies suffer from low efficiency in memory reclamation management when browser memory malfunctions, resulting in a poor user experience. To address these issues, this application provides a typical embodiment of a memory reclamation method, apparatus, computer-readable storage medium, and electronic device.
[0043] According to an embodiment of this application, a memory reclamation method is provided.
[0044] Figure 2 This is a flowchart of a memory reclamation method according to an embodiment of this application. For example... Figure 2 As shown, the method includes the following steps:
[0045] Step S101: If the target application has been started, execute memory check logic. The memory check logic refers to the logic of obtaining the memory usage information of the target application at least when the target application has just started or when the target application has been running for a target period of time. The memory usage information refers to the system memory usage of the target application during runtime.
[0046] Specifically, when using the target application to open a web game or watch a high-definition video, the target application will consume more memory. However, when using the target application to view text materials, the memory consumed will be less than that consumed when opening a web game or watching a high-definition video.
[0047] There can be various conditions for executing memory check logic. For example, the memory check logic may be invoked using a callback interface, invoked after the target application has been running for a period of time, or executed when a change is detected in the target application's running page. Of course, it is not limited to the above situations; those skilled in the art can execute memory check logic based on any other feasible conditions.
[0048] When the target application begins browsing a running page, it loads the opened running page and adds it to the webpage cache. Furthermore, as the user browses the running page, they may occasionally interact with it (e.g., click or select); the target application also records the time of the last interaction with the running page in the webpage cache. The webpage cache can be configured to cache up to 20 historical running page resources, with no specific limit, selectable based on actual needs. This improves the user's browsing experience and helps avoid excessive memory usage to some extent.
[0049] Step S102: Based on the memory usage information of the target application, determine whether the target application has any abnormal system memory usage.
[0050] Specifically, memory usage information can be physical memory usage information or virtual memory usage information. It is possible to determine whether the target application has abnormal system memory usage based solely on physical memory usage information, or based solely on virtual memory usage information, or based solely on both physical and virtual memory usage information.
[0051] The above step S102 uses an active method to check memory usage. Therefore, determining whether the target application has abnormal system memory usage based on memory usage information is also an active check. This can also check in advance whether the target application has abnormal system memory usage.
[0052] Step S103: If the target application has abnormal system memory usage, the memory occupied by the target application's running page is reclaimed sequentially according to the browsing time of the running page of the target application.
[0053] The method described above first executes memory check logic after the target application has started. Then, based on the target application's memory usage information, it determines whether there are any abnormal system memory usages. Finally, if abnormal system memory usage is found, the memory used by the target application's running pages is reclaimed sequentially based on their browsing time. This approach proactively checks the target application's memory usage information to determine if there are any abnormal system memory usages, and reclaims memory based on the browsing time of the target application's running pages. This gradual memory reclamation improves memory check efficiency and enhances the user experience.
[0054] In one embodiment of this application, when the target application has been started, memory check logic is executed, specifically including the following steps:
[0055] Step S201: If the target application has been started, generate a callback interface, and use the callback interface to call and execute the memory check logic.
[0056] Specifically, once the target application is running, a callback interface can be registered with the operating system to be triggered when memory usage is high. Generally, when the target application is using a lot of memory, the operating system will use this interface to notify the target application to release memory.
[0057] The operating system has a system callback notification when memory usage is high. When the target application starts, it registers a callback interface with the operating system. Under normal circumstances, when memory usage is high, it will receive a system callback notification, and the target application will then execute the corresponding memory check logic.
[0058] Step S202: If the target application has been started, obtain the target time period and execute the memory check logic periodically according to the target time period.
[0059] Specifically, once the target application is running, it starts a timer for memory checks. Initially, since the application uses relatively little memory, the timer interval can be set to 10 seconds, executing the memory check logic every 10 seconds. This allows for proactive execution of the memory check logic through a timed approach. Under normal circumstances, the memory check logic executes every 10 seconds; when memory usage is high, it executes every 5 seconds; and when memory usage is extremely high, it executes every 1 second.
[0060] More specifically, the target time period is not limited to the aforementioned 10 seconds and can be set according to other factors. For example, an appropriate target time period can be selected based on the type of the target application. Furthermore, the target time period can be changed; after the target application has been running for a period of time, the target time period can be shortened to achieve a higher frequency of memory check logic execution. The frequency of memory checks can be increased or decreased based on actual memory usage.
[0061] Step S203: If the target application has been started and a predetermined operation is detected, the memory check logic is executed. The predetermined operation includes at least a selection operation on the running page of the target application.
[0062] Specifically, memory usage can increase when a user interacts with the running page, or when the internal logic of the running page changes; therefore, memory check logic can be executed in both of these scenarios. Generally, user interaction with the running page may cause an increase in memory usage, hence the inclusion of memory check logic in this scenario. Since the internal logic of the running page controls changes to its content, it may also cause an increase in memory usage, thus memory check logic can be executed in this scenario as well.
[0063] Specifically, in steps S201 to S203 above, step S201 is a passively triggered memory check logic, while steps S202 and S203 are active triggered memory check logic. This allows for compatibility with both active and passive triggered memory check logic, enabling the execution of memory check logic in various situations. This solution not only responds to the operating system's memory check and reclamation callback notifications but also adds multiple active memory check and reclamation mechanisms; it reasonably increases the triggering timing of memory check and reclamation and allows for increasing or decreasing the frequency of active memory checks based on actual memory usage. This effectively reduces abnormal situations with excessive memory usage and also reasonably balances the CPU usage of memory checks.
[0064] In one alternative approach, the conditions for executing memory check logic can be determined based on the content of the running page. For example, when the running page is a special webpage, the memory check logic can be executed every 5 seconds, and when the running page is a regular webpage, the memory check logic can be executed every 30 seconds. A special webpage refers to a page containing web games or high-definition videos, while a regular webpage refers to a page containing only text or images, which consumes less memory.
[0065] In one specific embodiment, if multiple conditions are triggered simultaneously, the memory check logic can be executed only once instead of multiple times, thus avoiding continuous responses that could cause the target application to malfunction.
[0066] Whether a target application has abnormal system memory usage can be determined based on the target application's memory usage, which in turn can be determined based on the total system memory. To further accurately determine whether a target application has abnormal system memory usage, in another embodiment of this application, determining whether the target application has abnormal system memory usage based on the aforementioned memory usage information of the target application specifically includes the following steps:
[0067] Step S301: Obtain the total system memory.
[0068] Step S302: Determine the usage amount corresponding to the memory usage information of the target application during runtime. The usage amount refers to the total system memory usage of the target application during runtime.
[0069] Step S303: Based on the above usage, determine whether the target application has any abnormal system memory usage.
[0070] Specifically, during the memory check process, the current operating system's memory usage can be obtained first, including: total system physical memory, used physical memory, remaining available physical memory, total system virtual memory, used virtual memory, remaining available virtual memory, etc. It can also obtain the target application's memory usage, including: the amount of physical memory used, the amount of virtual memory used, etc.
[0071] In practical applications, the physical memory of low-end computers (or mobile phones) and high-end computers (or mobile phones) is different. Low-end computers use 32-bit memory, while high-end computers use 64-bit memory. The operating system can manage the memory usage of the entire target application. Low-end mobile phones use 4GB of memory, while high-end mobile phones use 16GB of memory.
[0072] To determine whether a target application has abnormal system memory usage, different anomalies can be identified based on different usage levels. Different usage levels correspond to different anomalies, and some usage levels do not exhibit anomalies, indicating the target application is running normally. To further accurately determine whether the target application has abnormal system memory usage and, in cases of abnormal system memory usage, accurately determine the anomaly level so that subsequent memory adjustment logic can be adjusted based on the anomaly level, in a specific embodiment of this application, determining whether the target application has abnormal system memory usage based on the aforementioned usage levels includes: if the aforementioned usage is less than a first usage level, determining that the target application does not have abnormal system memory usage; if the aforementioned usage is greater than or equal to the first usage level and less than a second usage level, determining that the target application has abnormal system memory usage and identifying the anomaly level as a first anomaly level; if the aforementioned usage is greater than or equal to the second usage level, determining that the target application has abnormal system memory usage and identifying the anomaly level as a second anomaly level, wherein the anomaly severity of the first anomaly level is less than the anomaly severity of the second anomaly level.
[0073] Optionally, the first usage can be 500M, and the second usage can be 800M. Of course, these are not limited to the above situations. Those skilled in the art can also choose appropriate first and second usages based on actual circumstances. When the target application's memory usage is less than 500M, the corresponding operating system's memory usage is less than 50%, indicating that the target application's memory usage is within the normal range. The timer interval for actively checking memory can be set to 10 seconds, and the cache of historical running pages in the webpage cache can be left unreleased. When the target application's memory usage reaches 500M, the corresponding operating system's memory usage exceeds 50%, indicating that the current target application's memory usage is too high, with an anomaly level of the first anomaly level. The timer interval for actively checking memory can be set to 5 seconds, and the cache of historical running pages in the webpage cache can be released. When the target application's memory usage reaches 800M, the corresponding operating system's memory usage exceeds 70%, indicating that the current target application's memory usage is exceptionally high, with an anomaly level of the second anomaly level. The timer interval for actively checking memory can be set to 1 second, and the cache of historical running pages in the webpage cache can be released.
[0074] To reclaim the memory occupied by the running pages of the target application, the memory can be reclaimed gradually according to the browsing order of the target application's cached historical running pages. This avoids a one-time reclamation, ensuring that some running pages' memory is not reclaimed while the user is browsing, thus improving the user experience. Furthermore, in this solution, the memory occupied by the running page with the furthest browsing time is also reclaimed gradually, further refining the reclamation mechanism and ensuring more efficient memory reclamation. In another embodiment of this application, the memory occupied by the running pages of the target application is reclaimed sequentially according to their browsing time, specifically including the following steps:
[0075] Step S401: Sort the browsing times of the running pages of the target application in a predetermined order to construct a first queue, wherein one element in the first queue corresponds to page-related information of the running page, and the browsing time of the running page corresponding to the Nth element is earlier than the browsing time of the running page corresponding to the (N-1)th element.
[0076] Specifically, the order of priority can be sorted from most recent to oldest, so that when reclaiming webpage cache later, the cache of the webpages that were viewed the oldest can be reclaimed first.
[0077] Page-related information may include: decoded data of images used to run the page, DOM tree structure, layout tree structure, PaintLayer tree structure parsed by the page, drawing data used for screen rendering and display, font cache, memory resources occupied by software or hardware renderers, and memory resources held by the corresponding V8 objects, etc.
[0078] Step S402: Based on the first queue, construct a second queue, wherein at least one element in the second queue corresponds to page-related information of the running page.
[0079] Specifically, upon receiving a memory release instruction, the following two steps can be executed: First, the release call stack corresponding to the elements in the first queue is recorded; second, the memory area to be released is cleaned up. That is, the memory of the elements in the first queue is not released directly, but the memory of the elements in the first queue is mounted in the second queue. The maximum length of the second queue can be 50, 100, or any other feasible queue length.
[0080] Given a first queue, the order in which page-related information in the running pages requiring memory reclamation is further refined. This means that memory reclamation is performed based on the page-related information in the second queue, further refining the reclamation mechanism and ensuring more efficient memory reclamation of running pages. In one specific embodiment of this application, constructing a second queue based on the first queue includes: obtaining first and second page-related information of target elements in the first queue. The first page-related information refers to the page-related information corresponding to the non-visible area of the target running page corresponding to the target element, and the second page-related information refers to the page-related information corresponding to the visible area of the target running page corresponding to the target element. The visible area refers to the area where the target running page displays a predetermined identifier. The second queue is constructed using the order where the Nth element corresponds to the first page-related information and the (N-1)th element corresponds to the second page-related information.
[0081] Specifically, the elements in the second queue are actually child elements of the elements in the first queue. For example, if the first queue contains three elements: element A, element B, and element C, each containing corresponding page-related information, and element A corresponds to the page with the furthest browsing time, then element A from the first queue can be used to construct the second queue. The second queue can also contain two elements: element A1 and element A2. Element A1 corresponds to the non-visible area, and element A2 corresponds to the visible area. This allows for the reclaiming of memory occupied by the non-visible area first, followed by the reclaiming of memory occupied by the visible area. If memory errors still exist after reclaiming the memory occupied by element A, then the memory occupied by element B can be released, and element B can be used to construct the second queue.
[0082] The information related to the first page may include: decoded image data of the running page, memory resources held by the corresponding V8 object, font cache, the DOM tree structure, layout tree structure, and PaintLayer tree structure parsed for the running page, memory resources occupied by the software or hardware renderer, and drawing data used for screen rendering and display, etc.
[0083] Step S403: Reclaim the occupied memory of the elements in the second queue in the order from the tail of the queue to the head of the queue.
[0084] Specifically, in steps S401 to S403 above, each time the webpage cache (the memory already occupied by the running page) is reclaimed, a memory check logic is re-executed to determine if there are any abnormal system memory usage situations. If, after all the webpage caches of historical running pages have been released, the system memory usage is still high, the webpage cache of the currently running page can be released gradually according to priority. Of course, the webpage cache of historical running pages can also be released gradually according to the page-related information corresponding to the elements on the page.
[0085] After each instance of reclaiming the memory occupied by an element in the second queue, a memory check is performed to confirm whether the target application still has any abnormal memory usage. If so, memory reclamation continues until the target application's memory usage is within a normal range (i.e., less than the first usage), at which point memory reclamation stops.
[0086] Generally, the older a page is, the lower the probability that a user will visit it again. Therefore, the webpage cache is sorted according to the browsing history, and the oldest webpage cache is deleted first. After deleting a webpage cache, a memory check is performed. This enables reasonable and accurate reclamation of webpage cache based on the actual memory usage, thus maximizing the user's browsing experience while reasonably reducing memory usage.
[0087] In another embodiment of this application, the occupied memory of the elements in the second queue is reclaimed sequentially from the tail of the queue to the head of the queue, specifically including the following steps:
[0088] Step S4031: Obtain all elements in the second queue mentioned above;
[0089] Step S4032: The elements in the second queue that need to be reclaimed from the memory are sequentially stored in the third queue to obtain the third queue.
[0090] Step S4033: Reclaim the occupied memory of the elements in the third queue in the order from the tail of the queue to the head of the queue.
[0091] In steps S4031 to S4033 above, when a release instruction is received from the application layer, the occupied memory of the elements in the second queue will not be released immediately. Instead, a new queue, namely the third queue, will be constructed. The third queue is the release queue, so that subsequent release can be delayed instead of being released immediately, so as to facilitate the developers to perform exception analysis.
[0092] In the event of a memory out-of-bounds error or a dangling pointer, the memory is not immediately released. Instead, the elements in the third queue are used as elements in the fourth queue, thus creating an exception memory queue (the fourth queue). The memory occupied by all elements in the fourth queue is only reclaimed when the target application exits. This prevents the target application from exiting abnormally. The specific implementation of step S4033 includes: reclaiming the memory occupied by elements in the third queue sequentially from the tail to the head, including: determining whether the page-related information corresponding to the last element in the third queue has a non-zero value; delaying the reclamation of the memory occupied by the page-related information corresponding to the last element in the third queue if the page-related information corresponding to the last element in the third queue does not have a non-zero value; if the page-related information corresponding to the last element in the third queue has a non-zero value, using the last element in the third queue as the first element of the fourth queue to obtain the fourth queue, and not reclaiming the memory occupied by all elements in the fourth queue; and reclaiming the memory occupied by all elements in the fourth queue when the target application is detected to have closed.
[0093] Specifically, when the page-related information corresponding to the last element in the third queue does not have a non-zero value, some solutions use direct memory reclamation, while this solution uses delayed reclamation. The delay time can be set according to the actual situation, such as 1 second or 2 seconds. In reality, the delayed release function is invisible to users, but developers can reproduce the memory reclamation scenario to facilitate anomaly analysis.
[0094] In this embodiment, the memory corresponding to the element to be released can be retrieved from the tail of the third queue. Before releasing it, the page-related information corresponding to the element can be checked for non-zero values to confirm whether there is a memory out-of-bounds error or a dangling pointer. If no memory out-of-bounds error or dangling pointer error exists, the corresponding memory can be released later. If a memory out-of-bounds error or dangling pointer error exists, a fourth queue is constructed, and the memory is released through the fourth queue. This embodiment can detect whether there is a memory out-of-bounds error or a dangling pointer error, and if such an error occurs, memory can be reclaimed according to the fourth queue. This can prevent the target application from exiting abnormally, thereby further improving the user experience.
[0095] In one specific embodiment, the recycling mechanism of this scheme is explained as follows:
[0096] The elements in the first queue include: A, B, and C, where A was viewed earlier than B, and B was viewed earlier than C.
[0097] When memory needs to be reclaimed, a second queue is constructed using element A from the first queue.
[0098] The elements in the second queue include: A1, A2, and A3, where A1 is the image information corresponding to the non-visible area, A2 is the text information corresponding to the non-visible area, and A3 is the text information corresponding to the visible area.
[0099] Upon receiving a recycling instruction, a third queue is constructed using elements from the second queue.
[0100] The elements in the third queue include A1 and A2. When the elements are in the third queue, the memory occupied by the elements has not yet been reclaimed.
[0101] Extract element A2 from the third queue and check if it contains a non-zero value. If no non-zero value exists, release the memory occupied by element A2 after a 5-second delay. If a non-zero value exists, construct the fourth queue.
[0102] The elements in the fourth queue include: A2;
[0103] If the target application is detected to be closed, reclaim the occupied memory of the element A2 in the fourth queue.
[0104] Specifically, in the event of a memory out-of-bounds error or a dangling pointer, the call stack information corresponding to that memory region can be reported to a remote server, facilitating developers' analysis and resolution of the memory anomaly. This embodiment implements the identification of memory out-of-bounds errors or dangling pointer anomalies. The target application will avoid this situation by not releasing the memory but adding it to a memory anomaly queue, releasing it when the target application exits. Furthermore, the call stack requesting the memory release is retained, and the corresponding information is automatically reported to a remote server, enabling developers to analyze and resolve the memory anomaly.
[0105] The above-described method of reclaiming memory using four queues enables a more granular memory reclamation mechanism.
[0106] In practical applications, the target application typically has robust management capabilities. After each memory reclamation, fragmented memory regions can be pieced together to address severe memory fragmentation. For instance, after prolonged operating system management, memory is reclaimed. To prevent small memory blocks from mistakenly triggering memory checks, fragmented memory can be pieced together. This results in a larger memory region for subsequent data caching. For example, if there are three memory regions, A, B, and C, and smaller regions are released—0.2MB in region A, 0.5MB in region B, and 0.7MB in region C—piecing together these smaller blocks yields a larger memory region.
[0107] The solution proposed in this application can not only accurately detect situations with excessive memory usage in advance, but also sort the memory occupied by running pages in the webpage cache (running page memory resources) according to the browsing time of the running pages, and gradually reclaim the memory occupied by the running pages with the oldest browsing time according to the actual memory of the system. This can minimize the abnormal problem of excessive memory usage, and can also automatically detect pointer out-of-bounds (memory out-of-bounds) or wild pointer situations.
[0108] This application's adaptive and proactive memory reclamation scheme for target applications can proactively trigger the memory reclamation mechanism, and the target application can adaptively adjust the frequency of memory checks based on the operating system's memory usage. Furthermore, during memory reclamation, running pages can be sorted according to their browsing time, releasing the memory of the oldest browsing page first. The number of running pages to be released is also determined based on the actual memory situation of the operating system. Additionally, it can check for memory out-of-bounds errors or dangling pointers, which not only facilitates developers in analyzing and resolving such issues but also provides exception protection to prevent the target application from abnormally exiting, thus improving the user experience.
[0109] It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases the steps shown or described may be executed in a different order than that shown here.
[0110] This application also provides a memory reclamation device. It should be noted that the memory reclamation device of this application can be used to execute the memory reclamation method provided in this application. The memory reclamation device provided in this application is described below.
[0111] Figure 3 This is a schematic diagram of a memory reclamation device according to an embodiment of this application. Figure 3 As shown, the device includes:
[0112] The execution unit 10 is used to execute memory check logic when the target application has been started. The memory check logic refers to the logic of obtaining the memory usage information of the target application at least when the target application has just started or when the target application has been running for a target period of time. The memory usage information refers to the usage of system memory by the target application during runtime.
[0113] The determining unit 20 is used to determine whether the target application has abnormal system memory usage based on the memory usage information of the target application.
[0114] The recycling unit 30 is used to reclaim the memory occupied by the running page of the target application in sequence according to the browsing time of the running page of the target application when the target application has abnormal system memory usage.
[0115] In the aforementioned device, the execution unit performs memory check logic when the target application is already running. The determination unit determines whether the target application has any abnormal system memory usage based on its memory usage information. If the target application has abnormal system memory usage, the memory reclamation unit reclaims the memory occupied by the target application's running pages sequentially based on the browsing time of the running pages. This solution proactively checks the target application's memory usage information to determine if there are any abnormal system memory usages, and reclaims memory according to the browsing time of the running pages. This allows for gradual memory reclamation, thereby improving the efficiency of memory checks and enhancing the user experience.
[0116] In one embodiment of this application, the execution unit includes a first execution module, a second execution module, and a third execution module, and the functions of each module are as follows:
[0117] The first execution module is used to generate a callback interface when the target application has been started, and to call and execute the memory check logic using the callback interface.
[0118] The second execution module is used to obtain the target time period when the target application has been started, and to execute the memory check logic periodically according to the target time period.
[0119] The third execution module is used to execute the memory check logic when the target application has been started and a predetermined operation is detected. The predetermined operation includes at least a selection operation on the running page of the target application.
[0120] Specifically, the first execution module, second execution module, and third execution module described above have different mechanisms. The first execution module passively triggers memory check logic, while the second and third execution modules actively trigger memory check logic. This ensures compatibility with both active and passive triggering of memory check logic, allowing the memory check logic to be executed in various situations. This solution not only responds to the operating system's memory check and reclamation callback notifications but also adds multiple active memory check and reclamation mechanisms. It reasonably increases the triggering timing of memory check and reclamation and allows for increasing or decreasing the frequency of active memory checks based on actual memory usage. This effectively reduces abnormal situations with excessive memory usage and also reasonably balances the CPU usage of memory checks.
[0121] Whether a target application has abnormal system memory usage can be determined based on the target application's memory usage, which in turn can be determined based on the total system memory. To further accurately determine whether a target application has abnormal system memory usage, in another embodiment of this application, the determining unit includes an acquisition module, a first determining module, and a second determining module. The acquisition module is used to determine the total system memory. The first determining module is used to determine the usage corresponding to the memory usage information of the target application during runtime. The usage refers to the usage of the total system memory occupied by the target application during runtime. The second determining module is used to determine whether the target application has abnormal system memory usage based on the usage.
[0122] To determine whether a target application has abnormal system memory usage, different abnormal situations can be identified based on different usage levels. Different usage levels correspond to different abnormal situations, and some usage levels do not exhibit abnormalities, indicating the target application is running normally. To further accurately determine whether the target application has abnormal system memory usage and, in cases of abnormal system memory usage, accurately determine the abnormality level to ensure that subsequent memory adjustment logic can be adjusted based on the abnormality level, in a specific embodiment of this application, the second determining module includes a first determining submodule, a second determining submodule, and a third determining submodule. The first determining submodule is used to determine that the target application does not have abnormal system memory usage when the aforementioned usage is less than a first usage level. The second determining submodule is used to determine that the target application has abnormal system memory usage when the aforementioned usage is greater than or equal to the first usage level and less than the second usage level, and determines the abnormality level as a first abnormality level. The third determining submodule is used to determine that the target application has abnormal system memory usage when the aforementioned usage is greater than or equal to the second usage level, and determines the abnormality level as a second abnormality level. The abnormality severity of the first abnormality level is less than that of the second abnormality level.
[0123] To reclaim the memory occupied by the running pages of the target application, the memory can be reclaimed gradually according to the browsing order of the target application's cached historical running pages. This is a gradual reclamation of the memory occupied by the running pages of the target application, rather than a one-time reclamation. This ensures that while the user is browsing the running pages, some of the memory occupied by the running pages has not been reclaimed, allowing the user to continue browsing and further improving the user experience. Furthermore, in this solution, the memory occupied by the running pages with the longest browsing time is also reclaimed gradually, further ensuring a more granular reclamation mechanism and thus guaranteeing more efficient reclamation of the memory occupied by running pages. In another embodiment of this application, the reclamation unit includes a first construction module, a second construction module, and a reclamation module, with the following functions:
[0124] The first construction module is used to sort the browsing time of the running page of the target application in a predetermined order to construct a first queue, wherein one element of the first queue corresponds to the page-related information of the running page, and the browsing time of the running page corresponding to the Nth element is earlier than the browsing time of the running page corresponding to the N-1th element.
[0125] The second construction module is used to construct a second queue based on the first queue, wherein at least one element in the second queue corresponds to page-related information of the running page.
[0126] Given a first queue, the order in which page-related information in the running pages that need memory reclamation is performed can be further refined. This means that memory reclamation is based on the page-related information in the second queue, further refining the reclamation mechanism and ensuring more efficient memory reclamation of running pages. In one specific embodiment of this application, the second construction module includes a first acquisition submodule and a construction submodule. The first acquisition submodule acquires the first page-related information and the second page-related information of the target elements in the first queue. The first page-related information refers to the page-related information corresponding to the non-visible area of the target running page corresponding to the target element, and the second page-related information refers to the page-related information corresponding to the visible area of the target running page corresponding to the target element. The visible area refers to the area where the target running page displays a predetermined identifier. The construction submodule constructs the second queue using the order of the Nth element corresponding to the first page-related information and the (N-1)th element corresponding to the second page-related information.
[0127] The recycling module is used to reclaim the occupied memory of the elements in the second queue in the order from the tail of the queue to the head of the queue.
[0128] Specifically, in the first, second, and recycling modules mentioned above, each time the webpage cache (the memory already occupied by the running page) is recycled, a memory check logic is re-executed to determine if there are any abnormal system memory usage situations. If, after all the webpage caches of historical running pages have been released, the system memory usage is still high, the webpage cache of the currently running page can be released gradually according to priority. Of course, the webpage cache of historical running pages can also be released gradually according to the page-related information corresponding to the elements on the page.
[0129] In another embodiment of this application, the recycling module includes a second acquisition submodule, a construction submodule, and a recycling submodule. The second acquisition submodule is used to acquire all elements in the second queue. The construction submodule is used to sequentially store the elements in the second queue whose memory is to be recycled into a third queue to obtain the third queue. The recycling submodule is used to sequentially recycle the memory occupied by the elements in the third queue in the order from the tail of the queue to the head of the queue.
[0130] The recycling submodule is further configured to determine whether the page-related information corresponding to the last element in the third queue has a non-zero value; the recycling submodule is further configured to delay the recycling of the memory occupied by the page-related information corresponding to the last element in the third queue if the page-related information corresponding to the last element in the third queue does not have a non-zero value; the recycling submodule is further configured to, if the page-related information corresponding to the last element in the third queue has a non-zero value, take the last element in the third queue as the first element of the fourth queue to obtain the fourth queue, and not recycle the memory occupied by all elements in the fourth queue; the recycling submodule is further configured to recycle the memory occupied by all elements in the fourth queue if the target application is detected to have been closed.
[0131] In this embodiment, the memory corresponding to the element to be released can be retrieved from the tail of the second queue. Before releasing it, the page-related information corresponding to the element can be checked for non-zero values to confirm whether there is a memory out-of-bounds error or a dangling pointer. If no memory out-of-bounds error or dangling pointer error exists, the corresponding memory can be released later. If a memory out-of-bounds error or dangling pointer error exists, a third queue is constructed, and the memory is released through the third queue. This embodiment can detect whether there is a memory out-of-bounds error or a dangling pointer error, and if such an error occurs, memory can be reclaimed according to the third queue. This can prevent the target application from exiting abnormally, thereby further improving the user experience.
[0132] In the event of a memory out-of-bounds error or a dangling pointer, the memory is not immediately released. Instead, the elements in the second queue are used as elements in the third queue, thus creating an exception memory queue (the third queue). The memory occupied by all elements in the third queue is only reclaimed when the target application exits. This prevents the target application from exiting abnormally. The second reclamation submodule is also used to take the last element in the second queue as the first element in the third queue to obtain the third queue, without reclaiming the memory occupied by all elements in the third queue. The second reclamation submodule is also used to reclaim the memory occupied by all elements in the third queue when it is detected that the target application has been closed.
[0133] The aforementioned memory reclamation device includes a processor and a memory. The aforementioned execution unit, determination unit, and reclamation unit are all stored in the memory as program units, and the processor executes the aforementioned program units stored in the memory to achieve the corresponding functions.
[0134] The processor contains a kernel, which retrieves the corresponding program units from memory. One or more kernels can be configured, and adjusting kernel parameters can address the problem of low efficiency in memory reclamation management and poor user experience in current technologies when browser memory encounters abnormalities.
[0135] The memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0136] This invention provides a computer-readable storage medium storing a program that, when executed by a processor, implements the above-described memory reclamation method.
[0137] This invention provides a processor for running a program, wherein the program executes the memory reclamation method described above.
[0138] This application also provides an electronic device including one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs include methods for performing any of the above-described methods.
[0139] Step S101: If the target application has been started, execute memory check logic. The memory check logic refers to the logic of obtaining the memory usage information of the target application at least when the target application has just started or when the target application has been running for a target period of time. The memory usage information refers to the system memory usage of the target application during runtime.
[0140] Step S102: Based on the memory usage information of the target application, determine whether the target application has any abnormal system memory usage.
[0141] Step S103: If the target application has abnormal system memory usage, the memory occupied by the target application's running page is reclaimed sequentially according to the browsing time of the running page of the target application.
[0142] This invention provides a device including a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, it performs at least the following steps:
[0143] Step S101: If the target application has been started, execute memory check logic. The memory check logic refers to the logic of obtaining the memory usage information of the target application at least when the target application has just started or when the target application has been running for a target period of time. The memory usage information refers to the system memory usage of the target application during runtime.
[0144] Step S102: Based on the memory usage information of the target application, determine whether the target application has any abnormal system memory usage.
[0145] Step S103: If the target application has abnormal system memory usage, the memory occupied by the target application's running page is reclaimed sequentially according to the browsing time of the running page of the target application.
[0146] The devices mentioned in this article can be servers, PCs, tablets, mobile phones, etc.
[0147] This application also provides a computer program product, which, when executed on a data processing device, is suitable for executing an initialization program having at least the following method steps:
[0148] To enable those skilled in the art to better understand the technical solution of this application, the technical solution and technical effects of this application will be described below in conjunction with specific embodiments.
[0149] Example
[0150] This embodiment relates to a memory reclamation method, such as... Figure 4 As shown, it includes:
[0151] With the browser already running, start an active check timer, set a default interval, and trigger the detection mechanism periodically; also, trigger the detection mechanism based on system memory notifications, user interaction with the webpage, and changes to the webpage content.
[0152] Each time the detection mechanism is triggered, an active memory detection mechanism is initiated to obtain the current operating system memory usage and dynamically set the timer interval based on the memory usage.
[0153] Determine if memory usage is too high. If memory usage is too high, trigger webpage recycling. If memory usage is too low, perform a memory overflow check.
[0154] The webpage recycling mechanism is as follows: When a user opens a webpage, a webpage cache is added (a maximum of 20 historical webpages are cached; once this is exceeded, the oldest webpage cache is deleted); when a user interacts with a webpage, the browsing time of the webpage is recorded, and the webpage and browsing time are added to the webpage cache area. The webpage cache is sorted according to the historical browsing time, and the webpage cache with the oldest historical browsing time is deleted.
[0155] The deletion process and memory out-of-bounds check are as follows: Obtain the memory region to be released, clear the memory region to zero, and record the call stack information; add the memory region to the queue to be released, obtain the memory region to be released from the tail of the queue to be released, and check whether the memory region has a non-zero value;
[0156] If a non-zero value exists in the memory region, the call stack information is reported to the server for exception handling by staff; if no non-zero value exists in the memory region, memory release is delayed; and the program terminates.
[0157] In the above embodiments of the present invention, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0158] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units described above can be a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces, or indirect coupling or communication connection between units or modules, and may be electrical or other forms.
[0159] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0160] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0161] If the aforementioned integrated units are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0162] As can be seen from the above description, the embodiments of this application achieve the following technical effects:
[0163] 1) The memory reclamation method of this application first executes memory check logic when the target application is already running. Then, based on the memory usage information of the target application, it determines whether there are any abnormalities in system memory usage. Finally, if there are abnormalities in system memory usage, the memory occupied by the running pages of the target application is reclaimed sequentially according to the browsing time of the running pages. In this scheme, the memory usage information of the target application is actively checked to determine whether there are any abnormalities in system memory usage when the target application is already running. Furthermore, memory is reclaimed according to the browsing time of the running pages of the target application, which allows for gradual memory reclamation, thereby improving the efficiency of memory checks and enhancing the user experience.
[0164] 2) The memory reclamation device of this application, when the target application is already running, executes memory check logic in the execution unit, determines whether the target application has any abnormal system memory usage based on the target application's memory usage information, and reclaims memory in the case of abnormal system memory usage based on the browsing time of the target application's running pages. In this scheme, when the target application is already running, it actively checks the target application's memory usage information to determine whether there are any abnormal system memory usages, and reclaims memory according to the browsing time of the target application's running pages. This allows for gradual memory reclamation, thereby improving the efficiency of memory checks and enhancing the user experience.
[0165] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A memory reclamation method, characterized by, The application comprises the following steps: In the case that the target application has been started, memory checking logic is executed, which refers to logic for obtaining memory occupation information of the target application at least in the case that the target application has just been started or the target application has been running for a target time period, the memory occupation information referring to the use of system memory when the target application is running; According to the memory occupation information of the target application, it is determined whether the target application has system memory occupation abnormality; In the case that the target application has system memory occupation abnormality, the occupied memory of the running page of the target application is recycled in sequence according to the browsing time of the running page of the target application; According to the browsing time of the running page of the target application, the occupied memory of the running page of the target application is recycled in sequence, comprising the following steps: the browsing time of the running page of the target application is sorted in a predetermined order to construct a first queue, wherein one element in the first queue corresponds to page-related information of one running page, and the browsing time of the running page corresponding to the Nth element is earlier than the browsing time of the running page corresponding to the N-1th element; a second queue is constructed according to the first queue, at least one element in the second queue corresponding to page-related information of one running page; the occupied memory of the elements in the second queue is recycled in sequence from the tail of the queue to the head of the queue; The occupied memory of the elements in the second queue is recycled in sequence from the tail of the queue to the head of the queue, comprising the following steps: all elements in the second queue are obtained; the elements in the second queue whose occupied memory is to be recycled are sequentially stored in a third queue to obtain the third queue; the occupied memory of the elements in the third queue is recycled in sequence from the tail of the queue to the head of the queue; The occupied memory of the elements in the third queue is recycled in sequence from the tail of the queue to the head of the queue, comprising the following steps: it is determined whether the page-related information corresponding to the last element in the third queue has a non-zero value; in the case that the page-related information corresponding to the last element in the third queue has no non-zero value, the occupied memory of the page-related information corresponding to the last element in the third queue is recycled; in the case that the page-related information corresponding to the last element in the third queue has a non-zero value, the last element in the third queue is taken as the first element of a fourth queue in order to obtain the fourth queue, and the occupied memory of all elements in the fourth queue is not recycled; in the case that the target application is detected to have been closed, the occupied memory of all elements in the fourth queue is recycled.
2. The method of claim 1, wherein, In the case that the target application has been started, memory checking logic is executed, comprising the following steps: In the case that the target application has been started, a callback interface is generated, and the memory checking logic is called and executed by using the callback interface; In a case where the target application has been started, the target time period is acquired, and the memory checking logic is executed according to the target time period; In a case where the target application has been started and a predetermined operation is detected, the memory checking logic is executed, and the predetermined operation at least includes a selection operation on the running page of the target application.
3. The method of claim 1, wherein, According to the memory occupation information of the target application, it is determined whether the target application has a system memory occupation exception, including: Acquiring a total amount of system memory; Determining a usage amount corresponding to the memory occupation information of the target application when the target application is running, the usage amount referring to a usage of the total amount of system memory occupied by the target application when the target application is running; According to the usage amount, it is determined whether the target application has a system memory occupation exception.
4. The method of claim 3, wherein, According to the usage amount, it is determined whether the target application has a system memory occupation exception, including: In a case where the usage amount is less than a first usage amount, it is determined that the target application does not have a system memory occupation exception; In a case where the usage amount is greater than or equal to the first usage amount and the usage amount is less than a second usage amount, it is determined that the target application has a system memory occupation exception, and an exception level is determined as a first exception level; In a case where the usage amount is greater than or equal to the second usage amount, it is determined that the target application has a system memory occupation exception, and an exception level is determined as a second exception level, wherein the exception degree of the first exception level is less than the exception degree of the second exception level.
5. The method of claim 1, wherein, According to the first queue, a second queue is constructed, including: Acquiring first page-related information and second page-related information of a target element in the first queue, the first page-related information referring to page-related information corresponding to a non-visible area of a target running page corresponding to the target element, and the second page-related information referring to page-related information corresponding to a visible area of the target running page corresponding to the target element, the visible area referring to an area in which a predetermined identifier is displayed on the target running page; The second queue is constructed in an order in which an Nth element corresponds to the first page-related information and an N-1th element corresponds to the second page-related information.
6. A memory reclamation apparatus, comprising: Including: An execution unit is configured to execute memory checking logic in a case where a target application has been started, the memory checking logic referring to logic of acquiring memory occupation information of the target application at least in a case where the target application has just been started or the target application has been running for a target time period, the memory occupation information referring to usage of system memory occupied by the target application when the target application is running; A determination unit is configured to determine whether the target application has a system memory occupation exception according to the memory occupation information of the target application; A recycling unit is configured to recycle occupied memory of a running page of the target application according to a browsing time of the running page of the target application in a case where the target application has a system memory occupation exception. The recovery unit comprises a first construction module, a second construction module and a recovery module. The first construction module is configured to sort the browsing time of the running pages of the target application in a predetermined order, and construct a first queue. One element in the first queue corresponds to page-related information of one running page, and the browsing time of the running page corresponding to the Nth element is earlier than the browsing time of the running page corresponding to the (N-1)th element. The second construction module is configured to construct a second queue according to the first queue. At least one element in the second queue corresponds to page-related information of one running page. The recovery module is configured to recover the occupied memory of the elements in the second queue in turn from the tail of the queue to the head of the queue. The recovery module comprises a second acquisition submodule, a construction submodule and a recovery submodule. The second acquisition submodule is configured to acquire all the elements in the second queue. The construction submodule is configured to store the elements in the second queue whose occupied memory is to be recovered into a third queue in turn, and obtain the third queue. The recovery submodule is configured to recover the occupied memory of the elements in the third queue in turn from the tail of the queue to the head of the queue. The recovery submodule is further configured to determine whether the page-related information corresponding to the last element in the third queue has a non-zero value. The recovery submodule is further configured to delay the recovery of the occupied memory of the page-related information corresponding to the last element in the third queue in the case that the page-related information corresponding to the last element in the third queue has no non-zero value. The recovery submodule is further configured to, in the case that the page-related information corresponding to the last element in the third queue has a non-zero value, obtain a fourth queue by taking the last element in the third queue as the first element of the fourth queue in order, and not recover the occupied memory of all the elements in the fourth queue. The recovery submodule is further configured to recover the occupied memory of all the elements in the fourth queue in the case that the target application is detected to be closed.
7. A computer readable storage medium characterized by The computer readable storage medium comprises a stored program, wherein the program performs the method of any one of claims 1 to 5.
8. An electronic device, comprising: The computer readable storage medium comprises a stored program, wherein the program performs the method of any one of claims 1 to 5. The computer readable storage medium comprises a stored program, wherein the program performs the method of any one of claims 1 to 5.
Citation Information
Patent Citations
Page processing method and device, storage medium and terminal equipment
CN113127773A
Memory management method and device, electronic equipment and computer readable storage medium
CN114443268A