|
-
October 16th, 2001, 08:31 PM
#1
Memory allocation
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
-
October 16th, 2001, 10:09 PM
#2
Re: Memory allocation
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.
-
October 17th, 2001, 12:50 AM
#3
Re: Memory allocation
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)
[email protected] | ICQ:57404554 | http://soukhov.com
Member of Russian Software Developer Network http://rsdn.ru
-
October 17th, 2001, 01:16 AM
#4
Re: Memory allocation
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.
-
October 17th, 2001, 12:19 PM
#5
Re: Memory allocation
Igor
Do you mean the memory will free up in Windows and not in UNIX when the application/process terminates? Please comment
Thanks
-
October 17th, 2001, 02:30 PM
#6
Re: Memory allocation
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
-
October 17th, 2001, 04:47 PM
#7
Re: Memory allocation
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|