In computer science, a memory leak is a particular kind of unintentional memory consumption by a computer program where the program fails to release memory when no longer needed. When a memory leak occurs, memory is not physically lost from the computer, but rather becomes claimed but ignored due to program logic flaws. When we are allocating memory using new or malloc and then failing to deallocate the memory after its use within the application’s life span, then the memory allocated earlier will become unusable for the application, there by making it a leak in the memory.

An Example:

Memory graph showing the memory leak When I ran the above program:

<image host deleted my graph :/>

How to avoid it:

Raise your coding standards, be careful while writing code so that whenever memory is allocated, its always deallocated properly.

**One nasty problem is the operating system leaking memory. This is much harder to detect, apart from the application gradually slowing down as the dynamic memory has to start using hard drive as memory.