Memory release methods, devices, electronic devices and storage media

By judging and marking repeatedly released memory blocks after the memory release request, the problem of system crash caused by not being properly released is solved, and effective memory release and system stability are improved.

CN115048237BActive Publication Date: 2025-02-18NINGBO SANXING INTELLIGENT ELECTRIC
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210743508.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-27
Publication Date
2025-02-18
Estimated Expiration
2042-06-27

AI Technical Summary

Technical Problem

The existing technology is difficult to effectively release memory, resulting in the memory not being released correctly. When an application applies for the memory again, it is easy for the system to crash.

Method used

After responding to the application's memory release request, determine whether the memory block is repeatedly released. If yes, mark it as re-freeing of memory blocks to avoid re-allocating to the application.

Benefits of technology

By marking repeatedly released memory blocks, avoiding them being allocated to the application again, effectively preventing memory crashes and improving system stability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115048237B_ABST
    Figure CN115048237B_ABST
Patent Text Reader

Abstract

The embodiment of the present invention provides a memory release method, device, electronic device and storage medium, which relate to the field of memory management technology. The method includes: responding to a memory release request sent by a first application, the memory release request includes an address range of a first memory block; determining the first memory block according to the address range, and releasing the first memory block; judging whether the first memory block is released repeatedly; if so, marking the first memory block as a repeatedly released memory block to avoid the first memory block being allocated to the application again; if not, marking the first memory block as a free memory block. Since the determined repeatedly released memory block is marked as a repeatedly released memory block, the memory block is avoided from being allocated to the application again and released again, thereby avoiding the memory crash caused by the memory block being allocated to the application again and released again.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of memory management, and in particular to a memory release method, device, electronic device and storage medium. Background Art

[0002] When an application is running, it will apply to the system for permission to use memory and store variables and other data in the memory obtained. When the application no longer needs this data, it will send a memory release request to the system. The system will respond to the memory release request and release the corresponding memory so that the released memory can be reused.

[0003] When the memory is not released correctly, the application will request the memory again, which may cause the system to crash. Therefore, how to release the memory effectively and avoid system crash is an urgent problem to be solved. Summary of the invention

[0004] The purpose of the present invention includes, for example, providing a memory release method, which can respond to the memory release request of the application and release the corresponding memory block. If it is determined that the memory block is released repeatedly, the memory block will be marked as a repeatedly released memory block to avoid the first memory block being allocated to the application again and causing a memory crash.

[0005] In order to achieve the above purpose, the technical solution adopted by the embodiment of the present invention is as follows:

[0006] In a first aspect, an embodiment of the present invention provides a memory release method, characterized in that it is applied to an electronic device, comprising:

[0007] Responding to a memory release request sent by a first application, wherein the memory release request includes an address range of a first memory block;

[0008] Determine the first memory block according to the address range, and release the first memory block;

[0009] Determining whether the first memory block is released repeatedly;

[0010] If yes, marking the first memory block as a repeated released memory block to prevent the first memory block from being allocated to the application again;

[0011] If not, the first memory block is marked as a free memory block.

[0012] In a possible implementation, the first memory block includes an initial memory release value, where the initial memory release value represents the number of times the first memory block is continuously released;

[0013] The step of determining whether the first memory block is released repeatedly includes:

[0014] Add 1 to the initial memory release value to obtain a target memory release value;

[0015] If the target memory release value is greater than a preset value, it indicates that the first memory block is released repeatedly; wherein the preset value indicates the number of consecutive releases corresponding to the repeated release of the memory block;

[0016] If the target memory release value is less than or equal to the preset value, it indicates that the first memory block is not repeatedly released.

[0017] In a possible implementation, the method further includes:

[0018] Responding to a memory allocation request sent by a second application, wherein the memory allocation request includes a memory address size;

[0019] Determine whether there is a free memory block that meets the memory address size;

