Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does memory dynamically allocated reside?

We know that malloc() and new operation allocate memory from heap dynamically, but where does heap reside? Does each process have its own private heap in the namespace for dynamic allocation or the OS have a global one shared by all the processes. What's more, I read from a textbook that once memory leak occurs, the missing memory cannot be reused until next time we restart our computer. Is this thesis right? If the answer is yes, how can we explain it?

Thanks for your reply.

Regards.

like image 513
Summer_More_More_Tea Avatar asked Jan 23 '23 07:01

Summer_More_More_Tea


1 Answers

The memory is allocated from the user address space of your process virtual memory. And all the memory is reclaimed by the OS when the process terminates there is no need to restart the computer.

like image 65
Naveen Avatar answered May 16 '23 06:05

Naveen