English 中文(简体)
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?

最佳回答

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.





相关问题
What resources are shared between threads?

Recently, I have been asked a question in an interview what s the difference between a process and a thread. Really, I did not know the answer. I thought for a minute and gave a very weird answer. ...

Random access of multiple files and file caching

This relates to some software I ve been given to "fix". The easiest and quickest solution would make it open and read 10 random files out of hundreds and extract some very short strings for processing ...

What form is DLL & what makes it processor dependent

I know DLL contains one or more exported functions that are compiled, linked, and stored separately.. My question is about not about how to create it.. but it is all about in what form it is stored.. ...

Thread behavior on multicore machines

Does the threads of a single process run in parallel on a multi-core machine on windows XP? Is the behavior same on different windows versions (windows server editions) I have heard that only threads ...

How to check which Operating System?

How can I check OS version in a batch file or through a vbs in an Windows 2k/2k3 environment ? You know ... Something like ... : "If winver Win2k then ... or if winver Win2k3 then ....

热门标签