[0020] If yes, allocating a second memory block for the second application in any one of the free memory blocks;

[0021] If not, determining at least one target memory block from all the repeatedly released memory blocks, and reclaiming each of the target memory blocks using a preset reclaiming algorithm to obtain each reclaimed memory block, and allocating the second memory block to the second application program from all the reclaimed memory blocks;

[0022] The initial memory release value of the second memory block is set to 0.

[0023] In a possible implementation manner, the electronic device pre-stores a log table, the log table including the address range of each memory block and the accumulated release times corresponding to each address range;

[0024] The step of determining at least one target memory block from all the repeatedly released memory blocks comprises:

[0025] According to the address range of each repeatedly released memory block, determining the cumulative release times of each repeatedly released memory block from the log table;

[0026] Calculate the release count threshold of the repeated release memory block;

[0027] Each repeatedly released memory block whose cumulative release times is greater than 1 and less than or equal to the current release times threshold is used as the target memory block.

[0028] In a possible implementation, the log table further includes the historical number of times the electronic device recycles the repeatedly released memory block; and the step of calculating the current release number threshold of the repeatedly released memory block includes:

[0029] Obtain the historical recycling times from the log table;

[0030] According to the historical recycling times and the preset release times threshold, the current release times threshold is calculated using the preset formula k=2^n×k0; wherein the preset release times threshold represents the release times threshold corresponding to the first recycling of the repeatedly released memory block by the electronic device;

[0031] Wherein, k is the current release times threshold, n is the historical recycling times, and k0 is the preset release times threshold.

[0032] In a second aspect, an embodiment of the present invention further provides a memory release device, which is applied to an electronic device, and the memory release device includes:

[0033] A response module, used for responding to a memory release request sent by the first application, wherein the memory release request includes an address range of the first memory block;

[0034] A release module, used for determining the first memory block according to the address range, and releasing the first memory block;

[0035] A judging module, used for judging whether the first memory block is released repeatedly;

[0036] Marking module for:

[0037] If yes, marking the first memory block as a repeated released memory block to prevent the first memory block from being allocated to the application again;

[0038] If not, the first memory block is marked as a free memory block.

[0039] In a third aspect, an embodiment of the present invention further provides an electronic device, the electronic device comprising:

[0040] one or more processors;

[0041] The memory is used to store one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement the above-mentioned memory release method.

[0042] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, and the computer program implements the above-mentioned memory release method when executed by a processor.

[0043] Compared with the prior art, the embodiments of the present invention provide a memory release method, device, electronic device and storage medium, the method comprising: responding to a memory release request sent by a first application, the memory release request including an address range of a first memory block; determining the first memory block according to the address range, and releasing the first memory block; judging whether the first memory block is released repeatedly; if so, marking the first memory block as a repeatedly released memory block to avoid the first memory block being allocated to the application again; if not, marking the first memory block as a free memory block. Since the determined repeatedly released memory block is marked as a repeatedly released memory block, the situation in which the memory block is allocated to the application again and causes a memory crash is avoided. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.

[0045] Figure 1 A flowchart of a memory release method provided in an embodiment of the present invention.

[0046] Figure 2 An example diagram of a memory release method provided in an embodiment of the present invention.

[0047] Figure 3 Another flowchart of a memory release method provided by an embodiment of the present invention.

[0048] Figure 4 A block diagram of a memory release device provided by an embodiment of the present invention.

[0049] Figure 5 A block diagram of an electronic device provided by an embodiment of the present invention.

[0050] Icons: 100 - electronic device; 101 - memory; 102 - processor; 103 - bus; 200 - memory release device; 201 - response module; 202 - release module; 203 - judgment module; 204 - marking module; 205 - allocation module. DETAILED DESCRIPTION

[0051] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.

[0052] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0053] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.

[0054] In addition, the terms “first”, “second”, etc., if used, are merely used to distinguish between the descriptions and should not be understood as indicating or implying relative importance.

