Memory management method and device, medium and product
By obtaining and analyzing memory management information of Avalonia applications, combining reference counting, memory pool management, image compression and memory defragmentation and other technologies, memory usage is optimized, and the memory usage problem of Avalonia framework when processing large amounts of data is solved, and the application performance is improved and user experience.
Patent Information
- Application Number
- CN202411250595.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-06
- Publication Date
- 2024-12-10
- 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 operation.
By obtaining the application's memory management information, including reference quantity information, object creation and destruction information, graphic element feature information, memory block information, call reference counting methods, memory pool management, image compression and memory defragmentation and other technologies to optimize memory, select Suitable memory management methods to reduce memory usage.
It effectively reduces the memory usage of data, reduces the possibility of memory resource waste and the slow and stuttering of applications, improves the user experience, and significantly improves the system's memory utilization efficiency and performance.
Smart Images

Figure CN119105872A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of memory management technology, and more specifically, 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 a variety of 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] Because of the above characteristics, Avalonia is widely used in the development of graphical user interfaces (GUIs) for various applications. However, as application functions become more complex, the amount of data that needs to be processed is increasing day by day. However, as the amount of data increases, Avalonia is difficult to effectively reduce the memory usage of a large amount of data, which is prone to waste of memory resources and slow and stuck applications due to low memory, reducing application performance. Summary of the invention
[0004] The embodiments of the present application provide a memory management method, device, medium and product, which can solve the problem that the existing Avalonia is difficult to effectively reduce the memory usage of a large amount of data, and is prone to waste of memory resources and slow running and freezing of applications due to insufficient memory. To achieve this purpose, the embodiments of the present application provide the following solutions.
[0005] According to one aspect of an embodiment of the present application, a memory management method is provided for an application generated based on an Avolonia framework, the method comprising:
[0006] Acquire memory management information corresponding to the application, the memory management information including at least one of reference quantity information, object creation and destruction information, graphic element feature information, and memory block information;
[0007] The corresponding memory management method is called according to the memory management information to optimize the memory, and the memory management method includes at least one of a reference counting method, a memory pool management, an image compression, and a memory defragmentation.
[0008] In a possible implementation, the memory management information includes reference quantity information, and the invoking a corresponding memory management method to optimize memory according to the memory management information includes:
[0009] Determine a counting object corresponding to the reference counting method, and record the number of references of the counting object according to the reference number information;
[0010] If it is determined that the number of references is zero, the references and resources associated with the counting object are cleared, and the memory space occupied by the counting object is released.
[0011] In a possible implementation, the memory management information includes creation and destruction information of the object, and the invoking a corresponding memory management method to optimize the 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] Creating a memory pool to hold the memory management object;
[0014] The use and return of memory blocks in the memory pool are determined 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, and the invoking a corresponding memory management method to optimize memory according to the memory management information includes:
[0016] Acquire an image to be processed, and convert the color space of the image into a preset space;
[0017] Quantizing the image after color space conversion according to the graphic element feature information to obtain image data;
[0018] The image data is compression processed according to the probability distribution of the image data.
[0019] In a possible implementation, the invoking a corresponding memory management method according to the memory management information to optimize the memory includes:
[0020] Acquire optimization information corresponding to the image according to the graphic element feature information, wherein the optimization information is at least one of vertex duplication information, edge information, and structure information;
[0021] The data amount of the image data is reduced according to the optimization information.
[0022] In a possible implementation, the memory management information includes memory block information, and the invoking a corresponding memory management method to optimize memory according to the memory management information includes:
[0023] Acquire an adjacent and free free memory block according to the memory block information, wherein the memory block information includes at least one of a starting address, a size, and a usage status;
[0024] Merging the free memory blocks and arranging the used memory blocks according to a preset rule;
[0025] If a memory block allocation instruction is detected, a memory block is allocated 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, the scene data corresponding to the loading operation is obtained, and memory is allocated, monitored and released according to the scene data. The scene data includes at least one of the number of loaded objects, texture information corresponding to the loaded objects, the number of frames, and the complexity of special effects.
[0028] According to one aspect of an embodiment of the present application, an electronic device is provided, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the method described above.
[0029] According to one aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method described above are implemented.
[0030] According to one aspect of an embodiment of the present application, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the steps of the method described above are implemented.
[0031] The beneficial effects of the technical solution provided by the embodiment of the present application are:
[0032] The memory management method provided in the present application obtains memory management information corresponding to the application, and the memory management information includes at least one of reference quantity information, object creation and destruction information, graphic element feature information, and memory block information; the corresponding memory management method is called according to the memory management information to optimize the memory, and the memory management method includes at least one of a reference counting method, memory pool management, image compression, and memory defragmentation. The embodiment of the present application adds a new memory management method in addition to Avalonia's own memory management method, and can select the corresponding memory management method for memory optimization according to the acquired memory management information, thereby effectively reducing the memory usage of data, reducing the waste of memory resources and the possibility of slow application operation and jamming, and improving the user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following is a brief introduction to the drawings required for use in describing the embodiments of the present application.
[0034] Figure 1A flowchart of a memory management method provided in an embodiment of the present application;
[0035] Figure 2 A schematic diagram of the execution process of the reference counting method in the memory management method provided in the embodiment of the present application;
[0036] Figure 3 A schematic diagram of the execution process of the memory pool technology in the memory management method provided in an embodiment of the present application;
[0037] Figure 4 A schematic diagram of the execution process of image compression in the memory management method provided in an embodiment of the present application;
[0038] Figure 5 A schematic diagram of the execution process of memory defragmentation in the memory management method provided in an embodiment of the present application;
[0039] Figure 6 A schematic diagram of the implementation process of integrating the application with the Avolonia framework in the memory management method provided in the embodiment of the present application;
[0040] Figure 7 A flowchart of an embodiment of a memory management method provided in an embodiment of the present application;
[0041] Figure 8 This is a structural diagram of the electronic device of this application. DETAILED DESCRIPTION
[0042] The embodiments of the present application are described below in conjunction with the drawings in the present application. It should be understood that the implementation methods described below in conjunction with the drawings are exemplary descriptions for explaining the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions of the embodiments of the present application.
[0043] It will be understood by those skilled in the art that, unless specifically stated, the singular forms "one", "said", and "the" used herein may also include plural forms. It should be further understood that the terms "including" and "comprising" used in the embodiments of the present application refer to that the corresponding features can be implemented as the presented features, information, data, steps, operations, elements and / or components, but do not exclude the implementation of other features, information, data, steps, operations, elements, components and / or combinations thereof supported by the present technical field. It should be understood that when we say that an element is "connected" or "coupled" to another element, the one element may be directly connected or coupled to the other element, or it may refer to 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 that it is implemented as "A", or is implemented as "A", or is implemented as "A and B".
[0044] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below in conjunction with the accompanying drawings.
[0045] The following describes several exemplary embodiments to illustrate the technical solutions of the embodiments of the present application and the technical effects produced by the technical solutions of the present application. It should be noted that the following embodiments can refer to, draw on or combine with each other, and the same terms, similar features and similar implementation steps in different embodiments will not be described repeatedly.
[0046] The memory management method, device, medium and product provided in this application are intended to solve at least one technical problem existing in the prior art.
[0047] A memory management method is provided in an embodiment of the present application, and the memory management method can be executed by a mobile phone, a computer, a cloud, or other terminals that can load applications generated based on the Avolonia framework.
[0048] Optionally, the memory management method of the present application is used for an application generated based on the Avolonia framework, which can interact with a remote server through FRP (front-end reverse proxy) technology to ensure the real-time, stability and security of the data.
[0049] Alternatively, if Figure 1-Figure 7 As shown, the memory management method includes:
[0050] S101: Obtain memory management information corresponding to the application.
[0051] Optionally, the memory management information includes at least one of reference quantity information, object creation and destruction information, graphic element feature information, and memory block information. The memory management information may be acquired according to a received instruction, or may be acquired based on a trigger of a currently executed operation, or may be acquired according to a set frequency. The memory management information acquisition operation may also be automatically executed after the application is started.
[0052] Optionally, when acquiring memory management information, the acquisition method, acquisition conditions and acquisition scenario of the memory management information may be determined according to the type of memory management information. If it is determined that the acquisition condition is currently met and the acquisition scenario is in place, the memory management information is acquired according to the acquisition method.
[0053] In one embodiment, after the application is started, the reference quantity information, object creation and destruction information, graphic element feature information and memory block information are automatically obtained so as to perform memory optimization using the obtained information.
[0054] S102: Invoke a corresponding memory management method according to the memory management information to optimize the memory.
[0055] Optionally, the memory management method includes at least one of a reference counting method, a memory pool management, image compression, and memory defragmentation. Different memory management methods correspond to different memory management information.
[0056] Optionally, the memory management information includes reference count information, and the corresponding memory management method is called according to the memory management information to optimize the memory, including: determining the counting object corresponding to the reference counting method, and recording the number of references of the counting object according to the reference count information; if the reference count is determined to be zero, clearing the references and resources associated with the counting object and releasing the memory space occupied by the counting object.
[0057] Optionally, an object related to the application that needs to be referenced may be obtained and the object may be determined as a counted object. The reference quantity information may include information about newly added references or reduced references to the counted object, and the reference quantity of the counted object may be modified based on the information. The time to release the memory space is determined based on the reference quantity.
[0058] Optionally, to record the number of references to the counted object, a data structure for counting can be created for each counted object. The data structure can be a private integer variable referenceCount. When a new reference points to the counted object, the reference increase operation corresponding to the counted object is executed, and the number of references to the counted object increases, that is, referenceCount increases by 1. When a reference no longer points to the counted object, the reference decrease operation is triggered, the number of references to the counted object decreases, and referenceCount decreases by 1.
[0059] Optionally, the number of references may be recorded via a doubly linked list, a hash table, a tree structure, or other data structures capable of storing data.
[0060] Specifically, the doubly linked list can store all pointers that reference the count object in a doubly linked list. Each time a new reference is added, a node is added to the linked list; when a reference is reduced, the corresponding node is deleted from the linked list. The number of references is reflected by the length of the linked list.
[0061] For example, in a graphics processing program, the counting object is the image object, and for each image object, its reference count is stored in a doubly linked list. When multiple modules need to reference and operate the same image object at the same time, the reference relationship can be clearly managed through the linked list.
[0062] The hash table uses the identifier of the referenced counting object as the key and the corresponding reference count as the value in the hash table. For example, in a network communication program, the counting object is a data packet object. For different types of data packet objects, a hash table is used to record their reference counts. This allows for quick search and update of reference counts.
[0063] The tree structure (such as binary search tree) uses the identifier of the counting object as the node value and the number of references as the additional attribute of the node. For example, in a file system management program, the counting object is the file object. For different file objects, their reference information is organized through a binary search tree to facilitate fast search and maintenance.
[0064] In one embodiment, Figure 2 As shown in the figure, to improve the accuracy of the number of references, you can use mutex locks or atomic operations to ensure the accuracy and consistency of the number of references in a multi-threaded environment. Specifically, if you use a mutex lock, you can first use the System.Threading namespace. Then create an object of the Mutex class, such as Mutexmutex = newMutex();. When you want to perform an operation that requires mutex protection, call the mutex.WaitOne(); method to try to acquire the mutex lock. If the mutex lock is occupied by other threads at this time, the current thread will be blocked and wait until the mutex lock is released. After successfully acquiring the mutex lock, you can perform operations such as reading the current referenceCount value and increasing it by 1. After the operation is completed, call the mutex.ReleaseMutex(); method to release the mutex lock so that other waiting threads can acquire the mutex lock and perform corresponding operations. In this way, the thread safety of operations related to the number of references 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 thread-safe increase operations. This method atomically increases the specified integer variable used to record the number of references by 1 and returns the new value after the increase.
[0065] When a reference no longer points to the counted object, a reference reduction operation is triggered. The current referenceCount value can also be obtained in a thread-safe manner, such as using the same mutex or atomic operation mechanism as the increase operation. After obtaining the value of the reference count, its value is reduced by 1, and then immediately checked whether the reduced reference count value is 0.
[0066] If the number of references is determined to be 0, it is determined that the count object is no longer referenced by any object. At this point, the memory release process will be initiated. First, all references and resources related to the object will be fully cleaned up to ensure that there are no residual associations. Then, according to the predetermined memory management rules and the standard interface of the operating system, the memory space occupied by the count object is safely and effectively released, and these memory resources are returned to the available memory pool for subsequent use.
[0067] Optionally, counting references and resources associated with an object may include:
[0068] 1. During the execution of the application, some references are not executed correctly or are delayed. For example, in complex code logic, there may be some abnormal situations that cause the cleanup 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 if the external references have been released.
[0070] 3. The release operation of some resources contained in the counting object, such as open file handles, network connections, etc., may not be completely synchronized with the reduction operation of the number of references, resulting in these resources not being released when the number of references is 0.
[0071] 4. In a multi-threaded file processing program, if an exception occurs in a thread while processing a file, the reference to the file object may not be released correctly. Or in a graphics processing program, two graphics objects reference each other. When the external references to them are cancelled, they still occupy the relevant memory and resources due to the internal circular reference.
[0072] In one embodiment, there is a class called "DataObject" in the application. 500 "DataObject" objects are initially created. As the system runs, different modules perform reference operations on these objects. The reference changes of each "DataObject" object are accurately tracked by reference counting. When the number of references to some objects drops to zero, the approximately 80MB of memory occupied by approximately 200 objects that are no longer used are identified and released. This process makes the use of memory more efficient and reasonable, greatly optimizes the memory utilization efficiency of the system, effectively avoids the occurrence of memory leaks, and ensures the stability and performance of the system. The reference counting method of the present application has stronger adaptability and flexibility for the management of the number of references. By accurately tracking the changes in references, it is possible to better cope with the dynamic changes in the reference relationship of objects in complex systems, especially in large-scale, high-concurrency application scenarios, it is possible to more accurately control the allocation and release of memory and optimize memory usage efficiency.
[0073] Optionally, when the memory management information includes object creation and destruction information, the memory is optimized by calling a corresponding memory management method according to the memory management information, including: determining a memory management object corresponding to the memory pool management according to the creation and destruction information; creating a memory pool to accommodate the memory management object; and 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 frequency of creation and destruction of each object and a business requirement. The business requirement may include a memory pool allocation requirement of each object, and the memory management object is determined based on the frequency and the business requirement.
[0075] In one embodiment, the memory management object may be an object whose creation and destruction frequency is greater than a preset frequency. Specifically, in an online game, the room objects are frequently created and destroyed because players frequently enter and exit the game room. The server determines the room object as a memory management object according to the preset frequency, and can accurately pre-allocate the memory pool according to the player activity and historical peak data, so that the reuse and allocation of room objects are more efficient, greatly improving the server response speed and stability.
[0076] Optionally, the size of the memory pool can be determined by the peak number of memory management objects that need to be created. After the memory pool is created, if a new memory management object needs to be created, the available memory block corresponding to the size of the memory management object is directly obtained from the free part of the memory pool; when the object is no longer in use, it is marked as reusable and returned 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 process of memory allocation and release, and significantly improves the running efficiency of the program.
[0077] In one embodiment, Figure 3 As shown in the figure, in a real-time data processing application, it is often necessary to create and destroy "DataPacket" objects (memory management objects) to transmit data. A memory pool that can accommodate 1,000 "DataPacket" objects is created in advance. During the peak processing period, 800 "DataPacket" objects are created in a short period of time ("DataPacket" objects are entities with specific functions and structures used to transmit data in real-time data processing applications. When a "DataPacket" object is created, the corresponding memory block is obtained from the memory pool to store the data and related information of the "DataPacket" object). Since the memory blocks are obtained from the memory pool, frequent system memory allocation operations are avoided, and the processing speed is increased by 30%. When the 500 objects are no longer used, they are returned to the memory pool in time to prepare for subsequent use, effectively saving system resources.
[0078] Optionally, the memory management information includes graphic element feature information, and the corresponding memory management method is called according to the memory management information to optimize the memory, including: obtaining an image to be processed, and converting the color space of the image to a preset space; quantizing the image after the color space conversion according to the graphic element feature information to obtain image data; and 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 pattern of the image, the complexity of the texture, and the geometric shape features of the graphics. Based on the features, 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 a YUV space, and the downsampling operation is performed based on the preset space.
[0081] In one embodiment, Figure 4 As shown, the image to be processed is a 4K resolution (3840×2160 pixels) RGB image, each pixel consists of three 8-bit color channels (R, G, B), and 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 YUV space by 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, the U and V components of the image are downsampled, and a 4:2:0 sampling method may be used, that is, the resolution of the U and V components in the horizontal and vertical directions is 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, the Y, U, and V components are quantized according to the quantization step size. The quantization formula may 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 richness of details, and the visual requirements can include the accuracy requirements. The richness of details can be determined by calculating the gradient or edge strength of the image area. If the gradient is greater than a preset gradient or the edge strength is greater than a preset strength, the area is determined to be rich in details. The grayscale value change of the pixel point in the horizontal and vertical directions can also be calculated. When the change value is greater than a preset value, it is identified as a detail-rich area. The accuracy requirement can be determined according to the specific application scenario and image content. For example, in a medical image, if the area is determined to be a key lesion area, the accuracy requirement corresponding to the area is determined to be greater than a first preset accuracy; in a satellite image, if the area is a specific target recognition area, the accuracy corresponding to the area is determined to be greater than the first preset accuracy. When the following conditions are met, the Q value used can be considered to be less than a predetermined value (i.e., a smaller Q value): if the gradient or edge strength of the image area exceeds a certain threshold, such as a gradient value greater than 50. Or for specific key targets or areas that need to be finely distinguished (i.e., the corresponding accuracy is greater than the first preset accuracy), such as key parts such as eyes and noses in face recognition. A smaller Q value can be determined based on specific image quality requirements and data compression ratios. The Q value can be selected between 2 and 10. The specific size of the Q value depends on the type of image and specific application requirements (such as accuracy requirements). For example, for images that require extremely high accuracy (accuracy greater than the first preset accuracy), the Q value can be selected as 2 or 3; for images that require relatively high accuracy (accuracy less than the first preset accuracy, but greater than the second preset accuracy) but still require a certain amount of compression (such as the data compression ratio is within a preset range), the Q value can be selected from 5 to 8.
[0090] Optionally, for smooth, low-importance areas in the image, a larger Q value (greater than or equal to a predetermined value) can be sampled for quantization. The Q value corresponding to the area can be determined by information such as the image type, resolution, content characteristics, required compression ratio, and image quality loss degree requirements. Specifically, the larger Q value can be greater than or equal to 10. For obtaining the Q value, a series of experiments and tests can be conducted to find the Q value that best suits a specific image and application scenario. For example, the Q value can be gradually increased from 10, while observing the quality of the compressed image and the data compression effect, until a maximum Q value is reached within an acceptable range of image quality (satisfying the image quality loss degree requirements) to achieve the optimal compression balance. Different images and application scenarios have different corresponding larger Q values.
[0091] Optionally, the quantized image is subjected to encoding compression processing to further reduce the data volume of the image.
[0092] Optionally, optimization information corresponding to the image may be obtained based on the graphic element feature information, and at least one of the optimization information vertex duplication information, edge information, and structural information may be optimized; and the amount of image data may be reduced based on the optimization information.
[0093] Optionally, a data structure may be selected or edge information may be optimized according to the optimization information.
[0094] In one embodiment, a more compact data structure can be used according to the optimization information, such as using an index to represent repeated vertices. Assuming that each vertex is repeatedly referenced 8 times on average, 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 triangular mesh, an edge table can be used to store the connection relationship of the edges, and the storage overhead can be reduced by sharing the edges. For parts with similar structures, an instantiation method can be used to store only one copy of the data, and then multiple instances can be generated through a transformation matrix. Through the above series of optimizations, the storage space is reduced from about 80MB to about 40MB, greatly improving the efficiency and performance of graphics 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 free memory blocks according to the memory block information, the memory block information including at least one of a starting address, a size, and a usage status; merging free memory blocks, and arranging used memory blocks according to preset rules; if a memory block allocation instruction is detected, allocating memory blocks based on the memory block allocation instruction and the merging result.
[0096] Optionally, the frequency of obtaining the memory block information may be determined according to the load status of the server and the usage frequency of the memory.
[0097] In one embodiment, 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 is reached, the 1000MB memory area is scanned comprehensively and carefully. The starting address, size, usage status and other detailed information of each memory block are recorded. The acquired 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. Defragment the memory according to the memory block information. According to the acquired memory block information, it is determined that memory blocks 4, 5, and 6 are adjacent and all free. Merge them into a new free memory block with a starting address of 550MB and a size of 130MB. Later, a 150MB memory block suddenly needs to be allocated to handle an urgent task. Due to the previous memory defragmentation, 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 due to memory fragmentation or the need to spend a lot of time looking for suitable space.
[0098] Optionally, the preset rules include the most recent access time of the memory blocks, and the used memory blocks are arranged according to the most recent access time. Among them, the arrangement can be carried out from the newest to the oldest. Specifically, the physical arrangement order of the memory blocks in the 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 the 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 is made more compact and orderly, the generation of memory fragmentation is reduced, and the continuity and availability of memory space are improved.
[0099] Optionally, the memory management method further includes: if it is determined that a loading operation is to be performed, obtaining scene data corresponding to the loading operation, and performing memory allocation, monitoring, and release according to the scene data, wherein the scene data includes at least one of the number of loaded objects, texture information corresponding to the loaded objects, the number of frames, and the complexity of special effects. The deep integration of the application and the Avolonia framework is achieved by performing memory allocation, monitoring, and release based on scene data.
[0100] In one embodiment, Figure 6As shown in the figure, the application is a multimedia application. Before loading a large 3D animation scene, the scene data related to the animation scene is fully collected. The scene data includes information such as the number of models in the scene, the resolution of the texture, the number of animation frames, and the complexity of special effects. According to the scene data, it is determined that the scene contains 1,000 fine models, each of which occupies an average of 1MB of memory; the total area of high-resolution textures is 500MB; the number of animation frames is 1,000, and each frame requires an average of 2MB of memory for temporary data; and the special effects are expected to occupy 200MB of memory. It is calculated that a total of about 1,000MB of memory is required. In order to cope with possible temporary growth and emergencies, 1,200MB of memory can be planned and allocated in advance. When starting to perform graphics operations and data processing, the memory is accurately allocated according to the plan. For example, 1,000MB of memory space is allocated for model data, 100MB of memory space is allocated for temporary data of animation, and 100MB of memory space is reserved for special effects. During the animation playback, the memory usage is continuously monitored. For example, through monitoring every second, it is found that the actual usage of model data at a certain moment is 800MB, animation temporary data is 50MB, and special effects use 80MB. When it is determined that a certain frame is rendered, the temporary data related to the 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 special effect ends, such as a flame special effect that uses 50MB of memory, this 50MB of memory is released in time. Through the above deep integration, the efficiency of memory usage has been significantly improved, an increase of 40% compared to before. At the same time, it successfully avoids jams and errors caused by improper memory allocation, bringing users a smooth and stable user experience.
[0101] Through the coordinated operation of the above multiple technologies, the present application can effectively reduce the memory usage of the application and significantly enhance the performance and stability of the program. Among them, the applications of the memory management method of the present application include medical image processing systems, intelligent traffic monitoring systems, financial transaction systems, games, and aerospace control systems. In medical image processing systems, 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 intelligent traffic monitoring systems, it can be used to process and display dynamic information such as vehicles and pedestrians on the road in real time. In financial transaction systems, it can be used to display complex market charts and real-time transaction data. In massively multiplayer online games, it can be used to process complex game scenes and player interaction data. In aerospace control systems, it can be used to monitor various parameters and states of aircraft.
[0102] The memory management method of the present application is further described below through specific embodiments.
[0103] In one embodiment, Figure 7As shown in the figure, the application is a monitoring client for an industrial control system. The monitoring client includes an FRP graphical user interface generated by the Avolonia framework. The client needs to run stably on Windows and Linux platforms and use FRP technology to interact with remote servers in real time. The client contains many dynamically changing graphic elements, such as a detailed process flow chart that is updated in real time, a monitoring chart that accurately reflects the operating status of the equipment, and a high-quality video monitoring screen. To achieve memory optimization, a memory pool technology is used for data point objects that are frequently created and destroyed in monitoring charts. 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, the space for 100 data points is automatically expanded. When a data point is no longer used, it is returned to the memory pool.
[0104] For the image data in the graphic elements, such as the icon image of the device, the color space is first converted from RGB to YUV. The color accuracy is reduced from 8 bits per channel to 5 bits per channel. For complex monitoring screen texture images, a lossy compression algorithm based on discrete cosine transform is used, and the compression ratio is set to 4:1. In addition, the image can also be processed by at least one of image scaling (such as reducing or enlarging the image according to actual needs to reduce the amount of data or adapt to a specific display size), image cropping (removing unnecessary parts of the image and retaining only key areas to reduce the amount of data), image filtering (such as using median filtering, Gaussian filtering, etc. to remove noise in the image, and may reduce the amount of data to a certain extent), color quantization (further reducing the number of colors, such as reducing the original 256 colors to 64 or less), and fractal compression (for some self-similar images, a fractal compression algorithm is used to achieve a higher compression ratio) to reduce the amount of image data. During the operation of the application, memory defragmentation can be started every 30 minutes. Merge the adjacent free memory blocks with a size of more than 512 bytes. At the same time, the used memory blocks are rearranged from high to low according to the access frequency to improve the memory access efficiency.
[0105] To achieve deep integration with the Avolonia framework, when loading a new monitoring screen, the actual demand is determined based on the complexity and number of elements of the screen, and 20% more memory is pre-allocated based on the actual demand. After the screen is displayed, the memory that is no longer used is accurately released to avoid memory waste. Among them, the calculation of complexity and number of elements includes: 1. Layering the monitoring screen. The screen is divided into foreground layer, background layer and data layer, etc., and the complexity and number of elements are calculated based on the layering results. For the foreground layer, elements such as key equipment icons and important data logos are identified, and the number and complexity of elements are determined by image recognition algorithms; for the background layer, the complexity is determined based on the complexity and repetitive pattern of its texture. 2. Use image segmentation technology to divide the screen into different areas, and calculate the complexity and number of elements for each area. Each area is analyzed separately. For example, for the chart area, the type of chart (bar chart, line chart, etc.), the number of data points, the number of coordinate axes, etc. are counted; for the flowchart area, the number of process nodes, the number of connections and complex branch structures are calculated, and the statistics of complexity and number of elements are determined based on the elements in different areas. 3. For image elements, feature vectors can be extracted, which include color features, shape features, texture features, etc. Using these features, the complexity category is predicted through trained machine learning models (such as support vector machines, random forests, etc.). 4. For the statistics of the number of elements, an object detection-based method is adopted. Pre-train a model that can recognize various common elements (such as icons of specific shapes, data blocks of specific formats, etc.), and use the model to detect the number of occurrences of these elements in the picture. 5. Combine historical data for analysis. If there are past monitoring pictures with similar scenes or functions, compare the new pictures with the historical pictures in terms of structure, element type and distribution, and refer to the complexity and element number evaluation results of the historical pictures. 6. Introduce a real-time monitoring mechanism. During the loading and running of the picture, continuously monitor the changes and interactions of the elements, such as the real-time update frequency of the data, the frequency of user operations on specific elements, etc., and dynamically adjust the complexity and element number evaluation. 7. After obtaining the complexity and element number, the results of the above automatic evaluation can also be reviewed and corrected by professionals. Based on their experience and expertise, they adjust the evaluation that may be biased 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, when running for a long time (for example, running continuously for 72 hours) and processing a large amount of real-time data, compared with the traditional memory management method, the memory usage of the present invention is reduced by 30%, and the program response speed is increased by 40%, which effectively ensures the stable and efficient operation of the industrial control system monitoring client application.
[0107] The memory management method of this application has the following advantages:
[0108] 1. Innovative intelligent object reference counting technology can accurately track object references, promptly release the memory of unused objects, and effectively avoid memory leaks.
[0109] 2. Efficient memory pool technology pre-allocates memory for frequently created and destroyed objects, reducing overhead and improving memory usage efficiency.
[0110] 3. A specific memory compression algorithm for Avolonia framework graphic elements is optimized according to the characteristics of graphic element data to reduce memory usage.
[0111] 4. Regular memory defragmentation mechanism merges free memory blocks and optimizes memory layout to improve overall memory utilization.
[0112] 5. Deep integration with the Avolonia framework ensures that memory management is seamlessly connected to the framework's key processes, enabling intelligent allocation and release of memory while avoiding conflicts.
[0113] In an optional embodiment, an electronic device is provided, such as Figure 8 As shown, Figure 8 The electronic device 4000 shown includes: a processor 4001 and a memory 4003. The processor 4001 and the memory 4003 are connected, such as through a bus 4002. Optionally, the electronic device 4000 may also include a transceiver 4004, which may be used for data interaction between the electronic device and other electronic devices, such as data transmission and / or data reception. It should be noted that in actual applications, the transceiver 4004 is not limited to one, and the structure of the electronic device 4000 does not constitute a limitation on the embodiments of the present application.
[0114] Processor 4001 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It may implement or execute various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. Processor 4001 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, and the like.
[0115] The bus 4002 may include a path to transmit information between the above components. The bus 4002 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus 4002 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0116] Memory 4003 can be ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or it can be EEPROM (Electrically Erasable Programmable Read Only Memory), CD-ROM (Compact Disc Read Only Memory) or other optical disk storage, optical disk storage (including compressed optical disk, laser disc, optical disk, digital versatile disc, Blu-ray disc, etc.), magnetic disk storage medium, 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, without limitation here.
[0117] The memory 4003 is used to store the computer program for executing the embodiment of the present application, and the execution is controlled by the processor 4001. The processor 4001 is used to execute the computer program stored in the memory 4003 to implement the steps shown in the above method embodiment.
[0118] Among them, the electronic device can be any electronic product that can interact with an object, such as a personal computer, a tablet computer, a smart phone, a personal digital assistant (PDA), a game console, an interactive network television (IPTV), a smart wearable device, etc.
[0119] The electronic device may also include a network device and / or an object device, wherein the network device includes, but is not limited to, a single network server, a server group consisting of multiple network servers, or a cloud consisting 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, a wide area network, a metropolitan area network, a local area network, a virtual private 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 aforementioned 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 aforementioned method embodiment can be implemented.
[0123] The terms "first", "second", "third", "fourth", "1", "2", etc. (if any) in the specification and claims of this application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than that shown or described in the drawings.
[0124] It should be understood that, although each operation step is indicated by arrows in the flowchart of the embodiment of the present application, the implementation order of these steps is not limited to the order indicated by the arrows. Unless clearly stated herein, in some implementation scenarios of the embodiment of the present application, the implementation steps in each flowchart can be performed in other orders according to demand. In addition, some or all of the steps in each flowchart may include multiple sub-steps or multiple stages based on actual implementation scenarios. Some or all of these sub-steps or stages may be executed at the same time, and each sub-step or stage in these sub-steps or stages may also be executed at different times respectively. In different scenarios of execution time, the execution order of these sub-steps or stages may be flexibly configured according to demand, and the embodiment of the present application does not limit this.
[0125] The above is only an optional implementation method for some implementation scenarios of the present application. It should be pointed out that for ordinary technicians in this technical field, without departing from the technical concept of the solution of the present application, other similar implementation methods based on the technical ideas of the present application are also within 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 comprises: Acquire memory management information corresponding to the application, the memory management information including at least one of reference quantity information, object creation and destruction information, graphic element feature information, and memory block information; The corresponding memory management method is called according to the memory management information to optimize the memory, and the memory management method includes at least one of a reference counting method, a memory pool management, an image compression, and a memory defragmentation.
2. The memory management method according to claim 1, characterized in that: The memory management information includes reference quantity information, and the invoking a corresponding memory management method to optimize memory according to the memory management information includes: Determine a counting object corresponding to the reference counting method, and record the number of references of the counting object according to the reference number information; If it is determined that the number of references is zero, the references and resources associated with the counting object are cleared, and the memory space occupied by the counting object is released.
3. The memory management method according to claim 1, characterized in that: The memory management information includes creation and destruction information of the object, and the optimizing memory by calling a corresponding memory management method according to the memory management information includes: Determine the memory management object corresponding to the memory pool management according to the creation and destruction information; Creating a memory pool to hold the memory management object; The use and return of memory blocks in the memory pool are determined according to the creation and destruction of the memory management object.
4. The memory management method according to claim 1, characterized in that: The memory management information includes graphic element feature information, and the optimizing memory by calling a corresponding memory management method according to the memory management information includes: Acquire an image to be processed, and convert the color space of the image into a preset space; Quantizing the image after color space conversion according to the graphic element feature information to obtain image data; The image data is compression-processed according to the probability distribution of the image data.
5. The memory management method according to claim 4, characterized in that: The optimizing memory by calling a corresponding memory management method according to the memory management information includes: Acquire optimization information corresponding to the image according to the graphic element feature information, wherein the optimization information is at least one of vertex duplication information, edge information, and structure information; The data amount of the image data is reduced according to the optimization information.
6. The memory management method according to claim 1, characterized in that: The memory management information includes memory block information, and the invoking a corresponding memory management method to optimize memory according to the memory management information includes: Acquire an adjacent and free free memory block according to the memory block information, wherein the memory block information includes at least one of a starting address, a size, and a usage status; Merging the free memory blocks and arranging the used memory blocks according to a preset rule; If a memory block allocation instruction is detected, a memory block is allocated based on the memory block allocation instruction and the merge result.
7. The memory management method according to claim 1, characterized in that: The method comprises: If it is determined that a loading operation is to be performed, the scene data corresponding to the loading operation is obtained, and memory is allocated, monitored and released according to the scene data. The scene data includes at least one of the number of loaded objects, texture information corresponding to the loaded objects, the number of frames, and the complexity of special effects.
8. An electronic device comprising a memory, a processor and a computer program stored in 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 to 7.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Memory management method and device, electronic device and computer readable storage medium
CN110008021A
Memory management method and device and storage medium
CN113127181A
Method and system for managing memory occupied by reference counting
CN113778670A
Memory use method, electronic equipment and storage medium
CN114218130A
Object creation method and device based on memory management, equipment and storage medium
CN116139498A
