Memory leak in C/C++


See complete series on pointers and dynamic memory in C/C++ here:

In this lesson, we have explained the concept of memory leak in C/C++. This is a good interview question also. Memory leak happens due to improper use of dynamic memory in a program when we get some memory using malloc and do not free it, when its not being used.

Feel free to drop your comments, feedback and suggestions.

For practice problems and more, visit:

Like us on Facebook:

Follow us on twitter:



  1. Really enjoyed this playlist about pointers, I was quite afraid about using them because I didn't understand them well. But now I really enjoy the concept and very useful the teaching about memory management! I'll check your other playlists too!

  2. char* C=(int*)malloc(3*sizeof(char))
    Do we need one more character to store null termination? I guess not, why? I mean here it's not important (or we could add it and in the next line instead of – 1 we write – 2), but what if we want to read it like string, then we would include it, right?

  3. Hey. Thanks for the tutorials. I really appreciate them. But theres something id like to know. When the Play function gets deleted it deletes the Pointer as well. Right? What would happen when i allocate the C Array in Main? Then my pointer would be in main and couldnt be deleted? It feels like a waste to write the value 'J' 'Q' and 'K' in the C array every time Play starts anew. Feels kinda wrong when i think about big projects that would deal with 10000 Characters instead of just 3.

  4. Thanks a lot for this playlist …it was very informative and the programming concepts including heap ,stacks which come under memory management was taught in great depth…thanks a lot again .

  5. looks like using Heap makes you a winner and using Stack makes you a looser.
    Serious: How on earth can such s little program make the memory usage "shoot up" thousands of bytes after a few steps?
    Did I miss something?
    Ok i rewatched the part: "after some time of playing…" .. i wonder how much time it took to increase the memory 140.000 Bytes…

  6. I know this video is old and no one will probably see this but my teacher can succ your dikh when it comes to teaching programming languages

  7. i have one simple code to check out memory leak in task manager…..



    #define SIZE 100000000// replace memory size here!!

    void leak()


    int *c=(int*)malloc(SIZE*sizeof(int));

    int i;




    void main()


    int i;



    printf("do u want to increase the memory? press 1 to continue.n");









Please enter your comment!
Please enter your name here