[0055] It should be noted that, in the absence of conflict, the features in the embodiments of the present invention may be combined with each other.

[0056] When an application is running, it will apply to the system for permission to use memory and store variables and other data in the memory obtained. When the application no longer needs this data, it will send a memory release request to the system. The system will respond to the memory release request and release the corresponding memory so that the released memory can be reused.

[0057] Due to defects in the code of some applications, a block of memory that has been released may be released again, i.e., repeated release. Assuming that a free flag is assigned to the memory block released for the first time, the free flags of the memory blocks released repeatedly will be accumulated. When the memory block is requested by the application again, the memory block still includes a free flag, that is, the memory block is not protected and can still be requested by other applications. When the memory block is requested by other applications at the same time, it will cause memory trampling, resulting in a memory crash of the system.

[0058] To solve the above problems, this embodiment provides a memory release method. When releasing a memory block, if it is determined that the memory block is released repeatedly, the memory block is marked as a repeatedly released memory block to avoid the memory block being allocated to the application again and causing a memory crash.

[0059] A detailed introduction is given below.

[0060] Please refer to Figure 1 , Figure 1 The flowchart of the memory release method provided in this embodiment is shown, and the memory release method is applied to the electronic device 100. The method may include the following steps S110-S150.

[0061] S110, responding to a memory release request sent by a first application, where the memory release request includes an address range of a first memory block.

[0062] In this embodiment, if the memory release request is the first memory release request, before step S110, the first application may also send a memory allocation request to the system, and the system allocates a first memory block to the first application according to the memory allocation request. At this time, the status of the first memory block is allocated.

[0063] If the memory release request is not the first release request, the first memory block has been released before step S110.

[0064] S120: Determine a first memory block according to the address range, and release the first memory block.

[0065] S130, determining whether the first memory block is released repeatedly.

[0066] S140: If the first memory block is released repeatedly, mark the first memory block as a repeatedly released memory block to prevent the first memory block from being allocated to the application again.

[0067] S150: If the first memory block is not released repeatedly, mark the first memory block as a free memory block.

[0068] In this embodiment, if the first memory block is repeatedly released, it indicates that the memory block has been released before the release. If the memory block is allocated to the application again, it is easy to cause a system memory crash. Therefore, the first memory block is marked as a repeatedly released memory block, and the memory block marked as a repeatedly released memory block is not allowed to be allocated to the application again.

[0069] If the first memory block is not released repeatedly, that is, the first memory block is released for the first time, the first memory block is allowed to be allocated to the application again.

[0070] Compared with the prior art, the memory release method provided in this embodiment responds to the memory release request of the application and releases the corresponding memory block. If it is determined that the memory block is released repeatedly, the memory block will be marked as a repeatedly released memory block, thereby avoiding the first memory block being allocated to the application again and causing memory crash.

[0071] Optionally, the first memory block includes an initial memory release value, and the initial memory release value represents the number of times the first memory block is continuously released.

[0072] Step S130 may include the following steps S1301 - S1303 .

[0073] S1301, add 1 to the initial memory release value to obtain the target memory release value.

[0074] S1302: If the target memory release value is greater than a preset value, it indicates that the first memory block is repeatedly released; wherein the preset value indicates the number of consecutive releases corresponding to the repeated release of the memory block.

[0075] S1303: If the target memory release value is less than or equal to the preset value, it indicates that the first memory block is not repeatedly released.

[0076] In this embodiment, the preset value can be set to 2.

[0077] When a memory block is first requested by an application, the system assigns a memory release value to the memory block and sets the memory release value to 0. When the memory block is released, the memory block is initialized and the memory release value is set to 1. At this time, the memory block can be requested again.

[0078] If the memory block is requested again, the memory release value is set to 0; when it is released again, the memory block is marked as a dirty block and the memory release value is increased by 1.

