Method, electronic device, and storage medium for processing duplicate images in memory

By generating a child process to identify and merge the virtual addresses of duplicate images, the problem of waste of memory resources caused by the application to repeatedly allocate the same images is solved, and memory usage is optimized and the application usage experience is improved.

CN112835813BActive Publication Date: 2025-08-05TENCENT MUSIC ENTERTAINMENT TECH (SHENZHEN) CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202110238770.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-03-04
Publication Date
2025-08-05
Estimated Expiration
2041-03-04

AI Technical Summary

Technical Problem

The prior art cannot effectively solve the problem of waste of memory resources caused by repeated allocation of the same pictures during runtime of applications, affecting the normal use and usage experience of terminal devices.

Method used

By generating a child process with the same virtual address space and memory object reference relationship as the main process, identify and merge the virtual address of the duplicate picture, modify the memory object reference relationship of the main process to merge and reference the same object, and eliminate references of the duplicate picture.

Benefits of technology

It effectively avoids the waste of memory resources caused by duplicate images, optimizes memory usage, improves the application experience, and avoids the impact of duplicate image merging and recycling processing on the main process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112835813B_ABST
    Figure CN112835813B_ABST
Patent Text Reader

Abstract

The present application discloses a method for processing duplicate images in memory, which includes: generating a second process of the application based on a first process of the running application, where the second process has the same virtual address space and memory object reference relationship as the first process; extracting a list of image objects in the memory of the running application in the second process based on the memory object reference relationship; determining duplicate images in the list of image objects in the second process and the virtual addresses of the duplicate images in the virtual address space; obtaining the virtual addresses of the duplicate images by the first process; and modifying the memory object reference relationship of the first process based on the virtual addresses of the duplicate images obtained by the first process so that the virtual addresses of the duplicate images in the first process merge to reference the same object in the memory. The present application also discloses an electronic device and a storage medium.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and particularly to a method and apparatus for processing duplicate images in memory. This application also relates to related electronic devices and storage media. Background Art

[0002] Currently, computer terminal devices represented by smartphones and the like have been widely used. The functions of application programs (APPs) installed in these terminal devices have become increasingly powerful. Therefore, the application program services in terminal devices often face the pain point of huge memory consumption. In particular, a large number of images called by application programs during operation often occupy a large part of the precious memory resources. In many cases, these images occupying memory resources are often the same images repeatedly allocated by application programs during operation.

[0003] To ensure the normal use of terminal devices, current terminal device operating systems, such as the Android system, can often actively or passively perform memory cleaning. However, the role of memory cleaning is to ensure the basic use of terminal devices without crashing, which often comes at the cost of affecting the rich usage experience that application programs intend to provide.

[0004] In addition, some terminal device operating systems, such as the Android system, also provide an image memory space reuse function, that is, when the continuous memory space allocated for image A is no longer in use, it can be used by another image B to improve the utilization of memory resources. However, this function cannot solve the waste problem caused by the allocation of multiple identical image resources during the operation of application programs.

[0005] Therefore, there is a current need to optimize the memory usage of computers by effectively processing duplicate images that occupy a large amount of memory resources.

[0006] The content described in this background art is only for facilitating the understanding of the related technologies in this field and is not regarded as an admission of the prior art. Summary of the Invention

[0007] Therefore, embodiments of the present invention intend to provide a method and apparatus for processing duplicate images in memory, as well as related electronic devices and storage media, which can effectively address the problem of memory resource waste caused by a large number of identical images repeatedly allocated during the operation of application programs.

[0008] In a first aspect, a method for processing duplicate images in memory is provided, which includes:

[0009] Generating a second process of the application program based on a first process of the running application program, where the second process has the same virtual address space and memory object reference relationship as the first process;

[0010] Extract a list of picture objects in the memory of the running application in the second process based on the memory object reference relationship.

[0011] Determine duplicate pictures in the picture object list in the second process and the virtual addresses of the duplicate pictures in the virtual address space.

[0012] Obtain the virtual addresses of the duplicate pictures from the first process.

[0013] Modify the memory object reference relationship of the first process based on the virtual addresses of the duplicate pictures obtained by the first process so that the virtual addresses of the duplicate pictures in the first process merge to reference the same object in the memory.

[0014] In a second aspect, there is provided an apparatus for processing duplicate pictures in memory, which includes:

[0015] A generation unit configured to generate a second process of the application based on a first process of the running application, where the second process has the same virtual address space and memory object reference relationship as the first process.

[0016] An extraction unit configured to extract a list of picture objects in the memory of the running application in the second process based on the memory object reference relationship.

[0017] A determination unit configured to determine duplicate pictures in the picture object list in the second process and the virtual addresses of the duplicate pictures in the virtual address space.

[0018] An acquisition unit configured to obtain the virtual addresses of the duplicate pictures from the first process.

[0019] A merged reference unit configured to modify the memory object reference relationship of the first process based on the virtual addresses of the duplicate pictures obtained by the first process so that the virtual addresses of the duplicate pictures in the first process merge to reference the same object in the memory.

[0020] In a third aspect, there is provided an electronic device, which includes: a processor and a memory storing a computer program, and the processor is configured to execute the method of any embodiment of the present invention when running the computer program.

[0021] In a fourth aspect, there is provided a storage medium storing a computer program, and the computer program is configured to execute the method of any embodiment of the present invention when running.

[0022] The solution according to an embodiment of the present invention generally relates to a method for memory optimization and related devices, equipment or storage media. The solution according to an embodiment of the present invention is particularly applicable to mobile terminal devices, such as terminal devices using mobile operating systems, such as Android or iOS systems. More specifically, the solution according to an embodiment of the present invention relates to the optimization of the memory occupied by application programs running under the mobile operating system.

[0023] Here, a second process, usually a child process, is generated by the first process of the running application program, usually the main process. Thus, the second process copies the virtual address space of the first process and obtains the memory object reference relationship of the first process. On this basis, picture objects in the memory, such as bitmap BITMAP objects, are extracted, and duplicate pictures among them are identified. Finally, the memory object reference relationship of the first process is modified thereby to merge the references to the same object in the memory. The solution according to an embodiment of the present invention can provide an extremely efficient way to avoid the waste of memory resources caused by duplicate pictures, thereby greatly optimizing the memory usage, and also avoiding the impact of the merging and recycling process of duplicate pictures on the user experience of the application program.

[0024] In a further solution according to an embodiment of the present invention, the real-time identification of memory picture objects can be efficiently and accurately achieved by using a hash function method for the data of the picture type objects called by the application program, more specifically the byte stream.

[0025] Some of the other optional features and technical effects of the embodiments of the present invention are described below, and some can be understood by reading this article. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] Hereinafter, the embodiments of the present invention will be described in detail with reference to the drawings. The elements shown are not limited by the scale shown in the drawings. The same or similar reference numerals in the drawings denote the same or similar elements, where:

[0027] Figure 1 A first schematic flowchart of the method according to an embodiment of the present invention is shown;

[0028] Figure 2 A second schematic flowchart of the method according to an embodiment of the present invention is shown;

[0029] Figure 3 A third schematic flowchart of the method according to an embodiment of the present invention is shown;

[0030] Figure 4 A fourth schematic flowchart of the method according to an embodiment of the present invention is shown;

[0031] Figure 5 A schematic structural diagram of the device according to an embodiment of the present invention is shown;

[0032] Figure 6 Shows a first schematic diagram according to a schematic example;

[0033] Figure 7 Shows a second schematic diagram according to the said schematic example;

[0034] Figure 8 Shows a third schematic diagram according to the said schematic example;

[0035] Figure 9 Shows a process schematic diagram of an application program according to an embodiment of the present invention;

[0036] Figure 10 Shows a hardware structure schematic diagram of an electronic device according to an embodiment of the present invention;

[0037] Figure 11 Shows an operating system schematic diagram of an electronic device according to an embodiment of the present invention. Detailed implementation manners

[0038] To make the objectives, technical solutions and advantages of the present invention clearer and more understandable, the present invention will be further described in detail below in combination with the detailed implementation manners and the accompanying drawings. Here, the schematic implementation manners of the present invention and their descriptions are used to explain the present invention, but do not limit the present invention.

[0039] Embodiments of the present invention provide a memory optimization solution, for example, for a computer, such as a terminal device, for example, a mobile terminal, especially for a memory optimization solution in the case of an application program process that repeatedly calls or allocates pictures in memory. Specifically, embodiments of the present invention relate to a method for processing duplicate pictures in memory. Specifically, in the case of running an application program that repeatedly calls or allocates pictures, the method generates a second process that replicates the first process of the application program running, and when duplicate pictures in memory are identified in the second process, the reference picture objects are correspondingly merged in the first process to eliminate the references to duplicate pictures and achieve the effect of reducing memory waste. In addition, embodiments of the present invention also correspondingly relate to corresponding devices, as well as computer systems for implementing the above method and storage media storing programs that can execute the above method. In some embodiments, devices, components, units or models can be implemented by software, hardware or a combination of software and hardware.

[0040] In some embodiments of the present invention, the application program (APP) can be different types of APPs, including but not limited to: music APP, social APP, live broadcast APP, shopping APP, video APP, etc. In some embodiments, the application program is preferably an application program that occupies a large amount of memory by repeatedly allocating the same pictures.

[0041] In the embodiments of the present invention, the memory has the commonly understood meaning and can also be referred to as the main memory. In the embodiments of the present invention, especially in the case of a terminal device, such as a mobile terminal device, the memory includes a random access memory (RAM), but does not include the cache integrated in the processor and the non-volatile memory or flash memory (which cannot be directly read by the processor), which is usually referred to as ROM. In some embodiments, the memory includes a dynamic RAM (DRAM). This will be further described below in conjunction with Figure 10 the schematic diagram of the hardware structure of the electronic device shown.

[0042] In the embodiments of the present invention, the picture is a digital picture (image) and may include a bitmap and a vector graph. In a preferred embodiment, the picture is of the bitmap type. A bitmap is a binary map and can also be called a pixel map or a raster map. It stores and displays an image by recording information such as the color, depth, and transparency of each point in the image. Bitmap pictures can include various formats, including but not limited to BMP, JPG, GIF, and PNG formats, etc. In the embodiments of the present invention, the recognition of the picture format can be implemented in various ways, such as reading the attribute file or the bytes representing the file format simultaneously.

[0043] In the embodiments of the present invention, the duplicate pictures include the same pictures repeatedly allocated by an application during runtime, which occupy multiple (physical) memory spaces, thus causing memory overhead, especially covering the case where multiple identical pictures are referenced by multiple objects and these identical pictures are located at different (physical) memory addresses.

[0044] Referring to Figure 1 , the method for processing duplicate pictures in the memory may include steps S101 to S105.

[0045] S101: Generate a second process of the application based on the first process of the running application, and the second process has the same virtual address space and memory object reference relationship as the first process.

[0046] In some embodiments, the method for processing duplicate pictures in the memory according to the present invention is triggered to start.

[0047] In a specific embodiment, the memory status can be detected, and when the memory status reaches a preset threshold condition, the merging and recycling of duplicate images are triggered.

[0048] For example, in Figure 2 the embodiment shown, step S101 may include:

[0049] S201: Detect whether the memory status meets the preset threshold condition;

[0050] S202: In response to the memory status meeting the preset threshold condition, generate the second process.

[0051] In some embodiments, detecting the memory status may be based on the overall memory of the electronic device. In an alternative preferred embodiment, detecting the memory status may be based on the memory occupied (pulled) or the remaining memory of the (main) process of the running application, which may be referred to herein as application memory or application remaining memory for short. For example, the memory status is preferably the memory status of the first process, such as the remaining memory status of the first process. In some embodiments, the preset threshold condition may be the amount or proportion of the remaining memory. For example, it may be bounded by the application remaining memory being less than 10%, that is, the unoccupied part in the maximum memory that the process can pull during application operation is less than 10%.

[0052] As an alternative embodiment, the method of processing duplicate pictures or duplicate image merging and recycling may be executed periodically, or a combination of both. For example, in a preferred embodiment, it may be periodically determined whether to execute the duplicate picture merging and recycling at N clock times and executed when the preset conditions are met; and optionally, during aperiodic times, if other preset conditions are met, such as lower remaining memory, it may also be triggered to execute.

[0053] In the embodiments of the present invention, the process has the commonly understood meaning.

[0054] In a specific embodiment, the second process may be created by means of the fork function. Here, the first process is the main process or the parent process, and the second process is the child process.

[0055] Specifically, generating the second process of the application based on the first process of the running application may include:

[0056] A1: The first process calls the fork function to create the second process.

[0057] When the main process creates the newly running child process by calling the fork function, the child process copies the entire virtual address space of the main process or the parent process. That is, the child process obtains an identical (but independent) copy of the virtual address space of the parent process, or it can be said that both have the same but independent address spaces. However, the physical memory corresponding to the virtual address space is not copied. When the fork function is called and executed, the two processes can have the same user stack, the same local variable values, the same heap, the same global variable values, and the same code. At this time, the virtual addresses and physical addresses corresponding to the variable x in the main process and the child process are the same. Correspondingly, the two processes have the same memory object reference relationship. Here, the main process and the child process can have different process identifiers (PIDs).

[0058] Here, for example, referring to Figure 6 , a schematic diagram according to an exemplary instance is shown. Since the child process copies the entire virtual address space of the main process or the parent process, it can then have the same mapping relationship of virtual memory addresses and physical memory addresses (after the fork function is executed). The mapping relationship can be in the form of a page table. The page table can allow the address translation unit in the memory management unit (MMU) in the operating system and the processor to obtain the corresponding mapping relationship between the virtual memory addresses and physical memory addresses of the two processes. Here, the main process and the child process (after the fork function is executed) can have the same but independent virtual address spaces. In this case, all the picture type objects in the memory can be determined in the second process, such as the child process (which are also the picture type objects in the first process, such as the parent process).

[0059] In Figure 6 the example shown, the virtual memory is divided into N consecutive byte-sized virtual pages (VPs) as the schematic virtual address space unit; correspondingly, M consecutive byte-sized physical pages (PPs) are divided from the physical memory (which is used for both the main process and the child process here) as the schematic physical address space unit, and the mapping between the two is schematically represented (for example, in the form of a page table). Here, hereinafter, each page will represent the storage space of one (picture) object or data, but it can be thought that this is only for the sake of facilitating the schematic definition of the example of the present invention and does not constitute a limitation on the actual running state. As Figure 6 shown, the mapping of the virtual address space and physical address space (pages) of the main process and the child process (after fork) is as follows: VP1→PP2, VP2→PP5, VP3→PP7, VP4→PP8, VP5→PP11, VP6→PP12.

