问题描述
如果我在不知情的情况下编写了内存泄漏,然后应用程序终止,泄漏的内存是否被释放?
If I programmed — without knowing it — a memory leak, and the application terminates, is the leaked memory freed?
推荐答案
是的,内存泄漏"只是进程不再引用的内存,因此无法再释放.操作系统仍会跟踪分配给进程的所有内存,并在该进程终止时将其释放.
Yes, a "memory leak" is simply memory that a process no longer has a reference to, and thus can no longer free. The OS still keeps track of all the memory allocated to a process, and will free it when that process terminates.
在绝大多数情况下,操作系统会释放内存 - 就像 Windows、Linux、Solaris 等正常风格"的情况一样.但重要的是要注意,在各种实时环境等特殊环境中操作系统程序终止时可能不会释放内存.
In the vast majority of cases the OS will free the memory - as is the case with normal "flavors" of Windows, Linux, Solaris, etc. However it is important to note that in specialized environments such as various Real-Time Operating Systems the memory may not be freed when the program is terminated.
这篇关于程序退出时是否释放了泄漏的内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!