[0079] If a dirty block is released again due to an application error, the memory release value is increased by 1, and the memory block is marked as a repeated released memory block. Any address in the memory block is not allowed to be applied for as a new memory block by the application.

[0080] The following example illustrates the above process. Figure 2 .

[0081] S1. The application sends a memory allocation request to the controller.

[0082] S2. The controller allocates a free memory block to the application, marks the free memory block as an occupied memory block, and sets the memory release value to 0.

[0083] S3: When the application finishes using the memory block, it sends a memory release request to the controller. The controller releases the memory block, marks the memory block as a free memory block, and increases the memory release value by 1.

[0084] S4. Due to code defects or other reasons, the application sends a memory release request to the controller again. The memory release request points to the memory block released last time. The controller releases the memory block and adds 1 to the memory release value. At the same time, it is determined that the memory block is released repeatedly and the memory block is marked as a repeatedly released memory block.

[0085] Optional, in Figure 1 Based on Figure 3 The memory release method may further include the following steps S210-S250 which are parallel to steps S110-S150.

[0086] S210, responding to a memory allocation request sent by a second application, where the memory allocation request includes a memory address size.

[0087] S220, determine whether there is a free memory block that meets the memory address size.

[0088] S230: If yes, allocate a second memory block for the second application in any free memory block.

[0089] S240, if not, determine at least one target memory block from all repeatedly released memory blocks, and recycle each target memory block using a preset recycling algorithm to obtain each recycled memory block, and allocate a second memory block to the second application in all recycled memory blocks.

[0090] In this embodiment, after each target memory block is determined, the release count of each target memory block is modified to 1, and all memory blocks with a release count of 1 are recycled using a preset recycling algorithm to initialize each target memory block. After initialization, the target memory block is a free memory block and is allowed to be allocated to the application again.

[0091] S250: Set the initial memory release value of the second memory block to 0.

[0092] Optionally, the electronic device 100 pre-stores a log table, which includes the address range of each memory block and the accumulated release times corresponding to each address range.

[0093] Determining at least one target memory block from all repeatedly released memory blocks in step S240 may include the following sub-steps S2401 - S2403 .

[0094] S2401, according to the address range of each repeatedly released memory block, determine the cumulative release times of each repeatedly released memory block from the log table.

[0095] In this embodiment, the log table is used to record the system's operations on the memory block, including the time when the memory block is marked as a repeatedly released memory block, the address range of each repeatedly released memory block, the size of each repeatedly released memory block, the cumulative number of releases of each repeatedly released memory block, and the historical number of times the electronic device 100 recycles the repeatedly released memory block.

[0096] The electronic device 100 generates corresponding information for the operation of repeatedly releasing the memory block and records it in the log table.

[0097] S2402, calculating a release count threshold for repeatedly releasing a memory block.

[0098] In this embodiment, the current release count threshold represents the release count threshold of the repeatedly released memory block corresponding to the reclaiming of the repeatedly released memory block by the system at the current time.

[0099] S2403, taking each repeatedly released memory block whose cumulative release times is greater than 1 and less than or equal to the current release times threshold as the target memory block.

[0100] In this embodiment, for example, if the threshold of the number of times of release is kn, each repeatedly released memory block whose cumulative number of releases belongs to (1, kn] is determined, and the repeatedly released memory block is used as the target memory block.

[0101] Optionally, the log table also includes the historical number of times the electronic device reclaims the repeatedly released memory blocks. Step S2402 may include the following detailed steps.

[0102] The first step is to obtain the historical recycling times from the log table.

[0103] The second step is to use the preset formula k=2 based on the historical recycling times and the preset release times threshold. n ×k0 calculates the release times threshold for that time; wherein the preset release threshold represents the release times threshold corresponding to the first recycling of the repeatedly released memory block by the electronic device.

[0104] Wherein, k is the current release count threshold, n is the historical recycling count, and k0 is the preset release count threshold.

