计划终止后动态分配的内存 [英] dynamically allocated memory after program termination

查看:94
本文介绍了计划终止后动态分配的内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在包含动态分配的内存中的C / C ++程序(使用malloc /新)没有自由/删除通话被终止,会发生什么情况,来动态分配的内存?
是否操作系统收回内存还是内存变得不可访问其他程序?

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.

如果你编程的单片机,​​在Mac OS 9或早期的版本,DOS或Windows 3.x中,那么你可能需要关注的内存泄漏使得内存permenantly不可用整个操作系统。

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.

这篇关于计划终止后动态分配的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