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.
这篇关于程序终止后动态分配的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:程序终止后动态分配的内存


基础教程推荐
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 我有静态或动态 boost 库吗? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01