What is a memory leak?

Seems like you do understand it – with one exception: In your example, len is a stack variable like everything else. new or malloc create on the heap, everything else (local variables etc) is on the stack. And main’s local variables are not different from any other function’s variables. Shared memory is a rather rare … Read more