Click to See Complete Forum and Search --> : Memory allocation
papudutta
October 16th, 2001, 08:31 PM
A basic question :-
An application allocates memory (from the heap) by using new. It terminates without deleting the assigned memory (from the heap). Now does that mean the OS will not use that memory at all which was allocated to the application for some other usage.
Thanks
Green_Beret
October 16th, 2001, 10:09 PM
Yes, the OS won't use that memory, since it has not been de-allocated. It will only be able to use that memory when the system is rebooted.
Regards,
The Beret.
Igor Soukhov
October 17th, 2001, 12:50 AM
In Windows all memory is owned by process. Then process is gone ALL memory was freed.
Please - rate answer if it helped you
It gives me inspiration when I see myself in the top list =)
Best regards,
-----------
Igor Soukhov (Brainbench/Tekmetrics ID:50759)
igor@soukhov.com | ICQ:57404554 | http://soukhov.com
Member of Russian Software Developer Network http://rsdn.ru
Green_Beret
October 17th, 2001, 01:16 AM
Igor,
Can you elaborate a bit on your statement?
What happens if the Process is not terminated and the malloc or new is being done in a loop many times? Will it then lead to a memory leak? And does finally terminating the process, return that memory back to the O.S.?
And what kind of behaviour will such a program exhibit in an UNIX system?
Finally, can you provide some links to sites explaining the Memory Organisation in a Windows system.
Thanks,
The Beret.
papudutta
October 17th, 2001, 12:19 PM
Igor
Do you mean the memory will free up in Windows and not in UNIX when the application/process terminates? Please comment
Thanks
NeilPearson
October 17th, 2001, 02:30 PM
This is not true. When the application is terminated all memory that the application has allocated will be freed up and the OS will use it again. The application frees all memory when the application closes even if delete has not been called
Paul McKenzie
October 17th, 2001, 04:47 PM
Igor's post is correct for Windows, but if this is your own program, please do not make it a habit of relying on the OS to clean up the memory.
The OS may or may not clean up the memory when the application terminates. This all depends on the OS. For example, 16-bit DOS/Windows will not clean up the memory. I don't know about the various UNIX OSes.
Anyway, relying on the OS to clean up the memory that you allocated is sloppy programming. It would (or should) never pass a code review by other fellow programmers. What if you are allocating the memory in a loop, and you slowly are exhausting the memory? Your app dies before the application reaches the end of the loop.
What if you reuse the code that leaks the memory in another portion of your app, where the app does not immediately terminate? Again, you now have a memory leak.
Always make sure to investigate and plug any memory leak in your program, regardless of whether the OS cleans up at the end.
Regards,
Paul McKenzie
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.