World's most popular travel blog for travel bloggers.

Does the memory get unallocated when program exits?

, , No Comments
Problem Detail: 

I have been trying to manipulate pointers just for the sake of studying. I have had some problems with some programs I wrote where I had memory leak.

Does this memory stay allocated even when the program returns?

  • If yes how to deallocate it?
  • If no why, isn't all saved in heap so only the one who has that heap pointer can deallocate? Or does the operating system pull some magic tricks?

Asked By : Erin Avllazagaj
Answered By : Kyle Jones

When you run your program its memory allocations take the form of page allocation requests to the operating system. When your program terminates, the operating system notices and returns all the allocated pages to the list of free pages, which can then be used by other processes. It does not matter if your program leaks memory (other than potentially using more memory as a result), because ultimately the operating system will reclaim everything.

Best Answer from StackOverflow

Question Source :

3200 people like this

 Download Related Notes/Documents


Post a Comment

Let us know your responses and feedback