Home » Blog » What is memory leak? Why it should be avoided.

What is memory leak? Why it should be avoided.

Memory leak occurs when programmers create a memory in heap and forget to delete it. Memory leaks are particularly serious issues for programs like daemons and servers which by definition never terminate.

#include <stdlib.h> 
  
void f() 
{ 
    int* ptr = (int*)malloc(sizeof(int)); 
  
  
    return; /* Return without freeing ptr*/
}

 

Leave a Reply

Your email address will not be published.