[0105] In this embodiment, the preset release threshold is set by a technician based on experience, and is generally set to 3.

[0106] For example, when the system first encounters insufficient allocatable free memory, the first recycling of repeatedly released memory blocks is performed, and the repeatedly released memory blocks with memory release values ​​belonging to (1, 3] are taken as target memory blocks, and the memory release value of the target memory blocks is set to 1. Then, the preset recycling algorithm is used to recycle all memory blocks with memory release values ​​of 1.

[0107] Compared with the prior art, this embodiment has the following beneficial effects:

[0108] First, the memory release method provided in this embodiment responds to the memory release request of the application and releases the corresponding memory block. If it is determined that the memory block is released repeatedly, the memory block will be marked as a repeatedly released memory block to avoid the first memory block being allocated to the application again and causing a memory crash.

[0109] Then, in this embodiment, a memory release value is allocated to each applied memory block, which is used to record the number of times the memory block is continuously released, so that it can be determined whether the memory block is repeatedly released according to the memory release value.

[0110] Please refer to Figure 4 , Figure 4 The block diagram of the memory release device 200 provided in this embodiment is shown. The memory release device 200 is applied to the electronic device 100 and includes: a response module 201 , a release module 202 , a judgment module 203 , a marking module 204 and an allocation module 205 .

[0111] The response module 201 is used to respond to a memory release request sent by a first application program, where the memory release request includes an address range of a first memory block.

[0112] The release module 202 is used to determine the first memory block according to the address range and release the first memory block.

[0113] The judging module 203 is used to judge whether the first memory block is released repeatedly.

[0114] The marking module 204 is used to:

[0115] If the first memory block is released repeatedly, the first memory block is marked as a repeatedly released memory block to prevent the first memory block from being allocated to the application again.

[0116] If the first memory block is not released repeatedly, the first memory block is marked as a free memory block.

[0117] Optionally, the electronic device 100 pre-stores a log table, which includes the address range of each memory block and the cumulative release times corresponding to each address range; the first memory block includes an initial memory release value, which represents the number of consecutive releases of the first memory block.

[0118] The judging module 203 is further used for:

[0119] Add 1 to the initial memory release value to get the target memory release value.

[0120] If the target memory release value is greater than a preset value, it indicates that the first memory block is repeatedly released; wherein the preset value indicates the number of consecutive releases corresponding to the repeated release of the memory block.

[0121] If the target memory release value is less than or equal to the preset value, it indicates that the first memory block is not repeatedly released.

[0122] Optionally, the memory release device also includes an allocation module.

[0123] The response module 201 is further used to respond to the memory allocation request sent by the second application, where the memory allocation request includes the memory address size.

[0124] The allocation module 205 is used to:

[0125] Determine whether there is a free memory block that meets the memory address size.

[0126] If so, a second memory block is allocated for the second application in any free memory block.

[0127] If not, at least one target memory block is determined from all repeatedly released memory blocks, and each target memory block is reclaimed using a preset reclaiming algorithm to obtain each reclaimed memory block, and a second memory block is allocated to the second application in all reclaimed memory blocks.

[0128] Set the initial memory release value of the second memory block to 0.

[0129] Optionally, the allocation module 205 is further configured to:

[0130] According to the address range of each repeatedly released memory block, the accumulated release times of each repeatedly released memory block is determined from the log table.

[0131] Calculate the current release count threshold of the repeatedly released memory block.

[0132] Each repeatedly released memory block whose cumulative release times is greater than 1 and less than or equal to the current release times threshold is used as the target memory block.

[0133] Optionally, the log table also includes the historical number of times the electronic device reclaims repeatedly released memory blocks.

[0134] The allocation module 205 is further used for:

[0135] Get the historical recycling times from the log table.

[0136] According to the historical recycling times and the preset release times threshold, the preset formula k=2 is used. n×k0 calculates the release times threshold for that time; wherein the preset release threshold represents the release times threshold corresponding to the first recycling of the repeatedly released memory block by the electronic device.

