Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

1 Answer
karthikeya Boyini

The memory leak occurs, when a piece of memory which was previously allocated by the programmer. Then it is not deallocated properly by programmer. That memory is no longer in use by the program. So that place is reserved for no reason. That’s why this is called the memory leak.

For the memory leak, some block of memory may have wasted. If the system has enough memory, in that case also this may slow down the performance.

Example

void my_func() {
   int *data = new int;
   *data = 50;
}

Here the problem is *data pointer is never deleted, so memory is wasted.

Example

#include <stdio.h>
main(void) {
   auto int my_fun();
   my_fun();
   printf("Main Function\n");
   int my_fun() {
      printf("my_fun function\n");
   }
   printf("Done");
}

Output

my_fun function
Main Function
Done

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.