[0060] Afterwards, changes (if any) made by the parent process and the child process to the local variable x are independent and do not reflect in the (physical) memory space of the other process. In some embodiments, this can be referred to as "copy-on-write", that is, when the virtual address space of each process is written, the corresponding physical memory space is copied. At this time, the virtual addresses corresponding to the variable x in the parent and child processes are still the same, but the physical addresses are different.

[0061] S102: Based on the memory object reference relationship, extract the list of picture objects in the memory of the running application in the second process;

[0062] Such as Figure 3 In the illustrated embodiment, step S102 may include:

[0063] S301: Based on the memory object reference relationship, dump the memory information of the running application in the second process;

[0064] Here, for example, after the first process, such as the main process, creates a child process by calling the fork function and the child process has the same memory object reference relationship as the main process, the memory information of the first process, such as the main process, can be dumped in the second process, such as the child process, by means of the dump function. In particular, the application heap (APP Heap) (the same as that of the first process) can be dumped in the child process. For example, in an operating system using a Java virtual machine (JVM), such as the Android system (as described below), in a terminal, such as a mobile terminal, a memory heap snapshot of the program process can be obtained by means of the heap dump. Figure 11 In the terminal, such as a mobile terminal, as described above, a memory heap snapshot of the program process can be obtained by means of the heap dump.

[0065] S302: Detect the data format in the dumped memory information in the second process to determine all picture objects in the memory;

[0066] With the help of the memory information, the second process can determine all picture objects in the memory information of the first process (when fork is executed).

[0067] S303: Generate the list of picture objects for all picture objects in the memory.

[0068] In these embodiments, the list of picture objects may be data obtained from a page table or in a modified form of the page table, which may allow the address translation unit in the memory management unit (MMU) of the operating system or the processor to obtain the corresponding mapping relationship between the virtual memory addresses and physical memory addresses of duplicate pictures in the first process. By way of explanation and not limitation, this can be used for the first process, such as the main process, to merge the object references of multiple duplicate pictures and reference the same picture object, as further described below. As a schematic example, assuming that all picture objects (byte streams) are respectively in the physical addresses (pages) mapped by the above VP1 to VP6, the above virtual memory addresses (VP1 to VP6) and physical memory addresses (PP2, PP5, PP7, PP8, PP11, PP12) and the list of picture objects mapped thereby can be obtained, which may be in the form of data obtained from the page table or a modified form of the page table.

[0069] In the described embodiments, by way of explanation and not limitation, since the first and second processes (when generating the second process, such as at fork) have the same virtual space addresses and memory object reference relationships, it is possible to determine all files of a specified type in the first process of the running APP (when generating the second process, such as at fork), here picture type files, and thereby obtain a list of objects, including the above virtual memory addresses and physical memory addresses and their mapping relationships.

[0070] In this embodiment, more precisely, the list of picture objects in the memory of the running application is the list of picture objects in the memory of the first process (when generating the second process, such as at fork), and the second process has the same memory information, for example, by generating and copying (such as fork).

[0071] S103: Determine the duplicate pictures in the list of picture objects in the second process and the virtual addresses of the duplicate pictures in the virtual address space;

[0072] As a schematic example, for example, referring to Figure 7 the schematic diagram shown. For example, it can be determined that there are duplicate pictures in VP1 (PP2), VP3 (PP7), VP4 (PP8) and VP6 (PP11), the same pictures that are repeatedly allocated. Thus, these duplicate pictures can be determined in the child process, and their virtual memory addresses can be correspondingly determined. By way of explanation and not limitation, obtaining the virtual memory addresses of duplicate pictures in the described embodiments can avoid the influence of, for example, the aforementioned "copy-on-write". In Figure 7 the example shown, it is still shown that the two processes have the same physical memory address for the convenience of description and understanding, but this is not necessarily the case in the embodiments of the present invention.

[0073] In multiple embodiments of the present invention, duplicate pictures in memory (here, the dumped memory information) can be determined in various ways.

[0074] In a preferred embodiment, duplicate pictures can be determined by means of a hash function, that is, the method of a hash function. In some embodiments, it can also be called the "digital fingerprint" method.

[0075] For example, in Figure 4 the embodiment shown, step S103 may include:

[0076] S401: Process the byte stream of each picture object in the picture object list by using a hash function to obtain the hash value of each picture object;

[0077] S402: Compare whether the hash values of the picture objects are the same to determine the duplicate pictures;

[0078] S403: Generate a list of virtual addresses corresponding to the duplicate pictures.

[0079] In a more specific embodiment, the hash function method is based on the MD5 algorithm. By way of explanation and not limitation, the MD5 Message-Digest Algorithm belongs to a cryptographic hash function, which can produce a 128-bit (16-byte) hash value, which can also be simply referred to as the MD5 value here, for ensuring the integrity and consistency of information transmission.

[0080] In some embodiments of the present invention, other methods can be used to determine duplicate pictures.

[0081] In a preferred embodiment, before implementing the step of determining duplicate pictures, preprocessing, such as a pre-grouping step, can be adopted.

[0082] For example, in the Bitmap picture type, pictures can be grouped by obtaining picture attributes. In a preferred embodiment, for example, pictures can be grouped by picture size, for example, based on the width and height attributes of the picture (such as mWindth, mHeight), so that pictures with the same attributes can be divided into a group, for example, to reduce the (sub-process) memory overhead occupied by using the hash function method to determine duplicate pictures. In some embodiments, a threshold criterion can also be additionally introduced for duplicate picture determination based on grouping. For example, only groups larger than a preset threshold are subject to picture duplicate checking, which can greatly reduce the workload of picture duplicate checking and reduce the memory overhead.

[0083] For example, the method may further include:

[0084] B1: Group all the picture objects in the memory based on preset picture object attributes, such as the width and height attributes of the picture objects, so that picture objects with the same picture object attributes, such as the width and height attributes of the picture objects, are grouped into one group.

[0085] Optionally, step S103 may include:

[0086] B2: Determine the duplicate pictures in the picture object groups that meet the preset threshold criteria.

[0087] In some embodiments, the preprocessing, such as the pre-grouping step, may be combined with the previous steps.

[0088] For example, the aforementioned step S303 may include step B1 above, and S304 may specifically include:

[0089] B3: Generate multiple lists of the picture objects for all the picture objects in the memory, where each list of picture objects corresponds to a group of picture objects.

[0090] S104: Obtain the virtual addresses of the duplicate pictures by the first process;

[0091] Here, referring to Figure 8 the example, and combining with Figure 9 the process schematic diagram, the first process can obtain the virtual addresses of the duplicate pictures determined in the second process, such as VP1(PP2), VP3(PP7), VP4(PP8), and VP6(PP11).

[0092] S105: Based on the virtual addresses of the duplicate pictures obtained by the first process, modify the memory object reference relationship of the first process so that the virtual addresses of the duplicate pictures in the first process merge to reference the same object in the memory.

[0093] Here, continuing to refer to Figure 8 the example, after the first process obtains the virtual addresses of the duplicate pictures determined in the second process, the virtual addresses of the duplicate pictures in the first process can be made to merge and reference. In the shown example, it can be understood that, only for the purpose of easy explanation, Figure 8 the example only schematically describes modifying the mapping relationship between the virtual memory and the physical memory in the first process, such as modifying the mappings of VP3→PP7, VP4→PP8, and VP6→PP12 to VP3, VP4, and VP6 all mapping to PP2, while the mapping of VP1→PP2 remains unchanged. In some embodiments, redundant object references can be eliminated.

[0094] In some preferred embodiments, the objects of the merged references are selected. In a preferred embodiment, the objects to which the merged references are made can be selected based on minimizing, i.e., locality, such as spatial locality.

[0095] For example, in some embodiments, step S105 may include:

[0096] C1: Select the same object to be merged and referenced in such a way that the (virtual and / or physical) memory space distance of the same object called by the first process, such as the main process, during subsequent execution is minimized.

[0097] In some embodiments, the method may further include:

[0098] D1: After modifying the memory object reference relationship of the first process to make the virtual addresses of the duplicate pictures in the first process merge and reference the same object in the memory, reclaim the space of the duplicate picture objects that are no longer referenced in the memory.

[0099] However, it can be conceived that in some embodiments, the method according to the present invention may not reclaim the space of the duplicate picture objects that are no longer referenced in the memory; for example, in the case where the references to the duplicate picture objects have been eliminated, the space is reclaimed by the free reclaim mechanism of the operating system, such as the Android system.

[0100] Here, referring to Figure 8 the example, it is schematically shown that the spaces of PP7, PP8, and PP12 have been reclaimed.

[0101] In some embodiments, the method may further include:

[0102] E1: After the first process obtains the virtual address of the duplicate picture, terminate the second process.

[0103] Here, referring to Figure 8 the example, and in combination with Figure 9 the process schematic diagram, the second process, such as the child process, can be terminated (schematically shown by a dashed line that the second process is destroyed) after the first process obtains the virtual address of the duplicate picture to reduce the (device) memory overhead. In some embodiments, as Figure 9 shown, the exit function can be called to terminate the child process, and the main process continues.

[0104] Those skilled in the art will understand that in the method according to the embodiments of the present invention, the termination is optional.

[0105] Thus, in the embodiments of the present invention, by independently creating a second process, such as a child process, that replicates the virtual memory address space and has the same memory object reference relationship, and using this to determine duplicate pictures, it is possible to avoid the improper impact on the operation of the main process of the application when processing duplicate pictures to reclaim memory, and also avoid the adverse occupation of the memory space pulled by the main process, which is often very precious. Thus, although the solution according to the embodiments of the present invention seemingly temporarily increases the memory consumption at the system level, the usage experience of the application is significantly improved.

[0106] In some embodiments of the present invention, such as Figure 5 shown, there is also provided a device 500 for processing duplicate pictures in memory, which may be, for example, for a terminal device. The device 500 may include a generation unit 501, an extraction unit 502, a determination unit 503, an acquisition unit 504, and a combined reference unit 505.

[0107] In the illustrated embodiment, the generation unit 501 may be configured to generate a second process of the application based on the first process of the running application. In some embodiments, the second process has the same virtual address space and memory object reference relationship as the first process. In the illustrated embodiment, the extraction unit 502 may be configured to extract a list of picture objects of the running application in the memory in the second process based on the memory object reference relationship. In the illustrated embodiment, the determination unit 503 may be configured to determine duplicate pictures in the list of picture objects in the second process and the virtual addresses of the duplicate pictures in the virtual address space. In the illustrated embodiment, the acquisition unit 504 may be configured to obtain the virtual addresses of the duplicate pictures from the first process. In the illustrated embodiment, the combined reference unit 505 may be configured to modify the memory object reference relationship of the first process based on the virtual addresses of the duplicate pictures obtained by the first process so that the virtual addresses of the duplicate pictures in the first process merge and reference the same object in the memory.

[0108] Those skilled in the art will understand that, without contradiction, the device of this embodiment can incorporate the method features described in other embodiments, and vice versa.

[0109] In the embodiments of the present invention, there is provided an electronic device, especially a terminal device. In a preferred embodiment of the present invention, the device is a mobile terminal, preferably a mobile phone. Only as an exemplary implementation solution, Figure 10 shows a schematic hardware structure diagram of a specific embodiment of a terminal device, such as a mobile terminal 1000; and Figure 11 shows a schematic system structure diagram of a specific embodiment of a terminal device, such as a mobile terminal.

[0110] In the illustrated embodiment, the mobile terminal 1000 may include a processor 1001, a RAM 1010, a ROM 1012, a Universal Serial Bus (USB) interface 1013, a charging management module 1014, a power management module 1015, a battery 1016, a mobile communication module 1040, a wireless communication module 1042, antennas 1039 and 1041, an audio module 1034, a speaker 1035, a receiver 1036, a microphone 1037, a headset interface 1038, keys 1009, a motor 1008, an indicator 1007, a subscriber identity module (SIM) card interface 1011, a display screen 1005, a camera device 1006, and a sensor module 1020, etc.

[0111] It can be understood that the structure illustrated in the embodiments of the present application does not constitute a specific limitation on the mobile terminal 1000. In other embodiments of the present application, the mobile terminal 1000 may include more or fewer components than those illustrated, or combine certain components, or split certain components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.

[0112] In some embodiments, the processor 1001 may include one or more processing units. In some embodiments, the processor 1001 may include one of the following or a combination of at least two of the following: an application processor (AP), a modulation and demodulation processor, a baseband processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, a neural network processor (NPU), etc. Different processing units may be independent devices or integrated in one or more processors.

[0113] The controller may be the nerve center and command center of the mobile terminal 1000. The controller may generate operation control signals according to the instruction operation code and timing signals to complete the control of fetching and executing instructions.

[0114] A memory may also be provided in the processor for storing instructions and data. In some embodiments, the memory in the processor is a cache memory (Cache) 1019.

[0115] The digital signal processor (ISP) is used to process digital signals. In addition to processing digital image signals, it can also process other digital signals.

[0116] In some embodiments, the processor 1001 may include one or more interfaces. The interfaces may include an Inter-Integrated Circuit (I2C) interface, an Inter-IC Sound (I2S) interface, a Pulse Code Modulation (PCM) interface, a Universal Asynchronous Receiver / Transmitter (UART) interface, a Mobile Industry Processor Interface (MIPI), a General-Purpose Input / Output (GPIO) interface, a Subscriber Identity Module (SIM) interface, a Universal Serial Bus (USB) interface, etc.

[0117] In an embodiment of the present invention, the RAM 1010 is an internal memory that directly exchanges data with the processor. Especially, for example, in the context of a mobile terminal, such as a smart phone, in some embodiments, the memory may be or include the RAM 1010; Depending on the specific situation, in some embodiments of the present invention, the RAM may be used interchangeably with the (physical) memory or main memory. In some embodiments of the present invention, especially, for example, in the context of a mobile terminal, such as a smart phone, the RAM 1010 may be of the Low Power Double Data Rate (LPDDR) type.

[0118] Those skilled in the art will understand that, especially, for example, in the context of a mobile terminal, such as a smart phone, in some embodiments, the RAM 1010 and the ROM 1012 may be integrated with the processor 1001 to form a System-on-Chip (SoC) structure.

[0119] It can be understood that the interface connection relationships between the modules illustrated in the embodiments of this application are only illustrative descriptions and do not constitute a structural limitation on the mobile terminal. In other embodiments of this application, the mobile terminal may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.

[0120] The wireless communication function of the mobile terminal 1000 can be implemented through antennas 1039 and 1041, a mobile communication module 1040, a wireless communication module 1042, a modulation / demodulation processor, or a baseband processor, etc.

[0121] The mobile terminal 1000 can implement audio functions through an audio module, a speaker, a receiver, a microphone, a headset interface, and an application processor, etc. For example, music playback, recording, etc.

[0122] The audio module is used to convert digital audio information into an analog audio signal for output, and is also used to convert an analog audio input into digital audio signals.

[0123] The microphone is used to convert a sound signal into an electrical signal. When making a call or sending a voice message, the user can make a sound close to the microphone with their mouth to input the sound signal into the microphone.

[0124] The sensor module 1020 may include one or more of the following sensors:

[0125] The pressure sensor 1023 is configured to sense a pressure signal and convert the pressure signal into an electrical signal.

[0126] The barometric pressure sensor 1024 is used to measure barometric pressure.

[0127] The magnetic sensor 1025 includes a Hall sensor.

[0128] The gyroscope sensor 1027 can be used to determine the motion posture of the mobile terminal 1000.

[0129] The acceleration sensor 1028 can detect the magnitude of the acceleration of the mobile terminal 1000 in various directions.

[0130] The distance sensor 1029 can be configured to measure distance.

[0131] The proximity light sensor 1021 can include, for example, a light-emitting diode (LED) and a light detector, such as a photodiode.

[0132] The ambient light sensor 1022 is used to sense the ambient light brightness.

[0133] The fingerprint sensor 1031 can be configured to collect fingerprints.

[0134] The touch sensor 1032 can be disposed on the display screen. The touch sensor and the display screen form a touch screen, also known as a "touch control screen". The touch sensor is used to detect a touch operation acting thereon or nearby. The touch sensor can transmit the detected touch operation to the application processor to determine the type of touch event according to the embodiments of the present invention, such as single click, double click, long press, rotation, slide, zoom, etc.

[0135] The bone conduction sensor 1033 can acquire vibration signals.

[0136] The software operating system of an electronic device (computer), such as a mobile terminal, can adopt a layered architecture, an event-driven architecture, a microkernel architecture, a microservices architecture or a cloud architecture.

[0137] The embodiments shown herein take the Android operating system platform of the layered architecture as an example to exemplarily illustrate the software structure of the mobile terminal. However, it can be conceived that the embodiments herein can be implemented in different software operating systems.

[0138] Figure 11 It is a schematic diagram of the Android operating system structure. The solution of the embodiments of the present invention can adopt the Android operating system. The layered architecture divides the software into several layers, and the layers communicate through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom are the application layer 1110, the application framework layer 1120, the Android Runtime and system libraries 1130, and the kernel layer 1140.

[0139] The application layer 1110 may include a series of application packages.

[0140] The application framework layer 1120 provides application programming interfaces (APIs) and programming frameworks for the applications in the application layer. The application framework layer includes some predefined functions.

[0141] The window manager is used to manage window programs.

[0142] The content provider is used to store and obtain data, and make this data accessible to applications.

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

[0144] The telephone manager is used to provide the communication function of the mobile terminal.

[0145] The resource manager provides various resources for applications, such as localized strings, icons, pictures, layout files, video files, etc.

[0146] The notification manager enables applications to display notification information in the status bar, can be used to convey notification-type messages, and can disappear automatically after a short stay without user interaction.

[0147] Android Runtime includes core libraries and a virtual machine. Android Runtime is responsible for the scheduling and management of the Android system. The core libraries contain two parts: one part is the functional functions to be called by the Java language, and the other part is the core libraries of Android. The application layer and the framework layer run in the virtual machine.

[0148] The system libraries may include multiple functional modules. The surface manager is used to manage the display subsystem and provides the fusion of 2D and 3D layers for multiple applications.

[0149] The media library supports the playback and recording of multiple common audio and video formats, as well as static image files, etc.

[0150] The kernel layer 1140 is the layer between hardware and software. The kernel layer may include display drivers, camera drivers, audio interfaces, sensor drivers, power management, and GPS interfaces.

[0151] In some embodiments of the present invention, a computer system may further be provided, which includes: a processor and a memory storing a computer program, and the processor is configured to execute the method of any embodiment of the present invention when the computer program is running.

[0152] The systems, devices, modules or units illustrated in the above or below embodiments of the present invention may be implemented by a computer or its associated components. Depending on the specific situation, the computer may be, for example, a mobile terminal, a smart phone, a personal computer (PC), a laptop computer, an in-vehicle human-machine interaction device, a personal digital assistant, a media player, a navigation device, a game console, a tablet computer, a wearable device, a smart TV, an Internet of Things system, a smart home, an industrial computer or a combination thereof.

[0153] In some embodiments of the present invention, a storage medium may further be provided. In some embodiments, the storage medium stores a computer program, and the computer program is configured to execute the method of any embodiment of the present invention when it runs.

[0154] The storage medium in the embodiment of the present invention may include permanent and non-permanent, removable and non-removable articles that can implement information storage by any method or technology. Examples of the storage medium include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read only memory (ROM), electrically erasable programmable read only memory (EEPROM), flash memory or other memory technologies, compact disc read only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette tapes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission medium that can be used to store information accessible by a computing device.