[0137] Wherein, k is the current release count threshold, n is the historical recycling count, and k0 is the preset release count threshold.

[0138] Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working process of the memory release device 200 described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0139] Please refer to Figure 5 , Figure 5 A block diagram of an electronic device 100 provided in the present embodiment is shown, and the electronic device 100 may be, but not limited to, a mobile phone, a tablet computer, a laptop computer, a server or other electronic device with processing capabilities, and may also be a general-purpose computer or a computer for special purposes. The electronic device 100 includes a memory 101, a processor 102 and a bus 103. The memory 101 and the processor 102 are connected via a bus 103, for example, a disk, a ROM, or a RAM, or any combination thereof. Exemplarily, the electronic device 100 may also include program instructions stored in a ROM, a RAM, or other types of non-temporary storage media, or any combination thereof. The method of the present invention may be implemented according to these program instructions.

[0140] The memory 101 is used to store programs, such as the memory release device 200. The memory release device 200 includes at least one software function module that can be stored in the memory 101 in the form of software or firmware. After receiving the execution instruction, the processor 102 executes the program to implement the memory release method in this embodiment.

[0141] Among them, the memory 101 can be, but is not limited to, random access memory (Random Access Memory, RAM), read only memory (Read Only Memory, ROM), programmable read-only memory (Programmable Read-Only Memory, PROM), erasable programmable read-only memory (Erasable Programmable Read-Only Memory, EPROM), electrically erasable read-only memory (Electric Erasable Programmable Read-Only Memory, EEPROM), etc.

[0142] The processor 102 may be an integrated circuit chip with signal processing capability. In the implementation process, each step of the memory release method in this embodiment can be completed by an integrated logic circuit of hardware in the processor 102 or an instruction in the form of software. The above-mentioned processor 102 can be a general-purpose processor, including a central processing unit (CPU), a microcontroller unit (MCU), a complex programmable logic device (CPLD), a field programmable gate array (FPGA), an embedded ARM and other chips.

[0143] For ease of explanation, only one processor is described in the electronic device 100. However, it should be noted that the electronic device 100 in the present invention may also include multiple processors, so the steps performed by one processor described in the present invention may also be performed jointly or individually by multiple processors. For example, if the processor of the electronic device 100 performs step A and step B, it should be understood that step A and step B may also be performed jointly by two different processors or individually in one processor. For example, the first processor performs step A, the second processor performs step B, or the first processor and the second processor perform steps A and B together.

[0144] This embodiment further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by the processor 102, the memory release method disclosed in the above embodiment is implemented.

[0145] In summary, an embodiment of the present invention provides a memory release method, device, electronic device and storage medium, the method comprising: responding to a memory release request sent by a first application, the memory release request including an address range of a first memory block; determining the first memory block according to the address range, and releasing the first memory block; judging whether the first memory block is released repeatedly; if so, marking the first memory block as a repeatedly released memory block to avoid the first memory block being allocated to the application again; if not, marking the first memory block as a free memory block. Since the determined repeatedly released memory block is marked as a repeatedly released memory block, the situation in which the memory block is allocated to the application again and causes a memory crash is avoided.

[0146] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.

Claims

1. A memory release method, characterized in that: Used in electronic equipment, including: Responding to a memory release request sent by a first application, wherein the memory release request includes an address range of a first memory block; Determine the first memory block according to the address range, and release the first memory block; the first memory block includes an initial memory release value, and the initial memory release value represents the number of times the first memory block is continuously released; Determining whether the first memory block is released repeatedly; The determining whether the first memory block is released repeatedly includes: Add 1 to the initial memory release value to obtain a target memory release value; if the target memory release value is greater than a preset value, it indicates that the first memory block is repeatedly released; wherein the preset value indicates the number of consecutive releases corresponding to the repeated release of the memory block; if the target memory release value is less than or equal to the preset value, it indicates that the first memory block is not repeatedly released; If yes, marking the first memory block as a repeated released memory block to prevent the first memory block from being allocated to the application again; If not, the first memory block is marked as a free memory block.

