Service multi-instance memory optimization method, device, electronic device and storage medium
By obtaining memory snapshots in the on-board system and counting the number of service instances, detecting and reclaiming memory of excess instances, the memory usage abnormality caused by multiple service instances is solved, and the system stability and fluency are improved.
Patent Information
- Application Number
- CN202411757092.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-03
- Publication Date
- 2025-02-25
- Estimated Expiration
- 2044-12-03
AI Technical Summary
In the on-board system, multiple instances of the service cause abnormal memory usage, causing system lag, crash and restart, and the existing technology has failed to effectively solve this problem.
By obtaining a memory snapshot of the application process, counting the total number of instances of the same service to be inspected. If the total number of instances is greater than the preset threshold, the service business logic will be detected and memory recovery of the excess instances will be performed based on the memory snapshot.
Recycle memory resources in a timely manner, reduce memory usage abnormalities caused by multiple instances of service, and improve system stability and fluency.
Smart Images

Figure CN119248513B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of memory resource optimization, and in particular to a method, device, electronic device and storage medium for optimizing service multi-instance memory. Background Art
[0002] The in-vehicle system is a virtualized dual-system architecture solution. The Qnx operating system and the Android operating system (AndroidOS) share hardware resources such as the central processing unit (CPU) and memory through the virtualization (HyperVision) architecture. The Qnx operating system is mainly responsible for functions such as instrument applications, and the Android operating system is mainly responsible for central control entertainment information applications. Generally, the in-vehicle system has a total memory of 12GB, of which 7.7GB is allocated to the Android OS, but different car manufacturers can allocate the memory of the dual system on their own. For the Android OS, because it has to run a large number of applications and services, the system often freezes, crashes, restarts, etc. due to memory resources. Therefore, memory resources are extremely important for the Android OS.
[0003] There are many reasons why an application occupies memory resources, such as memory leaks, large images, multiple image loading, and dynamic library loading. It is particularly noteworthy that a little-known but far-reaching memory problem stems from the phenomenon of multiple service instances in Android applications. In some cases, multiple instances of the same service class may be unexpectedly retained in system memory. Moreover, when these instances and the objects they reference occupy a large amount of memory resources, the memory consumption of the application process will be significantly increased. If these instances are not recycled in time after the end of their life cycle, the remaining memory of the system will be sharply reduced, further exacerbating the tension of memory resources and posing a threat to the stability and smoothness of the entire vehicle system. However, there is currently no solution to deal with abnormal memory growth caused by multiple service instances. Summary of the invention
[0004] The present application provides a service multi-instance memory optimization method, device, electronic device and storage medium to solve the above-mentioned technical problem of being unable to solve the abnormal memory growth caused by service multi-instances.
[0005] In one embodiment of the present application, the present application provides a method for memory optimization of multiple instances of a service, including: obtaining detection information of an application process, the detection information including a memory snapshot; counting the total number of instances of the same service to be inspected based on the memory snapshot, and obtaining an optimization detection result of at least one service to be inspected based on the total number of instances; if the optimization detection result of a service to be inspected is to be memory optimized, then detecting the corresponding service stop business logic of the service to be inspected, and / or, reclaiming the memory of redundant instances of the service to be inspected based on the memory snapshot.
[0006] In one embodiment of the present application, the total number of instances of the same service to be inspected is counted based on the memory snapshot, and an optimized detection result of at least one service to be inspected is obtained based on the total number of instances, including: matching the registered service class name information with the snapshot service class name information in the memory snapshot to obtain a matching result, and the detection information also includes the registered service class name information; counting the total number of instances of the same service to be inspected based on the matching result; if the total number of instances of a service to be inspected is greater than a preset number threshold, the optimized detection result of the service to be inspected is determined as to be memory optimized.
[0007] In one embodiment of the present application, memory of redundant instances of the service to be inspected is reclaimed according to the memory snapshot, including: if the memory occupancy of an object to be inspected is greater than or equal to a preset memory threshold, the object to be inspected is marked for memory reclaim through a destruction method to obtain a memory marking resource; memory is reclaimed for all memory marking resources; wherein the object to be inspected is used to represent the memory object corresponding to the redundant instances in the memory snapshot.
[0008] In one embodiment of the present application, memory recycling marking is performed on the object to be inspected to obtain a memory marking resource, including: releasing data resources of the object to be inspected to obtain a first marking resource; modifying the access attributes of the object to be inspected through a reflection mechanism; cutting off the object reference chain of the object to be inspected through the modified access attributes to obtain a second marking resource; wherein the memory marking resource includes a first marking resource and a second marking resource.
[0009] In one embodiment of the present application, memory is recycled for all memory-tagged resources, including: executing a system garbage collection method at least twice on the memory of all memory-tagged resources; wherein the memory-tagged resources are used to represent objects to be inspected whose object reference chains have been cut off, referenced objects with no reference relationship, and data resources used by the objects to be inspected.
[0010] In one embodiment of the present application, detecting the stop service business logic corresponding to the service to be inspected includes: generating call prompt information of the service stop method of the service to be inspected; if the call prompt information indicates that the stop service method has been called, then detecting the call frequency and call location of the stop service method.
[0011] In one embodiment of the present application, obtaining a memory snapshot of an application process includes: starting at least one service to be inspected in the application to be inspected according to a preset first time interval to obtain the application process; collecting a memory snapshot of the application process according to a preset second time interval through a memory optimization integrated toolkit; wherein the memory optimization integrated toolkit is located in the application to be inspected.
[0012] In one embodiment of the present application, the present application provides a service multi-instance memory optimization device, including: an information acquisition module, used to obtain detection information of an application process, the detection information including a memory snapshot; an instance detection module, used to count the total number of instances of the same service to be inspected based on the memory snapshot, and obtain an optimization detection result of at least one service to be inspected based on the total number of instances; a memory optimization module, used to detect the corresponding service stop business logic of the service to be inspected if the optimization detection result of a service to be inspected is to be memory optimized, and / or, reclaim memory of redundant instances of the service to be inspected according to the memory snapshot.
[0013] In one embodiment of the present application, the present application provides an electronic device, which includes: one or more processors; a storage device for storing one or more programs, and when the one or more programs are executed by the one or more processors, the electronic device implements the service multi-instance memory optimization method as described in any of the above embodiments.
[0014] In one embodiment of the present application, the present application provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor of a computer, the computer executes the service multi-instance memory optimization method described in any one of the above embodiments.
[0015] Beneficial effects of the embodiments of the present application: The present application provides a method, device, electronic device and storage medium for memory optimization of multiple service instances. The embodiments of the present application can determine the optimization detection result of a service to be inspected through a memory snapshot. If a service to be inspected requires memory optimization, the service business logic is stopped and / or the memory of redundant instances is recovered through memory snapshots, and memory resources are recovered in time, thereby reducing memory usage abnormalities caused by multiple service instances and improving system stability and system fluency.
[0016] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The drawings herein are incorporated into the specification and constitute a part of the specification, showing embodiments consistent with the present application, and together with the specification, are used to explain the principles of the present application. Obviously, the drawings described below are only some embodiments of the present application, and for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0018] Figure 1 A schematic diagram showing an exemplary system architecture to which the technical solution of the embodiments of the present application can be applied;
[0019] Figure 2A schematic diagram of a process of optimizing a service multi-instance memory according to an embodiment of the present application is shown;
[0020] Figure 3 A scenario of generating multiple service instances according to an embodiment of the present application is shown;
[0021] Figure 4 A schematic diagram showing the memory usage of a service to be inspected and its referenced objects according to an embodiment of the present application is shown;
[0022] Figure 5 A schematic diagram of a process for optimizing service multi-instance memory according to an embodiment of the present application is shown;
[0023] Figure 6 A block diagram of a service multi-instance memory optimization device according to an embodiment of the present application is shown;
[0024] Figure 7 A schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present application is shown. DETAILED DESCRIPTION
[0025] The following describes the embodiments of the present application through specific examples, and those skilled in the art can easily understand other advantages and effects of the present application from the contents disclosed in this specification. The present application can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present application. It should be noted that the following embodiments and features in the embodiments can be combined with each other without conflict.
[0026] It should be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present application, and thus the drawings only show components related to the present application rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the form, quantity and proportion of each component may be changed arbitrarily, and the component layout may also be more complicated.
[0027] In the following description, a large number of details are discussed to provide a more thorough explanation of the embodiments of the present application. However, it is obvious to those skilled in the art that the embodiments of the present application can be implemented without these specific details. In other embodiments, well-known structures and devices are shown in the form of block diagrams rather than in detail to avoid making the embodiments of the present application difficult to understand.
[0028] See also Figure 1 , Figure 1 A schematic diagram of an exemplary system architecture to which the technical solution of the embodiment of the present application can be applied is shown. Figure 1As shown, the system architecture may include multiple applications to be inspected in the vehicle system, each application includes a memory optimization integrated toolkit and at least one service to be inspected, wherein the memory optimization integrated toolkit is used to perform memory optimization on multiple instances of the service.
[0029] Exemplarily, detection information of an application process is obtained through a memory optimization integrated toolkit, the detection information including a memory snapshot; the total number of instances of the same service to be inspected is counted based on the memory snapshot, and an optimization detection result of at least one service to be inspected is obtained based on the total number of instances; if the optimization detection result of a service to be inspected is to be memory optimized, the corresponding service stop business logic of the service to be inspected is detected, and / or the memory of redundant instances of the service to be inspected is reclaimed according to the memory snapshot.
[0030] In the related art, the problem of abnormal memory usage occurs because multiple instances of the same service are not recycled in time after their life cycle ends.
[0031] In order to solve the above technical problems, the present application provides a service multi-instance memory optimization method, device, electronic device and storage medium. The implementation details of the technical solution of the embodiment of the present application are elaborated in detail below.
[0032] See also Figure 2 , Figure 2 FIG. 1 is a flow chart of a method for optimizing service multi-instance memory according to an embodiment of the present application. Figure 2 As shown, in an exemplary embodiment, the service multi-instance memory optimization method includes at least steps S210 to S230, which are described in detail as follows:
[0033] Step S210, obtaining detection information of the application process.
[0034] The detection information includes a memory snapshot.
[0035] In one embodiment of the present application, the present application can be applied to an Android operating system of a vehicle-mounted system, wherein the application process is located in the Android operating system.
[0036] In one embodiment of the present application, see Figure 3 , Figure 3 FIG. 2 shows a scenario for generating multiple service instances according to an embodiment of the present application. Figure 3As shown, in the scenario where there are multiple instances of the same service, such as service A in application A is started multiple times by other applications or the system, service A will actively call the stop service (stopSelf) method to end service A after completing its business logic each time. Service A will follow the destruction (onDestroy) method of its life cycle, so that each time service A is started, an instance of service A will be generated in the memory of the vehicle system, such as instance A_1, instance A_2, instance A_3, instance A_X1, that is, there are X1 instances of A in total; if service A is started, it does not actively end itself by calling the stopSelf method, and multiple starts will not create multiple instances, nor will cause obvious memory problems. However, in some scenarios, it is necessary to end the service and destroy it. For example, when the vehicle system is in the screen saver service, when it receives the screen projection request, it is necessary to exit the screen saver service. If service A is started by other applications multiple times and frequently in a short period of time, resulting in multiple instances of service A in the memory of the vehicle system, if these destroyed instances cannot be recovered in time, the memory usage of application A will increase abnormally and rapidly, resulting in a sudden decrease in the available memory of the system, causing system freezes and abnormal operation.
[0037] In one embodiment of the present application, see Figure 4 , Figure 4 FIG. 1 shows a schematic diagram of memory usage of a service to be inspected and its referenced objects according to an embodiment of the present application. Figure 4 As shown, there is a ViewPager control in the screen saver service, which can display different interfaces by sliding left and right. Different pages are associated with ViewPager through the RecyclerView.Adapter. Each FrameLayout container contains the controls that need to be displayed. Figure 4 There are X2 frame layouts in total, and the bitmap list (List <bitmap>) is a bitmap object parsed from dozens or even hundreds of pictures and displayed on each control; frame animation parses dozens or hundreds of pictures of the same size and loads them into memory at one time for animation display; the screen saver service loads dozens of picture resources on the page corresponding to each screen saver style, resulting in 40MB of memory usage each time the screen saver service is started. If multiple instances of the screen saver service exist in the car system at the same time, the available memory resources will be severely reduced.
[0038] In one embodiment of the present application, obtaining a memory snapshot of an application process includes: starting at least one service to be inspected in the application to be inspected according to a preset first time interval to obtain the application process; collecting a memory snapshot of the application process according to a preset second time interval through a memory optimization integrated toolkit; wherein the memory optimization integrated toolkit is located in the application to be inspected.
[0039] In one embodiment of the present application, please continue to refer to Figure 1 ,like Figure 1 As shown, the multiple applications to be inspected include application A, application B and application C; application A includes a memory optimization integrated toolkit and service A, application B includes a memory optimization integrated toolkit and service B, and application C includes a memory optimization integrated toolkit and service C. The memory optimization integrated toolkit is obtained based on a software development kit (SDK) for optimizing the memory usage of host process services.
[0040] In one embodiment of the present application, the preset first time interval is set to 5 seconds. For example, the service to be inspected is started once every 5 seconds for 10 consecutive minutes through the script.
[0041] In one embodiment of the present application, the preset first time interval is equal to the preset second time interval, and the preset second time interval is set to 5 seconds. The memory optimization integrated toolkit collects memory snapshots of the application process every 5 seconds.
[0042] In one embodiment of the present application, the memory optimization integrated toolkit is attached to the host process, and the memory snapshot is obtained through the debug heap memory snapshot method (Debug.dumpHprofData). The host process is the application process corresponding to the application to be tested after starting.
[0043] Step S220: Count the total number of instances of the same service to be inspected based on the memory snapshot, and obtain an optimized detection result of at least one service to be inspected according to the total number of instances.
[0044] In one embodiment of the present application, the total number of instances of the same service to be inspected is counted based on a memory snapshot, and an optimized detection result of at least one service to be inspected is obtained based on the total number of instances, including: matching the registered service class name information with the snapshot service class name information in the memory snapshot to obtain a matching result, and the detection information also includes the registered service class name information; counting the total number of instances of the same service to be inspected based on the matching result; if the total number of instances of a service to be inspected is greater than a preset number threshold, the optimized detection result of the service to be inspected is determined as a service to be optimized in memory.
[0045] In one embodiment of the present application, by obtaining the registered service class name information corresponding to the application process in the application manifest, searching for the service to be inspected that matches the registered service class name information in the memory snapshot, the total number of instances of the same service to be inspected is counted.
[0046] In one embodiment of the present application, the preset quantity threshold is set to 1. If the total number of instances is greater than 1, the service to be inspected has a problem of multiple service instances affecting memory, and memory optimization is required; if the total number of instances is equal to 1, it means that the service to be inspected is normal.
[0047] Step S230: If the optimization detection result of a service to be checked is to be memory optimized, then the service stop business logic corresponding to the service to be checked is detected, and / or the memory of redundant instances of the service to be checked is reclaimed according to the memory snapshot.
[0048] In one embodiment of the present application, detecting the stop service business logic corresponding to the service to be inspected includes: generating call prompt information of the service stop method of the service to be inspected; if the call prompt information indicates that the stop service method has been called, detecting the call frequency and call location of the stop service method.
[0049] In one embodiment of the present application, if the total number of instances of a service to be inspected is greater than a preset threshold, a log is printed to prompt the developer with a call prompt message of the stopSelf method, so as to inspect the business logic of the stopSelf method.
[0050] In one embodiment of the present application, memory of redundant instances of a service to be inspected is reclaimed according to a memory snapshot, including: if the memory occupancy of the object to be inspected is greater than or equal to a preset memory threshold, memory-reclaiming marking the object to be inspected is performed through a destruction method to obtain a memory marking resource; memory is reclaimed for all memory marking resources; wherein the object to be inspected is used to represent the memory object corresponding to the redundant instances in the memory snapshot.
[0051] In one embodiment of the present application, redundant instances are used to represent instances that are not called by application processes and other services to be checked, that is, instances that are not currently in use.
[0052] In one embodiment of the present application, the called instance can be marked by the call identification return value. For example, if the call identification return value of an instance is 1, it means that the instance has been used; if the call identification return value of an instance is 0, it means that the instance has not been used. This is only an example and does not limit the scope of the present application.
[0053] In one embodiment of the present application, the business logic of releasing service memory in the memory optimization integration toolkit is called through the onDestroy method in the service to be inspected, so as to mark the objects to be inspected whose memory occupancy is greater than or equal to the preset memory threshold for memory recycling.
[0054] In one embodiment of the present application, the preset memory threshold is set to 100 KB.
[0055] In one embodiment of the present application, memory recycling marking is performed on the object to be inspected to obtain a memory marking resource, including: releasing data resources of the object to be inspected to obtain a first marking resource; modifying the access attributes of the object to be inspected through a reflection mechanism; cutting off the object reference chain of the object to be inspected through the modified access attributes to obtain a second marking resource; wherein the memory marking resource includes the first marking resource and the second marking resource.
[0056] In one embodiment of the present application, the access attribute of the object to be checked is changed through the reflection mechanism so that it can process or access the object to be checked, and the object reference chain is cut off one by one by clearing the root node of the object to be checked and the reference objects in the object reference chain of the object to be checked. <bitmap>The referenced bitmap object releases the data resources of each Bitmap instance through bitmap recycling (Bitmap.recycle). The data resources include pixel data, and the Bitmap instance is set to zero to release the memory space occupied by the Bitmap object.
[0057] In one embodiment of the present application, memory recycling is performed on all memory tagged resources, including: performing system garbage recycling on the memory of all memory tagged resources; performing system garbage recycling on the memory of all memory tagged resources again; wherein the memory tagged resources are used to represent the objects to be inspected whose object reference chains have been cut off, referenced objects with no reference relationship, and data resources used by the objects to be inspected.
[0058] In one embodiment of the present application, after processing the release logic, the system garbage collection (System.gc) method is actively called at least twice every preset third time interval to actively inform the Android operating system to recycle memory so that the instance to be checked that has been destroyed by the host process can be recycled in time. The preset third time interval can be set to 2 seconds.
[0059] In one embodiment of the present application, see Figure 5 , Figure 5 FIG. 2 shows a flow chart of service multi-instance memory optimization according to an embodiment of the present application. Figure 5 As shown, each service is started every 5 seconds for 10 minutes through the script: at least one service to be checked is started every 5 seconds for 10 minutes through the script; a memory snapshot of the host process is obtained every 5 seconds: a memory optimization integration toolkit is used to collect a memory snapshot of the application process every 5 seconds; memory snapshot data is parsed: the registered service class name information in the registration file is matched with the snapshot service class name information in the memory snapshot to obtain a matching result; the number of service instances is obtained: the total number of instances of the same service to be checked is counted according to the matching result; multiple service instances cause memory growth: if the total number of instances of a service to be checked is greater than the preset number threshold, there are multiple instances and memory optimization is required; no memory problem: if the total number of instances of a service to be checked is less than or equal to the preset number threshold, there are no multiple instances and memory optimization is not required; the log prompts whether the service to be checked is internal The service stop method is called, and the business logic is checked: the log prompts whether the stopSelf method is called. If the stopSelf method is called, the call frequency and call location of the stopSelf method are checked to see if they are reasonable; the memory is released in the destruction method of the host process service: the onDestroy method is used in the service to be checked to call the business logic of releasing the service memory in the memory optimization integration toolkit; the corresponding memory is released according to the object instance reflection in the memory snapshot, and the reference chain is cut off: the object reference chain is cut off through the recycling method and reflection mechanism to release large memory usage such as bitmap list objects; the system garbage collection method is called twice every 2 seconds to perform garbage collection: the Java virtual machine (JVM) is prompted to perform garbage collection by calling the System.gc method multiple times. This application discovers the problem of memory growth caused by multiple service instances through memory snapshots and registered service class name information, and actively releases the memory usage of redundant instances through memory snapshots, which can promptly solve the problem of abnormal memory usage caused by multiple service instances.
[0060] See also Figure 6 , Figure 6 A block diagram of a service multi-instance memory optimization device according to an embodiment of the present application is shown. The device can be applied to Figure 1 The implementation environment shown is specifically configured in the memory optimization integrated toolkit. The device can also be applied to other exemplary implementation environments and specifically configured in other devices. This embodiment does not limit the implementation environment to which the device is applicable.
[0061] like Figure 6 As shown, a service multi-instance memory optimization device 600 according to an embodiment of the present application includes: an information acquisition module 601, an instance detection module 602 and a memory optimization module 603.
[0062] The information acquisition module 601 is used to acquire detection information of the application process, and the detection information includes a memory snapshot;
[0063] The instance detection module 602 is used to count the total number of instances of the same service to be detected based on the memory snapshot, and obtain an optimized detection result of at least one service to be detected according to the total number of instances;
[0064] The memory optimization module 603 is used to detect the service stop business logic corresponding to the service to be inspected if the optimization detection result of a service to be inspected is to be memory optimized, and / or to reclaim the memory of redundant instances of the service to be inspected according to the memory snapshot.
[0065] It should be noted that the service multi-instance memory optimization device provided in the above embodiment and the service multi-instance memory optimization method provided in the above embodiment belong to the same concept, wherein the specific manner in which each module and unit performs operations has been described in detail in the method embodiment and will not be repeated here. In actual applications, the service multi-instance memory optimization device provided in the above embodiment can distribute the above functions to different functional modules as needed, that is, divide the internal structure of the device into different functional modules to complete all or part of the functions described above, and this is not limited here.
[0066] An embodiment of the present application also provides an electronic device, comprising: one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by one or more processors, the electronic device implements the service multi-instance memory optimization method provided in the above-mentioned embodiments.
[0067] See also Figure 7 , Figure 7 The structure diagram of the computer system suitable for implementing the electronic device of the embodiment of the present application is shown. It should be noted that: Figure 7 The computer system 700 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0068] like Figure 7 As shown, the computer system 700 includes a central processing unit 701, which can perform various appropriate actions and processes according to the program stored in the read-only memory 702 or the program loaded from the storage part 708 into the random access memory 703, such as executing the method in the above embodiment. In the random access memory 703, various programs and data required for system operation are also stored. The central processing unit 701, the read-only memory 702 and the random access memory 703 are connected to each other through a bus 704. The input / output interface 705 is also connected to the bus 704.
[0069] The following components are connected to the input / output interface 705: an input section 706 including a keyboard, a mouse, etc.; an output section 707 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker; a storage section 708 including a hard disk, etc.; and a communication section 709 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 709 performs communication processing via a network such as the Internet. A drive 710 is also connected to the input / output interface 705 as needed. A removable medium 711, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 710 as needed so that a computer program read therefrom is installed into the storage section 708 as needed.
[0070] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a computer program for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through the communication part 709, and / or installed from a removable medium 711. When the computer program is executed by the central processing unit 701, various functions defined in the system of the present application are executed.
[0071] It should be noted that the computer-readable medium shown in the embodiment of the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier, which carries a computer-readable computer program. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. A computer program contained on a computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0072] The flowchart and block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the system, method and computer program product according to various embodiments of the present application. Wherein, each box in the flowchart or block diagram can represent a module, a program segment, or a part of the code, and the above-mentioned module, program segment, or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart and the combination of boxes in the block diagram or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0073] The units involved in the embodiments described in the present application can be implemented by software or by hardware, and the units described can also be set in a processor. Among them, the names of these units do not constitute a limitation on the units themselves under certain circumstances. Therefore, the technical solution according to the implementation mode of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including a number of instructions to enable a computing device (which can be a personal computer, a server, a touch terminal, or a network device, etc.) to execute the method according to the implementation mode of the present application.
[0074] Another aspect of the present application further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor of a computer, the computer executes the service multi-instance memory optimization method provided in the above embodiments. The computer-readable storage medium may be included in the electronic device described in the above embodiments, or may exist independently without being assembled into the electronic device.
[0075] In the above embodiments, unless otherwise specified, describing common objects by using serial numbers such as "first" and "second" only indicates that they refer to different instances of the same object, rather than indicating that the objects being described must adopt a given order, whether in time, space, sorting or any other way.
[0076] The above embodiments are merely illustrative of the principles and effects of the present application, and are not intended to limit the present application. Anyone familiar with the technology may modify or change the above embodiments without violating the spirit and scope of the present application. Therefore, all equivalent modifications or changes made by a person of ordinary skill in the art without departing from the spirit and technical ideas disclosed in the present application shall still be covered by the claims of the present application.< / bitmap> < / bitmap>
Claims
1. A service multi-instance memory optimization method, characterized in that: The method comprises: Obtaining detection information of the application process, wherein the detection information includes a memory snapshot; Counting the total number of instances of the same service to be inspected based on the memory snapshot, and obtaining an optimized detection result of at least one service to be inspected according to the total number of instances; If the optimization detection result of a service to be checked is that memory optimization is required, then the service stop business logic corresponding to the service to be checked is detected, and / or the memory of redundant instances of the service to be checked is reclaimed according to the memory snapshot; The method of counting the total number of instances of the same service to be inspected based on the memory snapshot and obtaining an optimized detection result of at least one service to be inspected according to the total number of instances includes: Performing class name matching on the registered service class name information and the snapshot service class name information in the memory snapshot to obtain a matching result, wherein the detection information also includes the registered service class name information; Counting the total number of instances of the same service to be inspected according to the matching results; If the total number of instances of a service to be inspected is greater than a preset number threshold, the optimization detection result of the service to be inspected is determined as a service to be optimized for memory; Get a memory snapshot of the application process, including: Collecting memory snapshots of the application process according to a preset second time interval by using a memory optimization integrated toolkit; The memory optimization integrated toolkit is located in the application to be inspected and is attached to a host process. The host process is the application process corresponding to the application to be inspected after the application to be inspected is started. The application to be inspected includes the service to be inspected.
2. The service multi-instance memory optimization method according to claim 1, characterized in that: Reclaiming the memory of redundant instances of the service to be inspected according to the memory snapshot includes: If the memory usage of an object to be inspected is greater than or equal to a preset memory threshold, the object to be inspected is marked for memory recycling through a destruction method to obtain a memory marking resource; Perform memory recycling on all memory-tagged resources; The object to be checked is used to represent the memory object corresponding to the redundant instances in the memory snapshot.
3. The service multi-instance memory optimization method according to claim 2, characterized in that: Performing memory recycling marking on the object to be inspected to obtain memory marking resources includes: Release data resources of the object to be inspected to obtain a first marking resource; Modify the access attribute of the object to be checked through the reflection mechanism; The object reference chain of the object to be inspected is cut off by using the modified access attribute to obtain a second marking resource; The memory tag resource includes a first tag resource and a second tag resource.
4. The service multi-instance memory optimization method according to claim 2, characterized in that: Memory is reclaimed for all memory-tagged resources, including: Execute system garbage collection methods at least twice for all memory-tagged resources; The memory marking resource is used to represent the object to be inspected whose object reference chain has been cut off, the referenced object without a reference relationship, and the data resources used by the object to be inspected.
5. The service multi-instance memory optimization method according to any one of claims 1 to 4, characterized in that: Detecting the service stopping business logic corresponding to the service to be inspected includes: Generate call prompt information of the service stop method of the service to be inspected; If the calling prompt information indicates that the stop service method has been called, the calling frequency and calling location of the stop service method are detected.
6. The service multi-instance memory optimization method according to any one of claims 1 to 4, characterized in that: Get a memory snapshot of the application process, including: At least one service to be inspected in the application to be inspected is started according to a preset first time interval to obtain an application process.
7. A service multi-instance memory optimization device, characterized in that: The device comprises: An information acquisition module, used to acquire detection information of an application process, wherein the detection information includes a memory snapshot; An instance detection module, used to count the total number of instances of the same service to be detected based on the memory snapshot, and obtain an optimized detection result of at least one service to be detected according to the total number of instances; A memory optimization module, for detecting the service stop business logic corresponding to the service to be inspected if the optimization detection result of a service to be inspected is to be memory optimized, and / or, reclaiming the memory of redundant instances of the service to be inspected according to the memory snapshot; The method of counting the total number of instances of the same service to be inspected based on the memory snapshot and obtaining an optimized detection result of at least one service to be inspected according to the total number of instances includes: Performing class name matching on the registered service class name information and the snapshot service class name information in the memory snapshot to obtain a matching result, wherein the detection information also includes the registered service class name information; Counting the total number of instances of the same service to be inspected according to the matching results; If the total number of instances of a service to be inspected is greater than a preset number threshold, the optimization detection result of the service to be inspected is determined as a service to be optimized for memory; Get a memory snapshot of the application process, including: Collecting memory snapshots of the application process according to a preset second time interval by using a memory optimization integrated toolkit; The memory optimization integrated toolkit is located in the application to be inspected and is attached to a host process. The host process is the application process corresponding to the application to be inspected after the application to be inspected is started. The application to be inspected includes the service to be inspected.
8. An electronic device, characterized in that: The electronic device comprises: one or more processors; A storage device for storing one or more programs, which, when executed by the one or more processors, enables the electronic device to implement the service multi-instance memory optimization method as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed by a processor of a computer, the computer is caused to execute the service multi-instance memory optimization method described in any one of claims 1 to 6.
Citation Information
Patent Citations
Screensaver-based system optimization method and device, terminal equipment and storage medium
CN115408011A
Vehicle-mounted service communication middleware supporting multiple communication protocols and communication method
CN117240939A