Is leaked memory freed up when the program exits?(程序退出时是否释放了泄漏的内存?)
问题描述
如果我在不知情的情况下编写了内存泄漏,然后应用程序终止,泄漏的内存是否被释放?
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.
这篇关于程序退出时是否释放了泄漏的内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:程序退出时是否释放了泄漏的内存?


基础教程推荐
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- CString 到 char* 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09