memory leak: new and delete
If you use new without a corresponding call to delete, then this without exception always causes a memory leak?
If my program does cause a memory leak, Does the OS get the memory back after my program terminates? In other words, If I run the following program 100 times in a row, will it eventually crash and not be able to run because all the memory is gone?:
(assuming i have 64 megs of ram..)
int main() {
new int[250000]; // 1 meg
}
thanks!
-----
It''''s not my fault I''''m the biggest and the strongest; I don''''t even exercise!
quote: Original post by AndreTheGiant
If you use new without a corresponding call to delete, then this without exception always causes a memory leak?
Yes. It also means the object''s destructor never gets called, which might leak other resources aswell.
quote:
If my program does cause a memory leak, Does the OS get the memory back after my program terminates?
On sane OS''s, yes. The OS will reclaim all of the heap memory it allocated to the program. Whether it reclaims things like file-handles, sockets, etc, is another matter.
quote:
In other words, If I run the following program 100 times in a row, will it eventually crash and not be able to run because all the memory is gone?:
It''s more likely the OS will decline the program''s requests for stupid amounts of memory.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement