what is a memory leak

10 months ago 28
Nature

A memory leak is a type of resource leak that occurs when a computer program incorrectly manages memory allocations in a way that memory which is no longer needed is not released. This can happen when an object is stored in memory but cannot be accessed by the running code, or when a program uses some memory but never clears the memory it had used previously. Memory leaks can reduce the performance of the computer by reducing the amount of available memory, and eventually, in the worst case, too much of the available memory may become allocated and all or part of the system or device stops working correctly, the application fails, or the system slows down vastly due to thrashing. Memory leaks are particularly serious issues for programs like daemons and servers which by definition never terminate. To avoid memory leaks, memory allocated on the heap should always be freed when no longer needed. There are tools available, such as Valgrind, that can help track down memory leaks.