Memory Management Method, Device, Medium and Product
By obtaining memory management information of Avalonia framework applications, memory counting, memory pool management, image compression and memory defragmentation are used to optimize memory, which solves the memory usage problem of Avalonia framework when processing large amounts of data, and improves the performance and stability of the application.
Patent Information
- Application Number
- CN202411250595.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-06
- Publication Date
- 2025-07-29
- Estimated Expiration
- 2044-09-06
AI Technical Summary
The Avalonia framework is difficult to effectively reduce memory usage when processing large amounts of data, resulting in waste of memory resources and slow and stuttering application operations.
Optimize memory management by obtaining the application's memory management information, including reference quantity information, object creation and destruction information, graphic element feature information, memory block information, and calling reference counting methods, memory pool management, image compression and memory defragmentation.
It effectively reduces the memory usage of data, reduces the waste of memory resources, improves the operation speed and stability of the application, and improves the user experience.
Smart Images

Figure CN119105872B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of memory management. Specifically, this application relates to a memory management method, device, medium, and product. Background Art
[0002] Avalonia is a powerful framework that enables developers to create cross-platform applications using.NET. It uses its own rendering engine to draw UI controls, ensuring a consistent appearance and behavior across various platforms, including Windows, macOS, Linux, Android, iOS, and WebAssembly. This means that developers can share their UI code and maintain a unified look and feel regardless of the target platform.
[0003] Due to the above characteristics of Avalonia, it is widely used in the development of the graphical user interface (GUI) of various applications. However, as the functions of applications become more complex, the amount of data to be processed increases day by day. But after the amount of data increases, Avalonia is difficult to effectively reduce the memory occupancy of a large amount of data, and it is easy to have problems such as waste of memory resources and slow and laggy operation of the application due to insufficient memory, reducing the application performance. Summary of the Invention
[0004] Embodiments of this application provide a memory management method, device, medium, and product, which can solve the problem that existing Avalonia is difficult to effectively reduce the memory occupancy of a large amount of data, and is prone to problems such as waste of memory resources and slow and laggy operation of the application due to insufficient memory. To achieve this purpose, the embodiments of this application provide the following several solutions.
[0005] According to one aspect of the embodiments of this application, a memory management method is provided for an application generated based on the Avolonia framework. The method includes:
[0006] Obtain the memory management information corresponding to the application, where the memory management information includes at least one of reference count information, object creation and destruction information, graphic element feature information, and memory block information;
[0007] Call the corresponding memory management method to optimize memory according to the memory management information, where the memory management method includes at least one of reference counting method, memory pool management, image compression, and memory fragmentation reorganization.
[0008] In a possible implementation manner, the memory management information includes reference count information, and the calling the corresponding memory management method to optimize memory according to the memory management information includes:
[0009] Determine the counting object corresponding to the reference counting method, and record the reference count of the counting object according to the reference quantity information;
[0010] If it is determined that the reference count is zero, clean up the references and resources associated with the counting object, and release the memory space occupied by the counting object.
[0011] In a possible implementation, the memory management information includes the creation and destruction information of objects. The call to the corresponding memory management method to optimize memory according to the memory management information includes:
[0012] Determine the memory management object corresponding to the memory pool management according to the creation and destruction information;
[0013] Create a memory pool to accommodate the memory management object;
[0014] Determine the use and return of memory blocks in the memory pool according to the creation and destruction of the memory management object.
[0015] In a possible implementation, the memory management information includes graphic element feature information. The call to the corresponding memory management method to optimize memory according to the memory management information includes:
[0016] Obtain the image to be processed, and convert the color space of the image to a preset space;
[0017] Perform quantization processing on the image after converting the color space according to the graphic element feature information to obtain image data;
[0018] Compress the image data according to the probability distribution of the image data.
[0019] In a possible implementation, the call to the corresponding memory management method to optimize memory according to the memory management information includes:
[0020] Obtain the optimization information corresponding to the image according to the graphic element feature information, where the optimization information is at least one of vertex repetition information, edge information, and structure information;
[0021] Reduce the data volume of the image data according to the optimization information.
[0022] In a possible implementation, the memory management information includes memory block information. The call to the corresponding memory management method to optimize memory according to the memory management information includes:
[0023] Obtain adjacent and free memory blocks according to the memory block information, where the memory block information includes at least one of start address, size, and usage status;
[0024] Merge the free memory blocks and arrange the used memory blocks according to a preset rule;
[0025] If a memory block allocation instruction is detected, allocate a memory block based on the memory block allocation instruction and the merge result.
[0026] In a possible implementation, the method includes:
[0027] If it is determined that a loading operation is to be performed, obtain the scenario data corresponding to the loading operation, and perform memory allocation, monitoring, and release according to the scenario data, where the scenario data includes at least one of the number of loading objects, texture information corresponding to the loading objects, number of frames, and special effect complexity.
[0028] According to one aspect of the embodiments of the present application, there is provided an electronic device, including a memory, a processor, and a computer program stored on the memory, where the processor executes the computer program to implement the steps of the method as described above.
[0029] According to one aspect of the embodiments of the present application, there is provided a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the method as described above are implemented.
[0030] According to one aspect of the embodiments of the present application, there is provided a computer program product, including a computer program, and when the computer program is executed by a processor, the steps of the method as described above are implemented.
[0031] The beneficial effects brought by the technical solutions provided by the embodiments of the present application are:
[0032] The memory management method provided by the present application obtains memory management information corresponding to an application, where the memory management information includes at least one of reference quantity information, creation and destruction information of objects, graphic element feature information, and memory block information; calls a corresponding memory management method to optimize memory according to the memory management information, and the memory management method includes at least one of a reference counting method, memory pool management, image compression, and memory fragmentation reorganization. The embodiments of the present application add a new memory management method outside the memory management method of Avalonia itself, and can select a corresponding memory management method according to the obtained memory management information to optimize memory, thereby effectively reducing the memory occupancy of data, reducing memory resource waste, and the possibility of slow and stuck application operation, and improving the user experience. Description of the Drawings
[0033] To more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required for description in the embodiments of the present application.
[0034] Figure 1Flow chart of the memory management method provided by the embodiments of the present application;
[0035] Figure 2 Schematic diagram of the execution process of the reference counting method in the memory management method provided by the embodiments of the present application;
[0036] Figure 3 Schematic diagram of the execution process of the memory pool technology in the memory management method provided by the embodiments of the present application;
[0037] Figure 4 Schematic diagram of the execution process of image compression in the memory management method provided by the embodiments of the present application;
[0038] Figure 5 Schematic diagram of the execution process of memory fragmentation reorganization in the memory management method provided by the embodiments of the present application;
[0039] Figure 6 Schematic diagram of the implementation process of the integration of the application and the Avolonia framework in the memory management method provided by the embodiments of the present application;
[0040] Figure 7 Flow chart of an embodiment of the memory management method provided by the embodiments of the present application;
[0041] Figure 8 Structural diagram of the electronic device of the present application. Detailed implementation manners
[0042] The embodiments of the present application will be described below with reference to the accompanying drawings in the present application. It should be understood that the embodiments described below with reference to the accompanying drawings are exemplary descriptions for explaining the technical solutions of the embodiments of the present application, and do not constitute limitations on the technical solutions of the embodiments of the present application.
[0043] Those skilled in the art of the present technology can understand that, unless specifically stated otherwise, the singular forms "a", "an", "the" and "said" used herein may also include the plural forms. It should be further understood that the terms "including" and "comprising" used in the embodiments of the present application mean that the corresponding features can be implemented as the presented features, information, data, steps, operations, elements and / or components, but do not exclude being implemented as other features, information, data, steps, operations, elements, components and / or their combinations supported by the art of the present technology. It should be understood that when we say an element is "connected" or "coupled" to another element, the one element can be directly connected or coupled to the other element, or it can mean that the one element and the other element establish a connection relationship through an intermediate element. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein indicates at least one of the items defined by the term, for example, "A and / or B" indicates being implemented as "A", or being implemented as "A", or being implemented as "A and B".
[0044] To make the objectives, technical solutions, and advantages of this application clearer, the following will further describe the implementation manners of this application in detail with reference to the accompanying drawings.
[0045] The following describes the technical solutions of the embodiments of this application and the technical effects produced by the technical solutions of this application through the description of several exemplary implementation manners. It should be noted that the following implementation manners can refer to, draw on, or combine with each other. For the same terms, similar features, and similar implementation steps in different implementation manners, they will not be described repeatedly.
[0046] The memory management method, device, medium, and product provided by this application aim to solve at least one technical problem existing in the prior art.
[0047] In an embodiment of this application, a memory management method is provided. Executing this memory management method can be applied to mobile phones, computers, cloud servers, and other terminals that can load applications generated based on the Avolonia framework.
[0048] Optionally, the memory management method of this application is used for applications generated based on the Avolonia framework. This application can perform data interaction with a remote server through FRP (Frontend Reverse Proxy) technology to ensure the real-time, stable, and secure nature of the data.
[0049] Optionally, as Figures 1-7 shown, the memory management method includes:
[0050] S101: Obtain the memory management information corresponding to the application.
[0051] Optionally, the memory management information includes at least one of reference count information, object creation and destruction information, graphic element feature information, and memory block information. Among them, the memory management information can be obtained according to the received instruction, can also be triggered based on the currently executed operation for obtaining the memory management information, or can be obtained according to the set frequency. The operation of obtaining the memory management information can also be automatically executed after the application is started.
[0052] Optionally, when obtaining the memory management information, the obtaining method, obtaining conditions, and obtaining scenario of the memory management information can be determined according to the type of the memory management information. If it is determined that the current conditions for obtaining are met and it is in the obtaining scenario, the memory management information is obtained according to the obtaining method.
[0053] In one embodiment, after the application is started, the reference count information, object creation and destruction information, graphic element feature information, and memory block information are automatically obtained to optimize the memory using the obtained information.
[0054] S102: Optimize the memory by calling the corresponding memory management method according to the memory management information.
[0055] Optionally, the memory management method includes at least one of reference counting method, memory pool management, image compression, and memory fragmentation reorganization. The memory management information corresponding to different memory management methods is different.
[0056] Optionally, the memory management information includes reference quantity information. Optimizing the memory by calling the corresponding memory management method according to the memory management information includes: determining the counting object corresponding to the reference counting method, and recording the reference quantity of the counting object according to the reference quantity information; if it is determined that the reference quantity is zero, then clean up the references and resources associated with the counting object, and release the memory space occupied by the counting object.
[0057] Optionally, the objects that need to be referenced related to the application can be obtained, and the object can be determined as the counting object. The reference quantity information may include information on the new reference or reduced reference of the counting object, and the reference quantity of the counting object is modified according to this information. The time to release the memory space is determined by this reference quantity.
[0058] Optionally, to record the reference quantity of the counting object, a data structure for counting can be created for each counting object. This data structure can be a private integer variable referenceCount. When a new reference points to the counting object, the operation of increasing the reference corresponding to the counting object is executed, and the reference quantity of the counting object increases, that is, referenceCount is incremented by 1. When a certain reference no longer points to the counting object, the operation of reducing the reference is triggered, and the reference quantity of the counting object decreases, and referenceCount is decremented by one.
[0059] Optionally, the reference quantity can also be recorded through a doubly linked list, a hash table, a tree structure, and other data structures that can store data.
[0060] Specifically, the doubly linked list can store all the pointers referencing the counting object in a doubly linked list. Each time a new reference is added, a node is added to the linked list; when the reference is reduced, the corresponding node is deleted from the linked list. The length of the linked list is used to reflect the reference quantity.
[0061] For example, in a graphics processing program, the counting object is an image object. For each image object, its reference quantity is stored in a doubly linked list. When multiple modules need to reference and operate the same image object simultaneously, the reference relationship can be clearly managed through the linked list.
[0062] The hash table stores the identifier of the reference-counted object as the key and the corresponding reference count as the value in the hash table. For example, in a network communication program, the counted object is the packet object. For different types of packet objects, a hash table is used to record their reference counts. This allows for quick lookup and update of the reference counts.
[0063] The tree structure (such as a binary search tree) uses the identifier of the counted object as the node value and the reference count as an additional attribute of the node. For example, in a file system management program, the counted object is the file object. For different file objects, their reference information is organized through a binary search tree for easy lookup and maintenance.
[0064] In one embodiment, as Figure 2 shown, to improve the accuracy of the reference count, a mutex or atomic operation can be used to ensure the accuracy and consistency of the reference count in a multi-threaded environment. Specifically, if a mutex is used, the System.Threading namespace can be used first. Then, an object of the Mutex class is created, such as Mutex mutex = new Mutex();. When an operation that requires mutual exclusion protection needs to be performed, the mutex.WaitOne(); method is called to attempt to acquire the mutex. If the mutex is occupied by another thread at this time, the current thread will be blocked and wait until the mutex is released. After successfully acquiring the mutex, operations such as reading the current referenceCount value and incrementing it by 1 can be performed. After the operation is completed, the mutex.ReleaseMutex(); method is called to release the mutex so that other waiting threads can acquire the mutex for corresponding operations. In this way, the thread safety of operations related to the reference count can be ensured in a multi-threaded environment. If atomic operations are used, the Interlocked.Increment method provided by the Interlocked class in C# can be used to implement a thread-safe increment operation. This method atomically increments the specified integer variable used to record the reference count by 1 and returns the new value after the increment.
[0065] When a certain reference no longer points to the counted object, an operation to decrease the reference is triggered. The current referenceCount value can be obtained in a thread-safe manner as well, such as using the same mutex or atomic operation mechanism as the increment operation. After obtaining the value of the reference count, it is decreased by 1. Subsequently, the value of the reference count after the decrease is immediately checked to see if it is 0.
[0066] If it is determined that the reference count is 0, it is determined that the counted object is no longer referenced by any object. At this time, the memory release process will be initiated. First, all references and resources associated with the object will be comprehensively cleared to ensure that there are no remaining associations. Then, according to the predetermined memory management rules and the standard interfaces of the operating system, the memory space occupied by the counted object will be safely and effectively released, and these memory resources will be returned to the available memory pool for subsequent use.
[0067] Optionally, the references and resources associated with the counted object may include:
[0068] 1. Some references that are not correctly executed or have delays during the execution of the application. For example, in complex code logic, there may be some abnormal situations that cause the cleaning code of some references not to be triggered.
[0069] 2. Circular references, that is, multiple objects reference each other to form a cycle, resulting in the reference relationship between these objects still existing even though the external references have been released.
[0070] 3. Some resources contained in the counted object, such as open file handles, network connections, etc., whose release operations may not be fully synchronized with the operation of reducing the reference count, resulting in these resources not being released when the reference count is 0.
[0071] 4. In a multi-threaded file handler, if an exception occurs when a thread is processing a file, it may cause the reference to the file object not to be correctly released. Or in a graphics handler, two graphics objects reference each other. When the external references to them are all cancelled, due to internal circular references, they still occupy the relevant memory and resources.
[0072] In one embodiment, there is a class named "DataObject" in the application. Initially, 500 "DataObject" objects are created. As the system runs, different modules perform reference operations on these objects. The reference counting method is used to accurately track the reference changes of each "DataObject" object. When the reference count of some objects drops to zero, approximately 200 unused objects are identified and released, along with approximately 80MB of memory they occupy. This process makes the use of memory more efficient and reasonable, greatly optimizing the memory utilization efficiency of the system, effectively avoiding the occurrence of memory leakage problems, and ensuring the stability and performance of the system. The reference counting method of this application has stronger adaptability and flexibility in managing the reference count. By accurately tracking reference changes, it can better handle the dynamic changes of object reference relationships in complex systems. Especially in large-scale and high-concurrency application scenarios, it can more accurately control the allocation and release of memory and optimize the memory usage efficiency.
[0073] Optionally, when the memory management information includes the creation and destruction information of objects, the corresponding memory management method is called according to the memory management information to optimize the memory, including: determining the memory management object corresponding to the memory pool management according to the creation and destruction information; creating a memory pool for accommodating the memory management object; determining the use and return of memory blocks in the memory pool according to the creation and destruction of the memory management object.
[0074] Optionally, the creation and destruction information may include the creation and destruction frequencies of each object and the business requirements. The business requirements may include the memory pool allocation requirements of each object, and the memory management object is determined based on the frequency and business requirements.
[0075] In one embodiment, the memory management object may be an object whose creation and destruction frequency is greater than a preset frequency. Specifically, the application is an online game. Since players frequently enter and exit the game room, the room object is frequently created and destroyed. The server determines the room object as the memory management object according to the preset frequency, and can accurately pre-allocate the memory pool based on the player activity and historical peak data, making the reuse and allocation of the room object more efficient, and greatly improving the server response speed and stability.
[0076] Optionally, the size of the memory pool may be determined by the peak value of the number of the memory management objects to be created. After creating the memory pool, if a new memory management object needs to be created, directly obtain an available memory block corresponding to the size of the memory management object from the free part of the memory pool; when the object is no longer used, mark it as reusable and return it to the memory pool, rather than directly releasing the memory back to the operating system. This method greatly reduces the system call overhead in the memory allocation and release process, and significantly improves the running efficiency of the program.
[0077] In one embodiment, as Figure 3 shown, in an application of real-time data processing, it is often necessary to create and destroy "DataPacket" objects (memory management objects) to transmit data. A memory pool that can accommodate 1000 "DataPacket" objects is created in advance. During the processing peak period, 800 "DataPacket" objects are created in a short time ("DataPacket" objects are entities with specific functions and structures used to transmit data in the real-time data processing application. When creating a "DataPacket" object, a corresponding memory block is obtained from the memory pool to store the data and related information of the "DataPacket" object). Since the memory block is obtained from the memory pool, frequent system memory allocation operations are avoided, and the processing speed is increased by 30%. When 500 objects are no longer used, they are promptly returned to the memory pool to prepare for subsequent use, effectively saving system resources.
[0078] Optionally, the memory management information includes graphic element feature information, and corresponding memory management methods are called according to the memory management information to optimize the memory, including: obtaining an image to be processed, converting the color space of the image to a preset space; performing quantization processing on the image after converting the color space according to the graphic element feature information to obtain image data; compressing the image data according to the probability distribution of the image data.
[0079] Optionally, the image element feature information may include features such as the color distribution law of the image, the complexity of the texture, and the geometric shape features of the graphics. Based on this feature, a corresponding compression algorithm is selected to compress the image, and color space conversion is performed on the compressed image.
[0080] Optionally, the preset space may be the YUV space, and a downsampling operation is performed based on this preset space.
[0081] In one embodiment, as Figure 4 shown, the image to be processed is an RGB image with a resolution of 4K (3840×2160 pixels), and each pixel is composed of 3 8-bit color channels (R, G, B). The original data volume is approximately: 3840×2160×3×8 = 199065600 bits = 24883200 bytes ≈ 24MB. After image compression, the image is converted from RGB to the YUV space by means of color space conversion. The conversion formula is:
[0082] 1. Y = 0.299R + 0.587G + 0.114B
[0083] 2. U = -0.14713R - 0.28886G + 0.436B
[0084] 3. V = 0.615R - 0.51499G - 0.10001B
[0085] After conversion, downsampling is performed on the U and V components of the image. The 4:2:0 sampling method can be used, that is, the resolutions of the U and V components in both the horizontal and vertical directions are 1 / 4 of the Y component. In this way, the data volume of the U and V components is reduced to 1 / 4 of the original. Among them, other sampling methods that can reduce the data volume of the U and V components can also be adopted.
[0086] Optionally, when performing quantization processing, quantization processing is performed on the Y, U, and V components according to the quantization step. The quantization formula can be:
[0087] Y' = round(Y / Q) U' = round(U / Q) V' = round(V / Q)
[0088] Wherein, Q is the quantization step size, Y' is the quantization result of the Y component, U' is the quantization result of the U component, and V' is the quantization result of the V component.
[0089] Optionally, the quantization step size can be adjusted according to the content and visual requirements of the image. The content of the image can include the degree of detail richness, and the visual requirements can include the accuracy requirements. Among them, the degree of detail richness can be determined by calculating the gradient or edge intensity of the image region. If the gradient is greater than the preset gradient or the edge intensity is greater than the preset intensity, it is determined that the region is rich in details. It is also possible to calculate the change in the gray value of the pixel points in the horizontal and vertical directions. When the change value is greater than the preset value, it is considered a region rich in details. The accuracy requirements can be determined according to the specific application scenario and image content. For example, in medical images, if it is determined that the region is a key lesion region, it is determined that the accuracy requirement corresponding to this region is greater than the first preset accuracy; in satellite images, if the region is a specific target recognition region, it is determined that the accuracy corresponding to this region is greater than the first preset accuracy. When the following conditions are met, a Q value that can be considered for use is less than a predetermined value (i.e., a smaller Q value): For example, if the gradient or edge intensity of the image region exceeds a certain threshold, such as the gradient value is greater than 50. Or for specific key targets or regions that need to be finely distinguished (i.e., the corresponding accuracy is greater than the first preset accuracy), such as the key parts like eyes and noses in face recognition. The smaller Q value can be determined according to the specific image quality requirements and data compression ratio. The Q value can be selected between 2 and 10. The specific size of the Q value depends on the type of the image and the specific application requirements (such as accuracy requirements). For example, for images with extremely high accuracy requirements (accuracy greater than the first preset accuracy), the Q value can be selected as 2 or 3; for images with relatively high accuracy requirements (accuracy less than the first preset accuracy but greater than the second preset accuracy) but still requiring a certain degree of compression (such as the data compression ratio is within the preset range), the Q value can be selected from 5 to 8.
[0090] Optionally, for smooth and less important regions in the image, a larger Q value (greater than or equal to the predetermined value) can be sampled for quantization. The Q value corresponding to this region can be determined by information such as the type of the image, resolution, content characteristics, required compression ratio, and the degree of image quality loss requirement. Specifically, the larger Q value can be greater than or equal to 10. For obtaining this Q value, a series of experiments and tests can be carried out to find the Q value that is most suitable for the specific image and application scenario. For example, the Q value can be gradually increased starting from 10, and at the same time, observe the quality of the compressed image and the data compression effect until a maximum Q value within the acceptable range of the image quality (meeting the degree of image quality loss requirement) is reached to achieve the optimal compression balance. The larger Q values corresponding to different images and application scenarios are different.
[0091] Optionally, the quantized image is subjected to encoding and compression processing to further reduce the data volume of the image.
[0092] Optionally, optimization information corresponding to the image can also be obtained according to the graphic element feature information, where the optimization information includes at least one of vertex repetition information, edge information, and structure information; and the data volume of the image data is reduced according to the optimization information.
[0093] Optionally, a data structure can be selected according to the optimization information or the edge information can be optimized.
[0094] In one embodiment, a more compact data structure can be adopted according to the optimization information, such as using indexes to represent repeated vertices. Suppose each vertex is repeatedly referenced 8 times on average, then the new storage space is approximately: 10000×4 / 8 = 5000 bytes = 5KB ≈ 0.005MB. The edge information can also be optimized according to the optimization information. For example, for a triangle mesh, an edge table can be used to store the connection relationships of the edges, and the storage overhead can be reduced by sharing the edges. For parts with similar structures, the instantiation method can be adopted, where only one copy of the data is stored, and then multiple instances are generated through transformation matrices. Through the above series of optimizations, the storage space is reduced from approximately 80MB to approximately 40MB, greatly improving the efficiency and performance of graphic processing.
[0095] Optionally, the memory management information includes memory block information, and the corresponding memory management method is called according to the memory management information to optimize the memory, including: obtaining adjacent and free memory blocks according to the memory block information, where the memory block information includes at least one of the starting address, size, and usage status; merging the free memory blocks and arranging the used memory blocks according to preset rules; and if a memory block allocation instruction is detected, allocating a memory block based on the memory block allocation instruction and the merging result.
[0096] Optionally, the frequency of obtaining the memory block information can be determined according to the load status of the server and the usage frequency of the memory.
[0097] In one embodiment, as Figure 5As shown, the frequency of obtaining memory block information is once an hour. The application is a server application, and the total size of its allocated memory area is 1000MB. When the set acquisition time arrives, a comprehensive and detailed scan is performed on the 1000MB memory area. Detailed information such as the starting address, size, and usage status of each memory block is recorded. The obtained memory block information includes: Used memory blocks: Memory block 1: Starting address 0, size 250MB; Memory block 2: Starting address 250MB, size 180MB; Memory block 3: Starting address 430MB, size 120MB. Free memory blocks: Memory block 4: Starting address 550MB, size 40MB; Memory block 5: Starting address 590MB, size 30MB; Memory block 6: Starting address 620MB, size 60MB; Memory block 7: Starting address 680MB, size 50MB. Memory fragmentation is performed based on this memory block information. It is determined according to the obtained memory block information that memory blocks 4, 5, and 6 are adjacent and all free. They are merged into a new free memory block with a starting address of 550MB and a size of 130MB. Subsequently, there is a sudden need to allocate a 150MB memory block to handle an urgent task. Due to the previous memory fragmentation, the required 150MB space can be quickly allocated from the merged free memory block (starting address 550MB, size 130MB) and its adjacent free area. This avoids allocation failures or the need to spend a large amount of time searching for a suitable space caused by memory fragmentation.
[0098] Optionally, the preset rules include the most recent access time of the memory block, and the used memory blocks are arranged according to this most recent access time. Among them, the arrangement can be carried out from new to old. Specifically, the physical arrangement order of the memory blocks in memory is readjusted according to the most recent access time of the memory blocks. That is, if the access time of memory block 2 is closest to the current time, its position in physical memory is moved to a position closer to the frequently accessed memory block 1, which can improve the efficiency of memory access. By merging free memory blocks and rearranging used memory blocks, the memory layout becomes more compact and orderly, reducing the generation of memory fragmentation and improving the continuity and availability of memory space.
[0099] Optionally, the memory management method further includes: if it is determined that a loading operation is to be performed, the scene data corresponding to the loading operation is obtained, and memory allocation, monitoring, and release are performed according to the scene data. The scene data includes at least one of the number of loading objects, texture information corresponding to the loading objects, number of frames, and special effect complexity. Deep integration of the application with the Avolonia framework is achieved by means of memory allocation, monitoring, and release based on scene data.
[0100] In one embodiment, as Figure 6As shown, the application is a multimedia application. Before loading a large 3D animation scene, it comprehensively collects the scene data related to the animation scene. The scene data includes information such as the number of models in the scene, the resolution of textures, the number of frames of the animation, and the complexity of special effects. According to the scene data, it is determined that the scene contains 1000 detailed models, and each model on average occupies 1MB of memory; the total area of high-resolution textures reaches 500MB; the number of animation frames is 1000 frames, and each frame on average requires 2MB of memory for temporary data; the special effects are expected to occupy 200MB of memory. It is calculated that a total of about 1000MB of memory is required. To cope with possible temporary growth and emergencies, 1200MB of memory can be planned and allocated in advance. When starting to execute graphic operations and data processing, the memory is precisely allocated according to the plan. For example, 1000MB of memory space is allocated for model data, 100MB of memory space is allocated for the temporary data of the animation, and 100MB of memory space is reserved for special effects. During the animation playback process, the memory usage is continuously monitored. For example, through the monitoring per second, it is found that at a certain moment, the actual usage of model data is 800MB, the animation temporary data is 50MB, and the special effects use 80MB. When it is determined that a certain frame is rendered, the temporary data related to this frame is no longer used. For example, the temporary data of this frame occupies 5MB of memory, and this part of the memory is released. Similarly, when a certain special effect ends, such as a flame special effect using 50MB of memory, the 50MB of memory is released in a timely manner. Through the above deep integration, the memory usage efficiency is significantly improved, which is 40% higher than before. At the same time, it successfully avoids the lags and errors caused by improper memory allocation, bringing a smooth and stable usage experience to users.
[0101] Through the coordinated operation of the above multiple technologies, this application can effectively reduce the memory occupancy of the application and significantly enhance the performance and stability of the program. Among them, the applications to which the memory management method of this application is applied include medical imaging processing systems, intelligent transportation monitoring systems, financial trading systems, games, and aerospace control systems. In the medical imaging processing system, it can be used to process a large amount of high-precision medical image data, such as X-ray, CT, MRI and other images. In the intelligent transportation monitoring system, it can be used to process and display dynamic information such as vehicles and pedestrians on the road in real time. In the financial trading system, it can be used to display complex market charts and real-time trading data. In large-scale multiplayer online games, it can be used to process complex game scenes and player interaction data. In the aerospace control system, it can be used to monitor various parameters and states of the aircraft.
[0102] The memory management method of this application will be further described below through specific embodiments.
[0103] In one embodiment, as Figure 7As shown, the application is a monitoring client for an industrial control system. This monitoring client includes a FRP graphical user interface generated by the Avolonia framework. The client needs to run stably on Windows and Linux platforms and achieve real-time data interaction with a remote server through FRP technology. The client contains many dynamically changing graphical elements, such as a fine process flow chart that is updated in real time, a monitoring chart that accurately reflects the operating status of equipment, and a high-definition video monitoring screen, etc. To achieve memory optimization, for the data point objects that are frequently created and destroyed in the monitoring chart, a memory pool technology is adopted. When the application is initialized, a memory pool with an initial size of 500 data point objects is created. When a new data point needs to be created, it is obtained from the memory pool. If the memory pool is empty, it will automatically expand by 100 data point spaces. When the data point is no longer in use, it is returned to the memory pool.
[0104] For the image data in the graphical elements, such as the icon image of the equipment, first perform a conversion from the RGB color space to the YUV color space. Reduce the color precision from 8 bits per channel to 5 bits per channel. For the complex monitoring screen texture image, adopt a lossy compression algorithm based on the discrete cosine transform, and set the compression ratio to 4:1. And at least one of image scaling (such as reducing or enlarging the image according to actual needs to reduce the data volume or adapt to a specific display size), image cropping (removing the unnecessary parts of the image and only retaining the key areas to reduce the data volume), image filtering (such as using median filtering, Gaussian filtering, etc. to remove the noise in the image and possibly reduce the data volume to a certain extent), color quantization (further reducing the number of colors, for example reducing the original 256 colors to 64 or fewer), fractal compression (for some images with self-similarity, adopting a fractal compression algorithm to achieve a higher compression ratio) can be performed on the image to reduce the data volume of the image. During the operation of the application, memory defragmentation can be started every 30 minutes. Merge the memory blocks with a size exceeding 512 bytes in adjacent free memory blocks. At the same time, rearrange the used memory blocks in descending order of access frequency to improve the memory access efficiency.
[0105] To achieve deep integration with the Avolonia framework, when loading a new monitoring screen, determine the actual requirements based on the complexity and number of elements of the screen, and pre-allocate 20% more memory than the actual requirements based on this actual requirement. After the screen display is completed, accurately release the memory that is no longer in use to avoid memory waste. Among them, the calculation of complexity and number of elements includes: 1. Perform hierarchical processing on the monitoring screen. Divide the screen into a foreground layer, a background layer, a data layer, etc., and calculate the complexity and number of elements based on the hierarchical results. For the foreground layer, identify elements such as key device icons and important data identifiers, and determine the number and complexity of the elements through image recognition algorithms; for the background layer, determine the complexity according to the complexity of its texture and repetition pattern. 2. Use image segmentation technology to divide the screen into different regions, and calculate the complexity and number of elements for each region. Analyze each region separately. For example, for a chart region, count the type of chart (bar chart, line chart, etc.), the number of data points, the number of coordinate axes, etc.; for a flowchart region, calculate the number of process nodes, the number of connections, and complex branch structures, and determine the complexity and the statistics of the number of elements according to the elements in different regions. 3. For image elements, feature vectors can be extracted, and the feature vectors include color features, shape features, texture features, etc. Using these features, through a trained machine learning model (such as support vector machine, random forest, etc.) to predict its complexity category. 4. For the statistics of the number of elements, use an object detection-based method. Pre-train a model that can identify various common elements (such as icons of specific shapes, data blocks of specific formats, etc.), and detect the number of occurrences of these elements in the screen through the model. 5. Analyze in combination with historical data. If there are past monitoring screens with similar scenarios or functions, compare the similarities in structure, element type, and distribution between the new screen and the historical screen, and refer to the evaluation results of the complexity and number of elements of the historical screen. 6. Introduce a real-time monitoring mechanism. During the screen loading and running process, continuously monitor the changes and interactions of elements, such as the real-time update frequency of data, the operation frequency of users on specific elements, etc., and dynamically adjust the evaluation of complexity and number of elements. 7. After obtaining the complexity and number of elements, professionals can also review and correct the results of the above automatic evaluation. Based on their experience and professional knowledge, they adjust the evaluation that may have deviations to ensure the accuracy of the final result. Through the comprehensive application of the above steps, the estimated complexity and number of elements of the monitoring screen can be obtained more accurately, providing a reliable basis for the pre-allocation and release of memory.
[0106] After actual testing, in the case of long-term operation (such as continuous operation for 72 hours) and processing a large amount of real-time data, compared with the traditional memory management method, the memory occupancy of the present invention is reduced by 30%, and the program response speed is increased by 40%, effectively ensuring the stable and efficient operation of the monitoring client application of the industrial control system.
[0107] The memory management method of this application has the following advantages:
[0108] 1. The innovative intelligent object reference counting technology can accurately track object references, timely release the memory of objects that are no longer in use, and effectively avoid memory leaks.
[0109] 2. The efficient memory pool technology pre-allocates memory for objects that are frequently created and destroyed, reduces overhead, and improves memory utilization efficiency.
[0110] 3. A specific memory compression algorithm for the graphical elements of the Avolonia framework is optimized according to the characteristics of the graphical element data to reduce memory occupancy.
[0111] 4. The regular memory fragmentation reorganization mechanism merges free memory blocks and optimizes the memory layout to improve the overall memory utilization rate.
[0112] 5. The deep integration with the Avolonia framework ensures seamless connection between memory management and the key processes of the framework, realizes intelligent allocation and release of memory, and avoids conflicts at the same time.
[0113] In an optional embodiment, an electronic device is provided, as Figure 8 shown. Figure 8 The electronic device 4000 shown includes: a processor 4001 and a memory 4003. Among them, the processor 4001 and the memory 4003 are connected, such as connected through a bus 4002. Optionally, the electronic device 4000 may further include a transceiver 4004, and the transceiver 4004 may be used for data interaction between this electronic device and other electronic devices, such as data sending and / or data receiving, etc. It should be noted that in practical applications, the transceiver 4004 is not limited to one, and the structure of this electronic device 4000 does not constitute a limitation on the embodiments of this application.
[0114] The processor 4001 may be a CPU (Central Processing Unit, central processor), a general-purpose processor, a DSP (Digital Signal Processor, data signal processor), an ASIC (Application Specific Integrated Circuit, application-specific integrated circuit), an FPGA (Field Programmable Gate Array, field programmable gate array), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It can implement or execute various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. The processor 4001 may also be a combination that realizes computing functions, such as a combination including one or more microprocessors, a combination of a DSP and a microprocessor, etc.
[0115] The bus 4002 may include a path for transmitting information between the above components. The bus 4002 can be a PCI (Peripheral Component Interconnect) bus, an EISA (Extended Industry Standard Architecture) bus, or the like. The bus 4002 can be divided into an address bus, a data bus, a control bus, etc. For the sake of convenience in representation, only a thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0116] The memory 4003 can be a ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or it can also be an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory), or other optical disc storage, optical disc storage (including compact discs, laser discs, optical discs, digital versatile discs, Blu-ray discs, etc.), magnetic disk storage media, other magnetic storage devices, or any other medium that can be used to carry or store computer programs and can be read by a computer, which is not limited here.
[0117] The memory 4003 is used to store the computer program for implementing the embodiments of the present application and is controlled by the processor 4001 to execute. The processor 4001 is used to execute the computer program stored in the memory 4003 to implement the steps shown in the foregoing method embodiments.
[0118] Among them, the electronic device can be any electronic product that can perform human-computer interaction with an object. For example, a personal computer, a tablet computer, a smart phone, a personal digital assistant (PDA), a game console, an Internet Protocol Television (IPTV), a smart wearable device, etc.
[0119] The electronic device may further include a network device and / or an object device. Among them, the network device includes, but is not limited to, a single network server, a server group composed of multiple network servers, or a cloud composed of a large number of hosts or network servers for cloud computing.
[0120] The network where the electronic device is located includes, but is not limited to, the Internet, wide area network, metropolitan area network, local area network, virtual private network (VPN), etc.
[0121] An embodiment of the present application provides a computer-readable storage medium, which includes a computer program. When the computer program is executed by a processor, the steps and corresponding contents of the foregoing method embodiment can be implemented.
[0122] An embodiment of the present application provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps and corresponding contents of the foregoing method embodiment can be implemented.
[0123] The terms "first", "second", "third", "fourth", "1", "2", etc. (if any) in the specification, claims and above-mentioned drawings of the present application are used to distinguish similar objects, and do not necessarily describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances, so that the embodiments of the present application described here can be implemented in an order other than the illustrated or textually described order.
[0124] It should be understood that although the flowchart of the embodiment of the present application indicates each operation step by an arrow, the execution order of these steps is not limited to the order indicated by the arrow. Unless there is a clear description in this article, in some implementation scenarios of the embodiment of the present application, the implementation steps in each flowchart can be executed in other orders according to requirements. In addition, some or all of the steps in each flowchart may include multiple sub-steps or multiple stages based on the actual implementation scenario. Some or all of these sub-steps or stages can be executed at the same time, and each sub-step or stage of these sub-steps or stages can also be executed at different times respectively. In the scenario where the execution times are different, the execution order of these sub-steps or stages can be flexibly configured according to requirements, and the embodiment of the present application does not limit this.
[0125] The above are only optional implementation manners of some implementation scenarios of the present application. It should be noted that for those of ordinary skill in the art, without departing from the technical concept of the solution of the present application, adopting other similar implementation means based on the technical idea of the present application also belongs to the protection scope of the embodiments of the present application.
Claims
1. A memory management method, characterized in that, For an application generated based on the Avolonia framework, the method includes: Obtain the memory management information corresponding to the application, where the memory management information at least includes graphic element feature information; Call the corresponding memory management method according to the memory management information to optimize the memory, and the memory management method includes at least one of reference counting method, memory pool management, image compression, and memory fragmentation reorganization; The step of calling the corresponding memory management method according to the memory management information to optimize the memory includes: Obtain the image to be processed, and convert the color space of the image to a preset space; Quantize the image after converting the color space according to the graphic element feature information to obtain image data; Compress the image data according to the probability distribution of the image data.
2. The memory management method according to claim 1, wherein The memory management information includes reference quantity information, and the step of calling the corresponding memory management method according to the memory management information to optimize the memory includes: Determine the counting object corresponding to the reference counting method, and record the reference quantity of the counting object according to the reference quantity information; If it is determined that the reference quantity is zero, then clean up the references and resources associated with the counting object, and release the memory space occupied by the counting object.
3. The memory management method according to claim 1, wherein The memory management information includes object creation and destruction information, and the step of calling the corresponding memory management method according to the memory management information to optimize the memory includes: Determine the memory management object corresponding to the memory pool management according to the creation and destruction information; Create a memory pool to accommodate the memory management object; Determine the use and return of memory blocks in the memory pool according to the creation and destruction of the memory management object.
4. The memory management method according to claim 3, wherein, The step of calling the corresponding memory management method according to the memory management information to optimize the memory includes: Obtain the optimization information corresponding to the image according to the graphic element feature information, and the optimization information includes at least one of vertex repetition information, edge information, and structure information; Reduce the data volume of the image data according to the optimization information.
5. The memory management method according to claim 1, characterized in that, The memory management information includes memory block information, and the step of calling the corresponding memory management method according to the memory management information to optimize the memory includes: Obtain adjacent and free memory blocks according to the memory block information, and the memory block information includes at least one of starting address, size, and usage status; Merge the free memory blocks, and arrange the used memory blocks according to preset rules; If a memory block allocation instruction is detected, then allocate a memory block based on the memory block allocation instruction and the merge result.
6. The memory management method according to claim 1, wherein The method includes: If it is determined that a loading operation is to be performed, then obtain the scene data corresponding to the loading operation, and perform memory allocation, monitoring, and release according to the scene data, where the scene data includes at least one of the number of loading objects, texture information corresponding to the loading objects, number of frames, and special effect complexity.
7. An electronic device, comprising a memory, a processor, and a computer program stored on the memory, characterized in that, The processor executes the computer program to implement the steps of the method according to any one of claims 1-6.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1-6.
9. A computer program product comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1-6.
Citation Information
Patent Citations
Method and system for managing memory occupied by reference counting
CN113778670A