Benny
Benny

Reputation: 8815

When process exit, will the memory that's left undeleted be returned to OS?

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?

Upvotes: 3

Views: 1179

Answers (2)

paxdiablo
paxdiablo

Reputation: 881993

This isn't so mush a C++ question as 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 mark them for deletion before your process exits (and, even then, they don't get deleted until everyone has detached).

Upvotes: 7

cab105
cab105

Reputation: 11

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.

Upvotes: 1

Related Questions