问题描述
当一个包含动态分配内存(使用 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.
这篇关于程序终止后动态分配的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)