[0155] The methods, programs, systems, devices, etc. in the embodiments of the present invention may be executed or implemented in a single or multiple networked computers, and may also be practiced in a distributed computing environment. In the embodiments of this specification, in these distributed computing environments, tasks may be executed by remote processing devices connected through a communication network.

[0156] Those skilled in the art should understand that the embodiments of this specification may be provided as a method, a system or a computer program product. Therefore, those skilled in the art may think that the implementation of the functional modules / units or controllers and related method steps illustrated in the above embodiments may be achieved in a software, hardware or a combination of software and hardware manner.

[0157] Unless otherwise specified, the acts or steps of the methods, procedures according to the embodiments of the present invention do not have to be executed in a specific order and still can achieve the desired results. In some embodiments, multitasking and parallel / merged processing of the steps are also possible or may be advantageous.

[0158] In this document, "first" and "second" are used to distinguish different elements in the same embodiment and do not refer to order or relative importance.

[0159] In this document, multiple embodiments of the present invention are described. For the sake of brevity, the descriptions of each embodiment are not exhaustive, and the same or similar features or parts between the embodiments may be omitted. In this document, "one embodiment", "some embodiments", "example", "specific example", or "some examples" mean applicable to at least one embodiment or example according to the present invention, rather than all embodiments. The above terms do not necessarily mean referring to the same embodiment or example. Without contradiction, those skilled in the art can combine and combine the different embodiments or examples described in this specification and the features of different embodiments or examples.

[0160] The exemplary systems and methods of the present invention have been specifically shown and described with reference to the above embodiments, which are only examples of the best mode for implementing the systems and methods. Those skilled in the art can understand that various changes can be made to the embodiments of the systems and methods described herein when implementing the systems and / or methods without departing from the spirit and scope of the present invention defined in the appended claims.

Claims

1. A method for processing duplicate images in memory, characterized in that: include: generating a second process of the application program based on a first process of the running application program, wherein the second process has the same virtual address space and memory object reference relationship as the first process; Based on the memory object reference relationship, extracting, in the second process, a list of picture objects of the running application in the memory; Determining, in the second process, duplicate pictures in the picture object list and virtual addresses of the duplicate pictures in the virtual address space, wherein determining, in the second process, the duplicate pictures in the picture object list comprises: grouping picture objects having the same picture object attributes based on preset picture object attributes, and determining the duplicate pictures in the picture object group that meets a preset threshold standard; Obtaining, by the first process, a virtual address of the repeated image; Based on the virtual address of the duplicate image obtained by the first process, modifying the memory object reference relationship of the first process so that the virtual addresses of the duplicate image in the first process merge and reference the same object in memory, including: selecting the same object to be merged and referenced so that the memory space distance of calling the same object by the first process in subsequent execution processes is minimized; After modifying the memory object reference relationship of the first process so that the virtual addresses of the duplicate pictures in the first process merge to reference the same object in the memory, the space of the duplicate picture objects that are no longer referenced in the memory is reclaimed.

2. The method according to claim 1, characterized in that The generating the second process of the application based on the first process of the running application includes: Detect whether the memory status meets the preset threshold conditions; In response to the memory state meeting the preset threshold condition, the second process is generated.

3. The method according to claim 1, characterized in that The generating the second process of the application based on the first process of the running application includes: The first process calls a fork function to create the second process.

4. The method according to claim 1, wherein The extracting, in the second process, a list of picture objects of the running application in the memory based on the memory object reference relationship includes: dumping memory information of the running application in the second process based on the memory object reference relationship; Detecting a data format in the memory information dumped in the second process to determine all image objects in the memory; For all the picture objects in the memory, the picture object list is generated.

5. The method according to claim 1, wherein The determining, in the second process, the duplicate pictures in the picture object list and the virtual addresses of the duplicate pictures in the virtual address space includes: Processing the byte stream of each picture object in the picture object list using a hash function to obtain a hash value of each picture object; Comparing the hash values of the picture objects to determine whether they are the same to determine the duplicate picture; Generate a virtual address list corresponding to the repeated pictures.

6. The method according to claim 1, characterized in that Also includes: After the first process obtains the virtual address of the repeated image, the second process is terminated.

7. The method according to any one of claims 1 to 6, characterized in that The picture is a bitmap.

8. An electronic device, characterized in that: include: A processor and a memory storing a computer program, wherein the processor is configured to execute the method for processing repeated images in a memory according to any one of claims 1 to 7 when running the computer program.

9. A storage medium, characterized in that: The storage medium stores a computer program, which is configured to execute the method for processing repeated images in a memory according to any one of claims 1 to 7 when executed.

Citation Information

Patent Citations

  • Repeated picture detection method and apparatus

    CN107169057A

  • Memory dump method and device, and electronic equipment

    CN111638952A

  • Merging identical memory pages

    US20070038837A1