Home  >  Article  >  How to solve memory leak

How to solve memory leak

若昕
若昕Original
2019-04-26 12:01:1118264browse

How to solve memory leak

Generally, the memory leak we often talk about refers to the leak of heap memory. Heap memory refers to memory allocated by the program from the heap, of any size (the size of the memory block can be determined during program running), and must be explicitly released after use. Applications generally use malloc, calloc, realloc, new and other functions to allocate a piece of memory from the heap. After use, the program must be responsible for calling free or delete accordingly to release the memory block. Otherwise, this memory cannot be used again. Let's just say that this memory is leaked.

Most memory leaks are caused by the design of the program itself. There are several solutions:

1) Recompile from within the program. Develop good coding habits and try to detect memory leaks in program segments that involve memory.

2) End the program, and the memory will naturally be reclaimed by the operating system.

3) After restarting the computer, restore immediately.


The above is the detailed content of How to solve memory leak. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn