开发者

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

开发者 https://www.devze.com 2022-12-11 20:42 出处:网络
I am wondering if i new some object but forget to de开发者_运维问答lete it, when the process exit, will the leaked memory be returned to the OS?This isn\'t so mush a C++ question as an operating syste

I am wondering if i new some object but forget to de开发者_运维问答lete it, when the process exit, will the leaked memory be returned to the OS?


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).


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消