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 case, you usually don’t need it and therefore you won’t have it unless you explicitly ask for it (otherwise, some random other process may use the very same memory your process uses – obviously, this would break things badly).

Leave a Comment