2. The method according to claim 1, characterized in that The method further comprises: Responding to a memory allocation request sent by a second application, wherein the memory allocation request includes a memory address size; Determine whether there is a free memory block that meets the memory address size; If yes, allocating a second memory block for the second application in any one of the free memory blocks; If not, determining at least one target memory block from all the repeatedly released memory blocks, and reclaiming each of the target memory blocks using a preset reclaiming algorithm to obtain each reclaimed memory block, and allocating the second memory block to the second application program from all the reclaimed memory blocks; The initial memory release value of the second memory block is set to 0.

3. The method according to claim 2, characterized in that The electronic device pre-stores a log table, wherein the log table includes an address range of each memory block and a cumulative number of releases corresponding to each address range; The step of determining at least one target memory block from all the repeatedly released memory blocks comprises: According to the address range of each repeatedly released memory block, determining the cumulative release times of each repeatedly released memory block from the log table; Calculate the release count threshold of the repeated release memory block; Each repeatedly released memory block whose cumulative release times is greater than 1 and less than or equal to the current release times threshold is used as the target memory block.

4. The method according to claim 3, characterized in that The log table also includes the historical recycling times of the repeatedly released memory blocks recycled by the electronic device; the step of calculating the current release times threshold of the repeatedly released memory blocks includes: Obtain the historical recycling times from the log table; According to the historical recycling times and the preset release times threshold, the preset formula k= k0 calculates the current release times threshold; wherein the preset release times threshold represents the release times threshold corresponding to the first recycling of the repeatedly released memory block by the electronic device; Wherein, k is the current release times threshold, n is the historical recycling times, and k0 is the preset release times threshold.

5. A memory release device, characterized in that: Applied to electronic equipment, the memory release device comprises: A response module, used for responding to a memory release request sent by the first application, wherein the memory release request includes an address range of the first memory block; A release module, configured to determine the first memory block according to the address range, and release the first memory block; the first memory block includes an initial memory release value, and the initial memory release value represents the number of times the first memory block is continuously released; A judging module, used for judging whether the first memory block is released repeatedly; The judgment module is further used to add 1 to the initial memory release value to obtain a target memory release value; if the target memory release value is greater than a preset value, it indicates that the first memory block is repeatedly released; wherein the preset value indicates the number of consecutive releases corresponding to the repeated release of the memory block; if the target memory release value is less than or equal to the preset value, it indicates that the first memory block is not repeatedly released; Marking module for: If yes, marking the first memory block as a repeated released memory block to prevent the first memory block from being allocated to the application again; If not, the first memory block is marked as a free memory block.

6. The memory release device according to claim 5, characterized in that: The memory release device also includes an allocation module; The response module is further used to respond to a memory allocation request sent by the second application, wherein the memory allocation request includes a memory address size; The allocation module is used to: Determine whether there is a free memory block that meets the memory address size; If yes, allocating a second memory block for the second application in any one of the free memory blocks; If not, determining at least one target memory block from all the repeatedly released memory blocks, and reclaiming each of the target memory blocks using a preset reclaiming algorithm to obtain each reclaimed memory block, and allocating the second memory block to the second application program from all the reclaimed memory blocks; The initial memory release value of the second memory block is set to 0.

7. An electronic device, characterized in that: The electronic device comprises: one or more processors; A memory, used to store one or more programs, when the one or more programs are executed by the one or more processors, enables the one or more processors to implement the memory release method according to any one of claims 1 to 4.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the memory release method according to any one of claims 1 to 4 is implemented.

Citation Information

Patent Citations

  • Memory management method and device

    CN105589809A

  • Memory processing method and device

    CN108509273A