dynamically allocated memory after program termination(程序终止后动态分配的内存)
问题描述
当一个包含动态分配内存(使用 malloc/new)而没有 free/delete 调用的 C/C++ 程序终止时,动态分配的内存会发生什么?操作系统是收回内存还是其他程序无法访问该内存?
When a C/C++ program containing the dynamically allocated memory(using malloc/new) without free/delete calls is terminated, what happens to that dynamically allocated memory? Does the operating system takes back the memory or does that memory becomes unaccessible to other programs?
推荐答案
我不认为语言标准有任何保证,但是支持稀疏虚拟内存和内存保护的现代操作系统(如 MacOS X、Linux、所有最新版本的 Windows 和所有当前制造的手机)在行为不良的进程(当它们终止时)后自动清理并为您释放内存.内存保持不可用,但是只要程序正在运行.
I don't think that there are any guarantees in the language standard, but modern operating systems which support sparse virtual memory and memory protection (such as MacOS X, Linux, all recent version of Windows, and all currently manufactured phone handsets) automatically clean up after badly-behaved processes (when they terminate) and free the memory for you. The memory remains unavailable, however as long as the program is running.
如果您在微控制器、MacOS 9 或更早版本、DOS 或 Windows 3.x 上进行编程,那么您可能需要担心内存泄漏会导致整个操作系统永久无法使用内存.
If you're programming on microcontrollers, on MacOS 9 or earler, DOS, or Windows 3.x, then you might need to be concerned about memory leaks making memory permenantly unavailable to the whole operating system.
这篇关于程序终止后动态分配的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:程序终止后动态分配的内存
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 近似搜索的工作原理 2021-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- C++ 协变模板 2021-01-01
- 从python回调到c++的选项 2022-11-16
- 静态初始化顺序失败 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01