views:

199

answers:

2

I am wondering if i new some object but forget to delete it, when the process exit, will the leaked memory be returned to the OS?

+7  A: 

This isn't a C++ question, more of an operating system question.

All of the operating systems that I have knowledge of will reclaim conventional memory that had been allocated. That's because the allocation generally comes from a processes private address space which will be reclaimed on exit.

This may not be true for other resources such as shared memory. There are implementations that will not release shared memory segments unless you specifically detach from them before your process exits.

paxdiablo
+1  A: 

For most modern operating systems (most flavors of unix and anything running in protected memory under x86), the memory allocation occurs within a program's heap (either through malloc for C or new/delete for C++). So when the program exits, then the memory will be released for use elsewhere.

cab105