哪些操作系统在程序退出时不会释放内存? [英] What operating systems won't free memory on program exit?

查看:137
本文介绍了哪些操作系统在程序退出时不会释放内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题使我感到好奇.诸如此类的问题总是会得到诸如总体上是安全的,但您不应该假设操作系统会为您完成此操作"之类的答案,这对我来说似乎是个很好的建议,但我想知道:是否有任何积极开发(发布)的软件?操作系统不这样做吗?

This question made me curious. Questions like this always get answers like "It's generally safe but you shouldn't assume that the OS will do this for you", which sounds like good advice to me, but I'm wondering: Are there any actively-developed (released) operating systems that don't do this?

这是在恐龙时代(80年代)修复的吗?

Is this something that was fixed back in the age of dinosaurs (the 80's)?

推荐答案

简短的回答是无".即使是几年前在DOS上运行的程序,也会在程序终止时释放内存(这是由于程序停止时没有任何东西可以管理内存).我确定有人可能会发现内核模式代码不一定会在应用程序退出时释放其内存,或者他们可能会引用一些晦涩的嵌入式操作系统....,但是您可以假设应用程序退出会返回用户模式代码获取的所有内存. . (Windows 3.x可能会出现此问题,具体取决于使用了哪个分配器...)

Short answer is "none". Even a program on DOS years ago would release memory on program termination (simply by the virtue that nothing was managing the memory when the program stopped). I'm sure someone might sight that kernel mode code doesn't necessarily free its memory on app exit or they may cite some obscure embedded os.... but you can assume that app-exit returns all the memory your user mode code acquired. (Windows 3.x might have had this problem depending on which allocator was used...)

之所以要释放内存",是因为对于大型软件工程,您应该努力开发使用灵活的组件,因为您永远都不知道别人会如何改变对它们的使用.您离开团队很久之后的代码.

The reason for the virtue that you "should free your memory" is that for large scale software engineering, you should strive to develop components that are flexible in their use because you never know how someone else is going to change the use of your code long after you've left the team.

这样想吧.假设您设计了一个设计为单例的类(在应用程序生存期内仅实例化一次).因此,您决定在组件破坏或最终确定时不去理会内存清理.在那一刻,这是一个非常好的决定.几年后,在您去了更绿色的牧场之后,其他人可能会出现并决定他们需要在多个地方使用您的课程,以便在应用程序生命周期内来回出现许多实例.您的内存泄漏将成为他们的问题.

Think of it like this. Let's say you design some class that is designed to be a singleton (only instantiated once during the app lifetime). As such, you decide not to bother with memory cleanup when your component destructs or gets finalized. That's a perfectly fine decision for that moment. Years later, after you've left for greener pastures, someone else may come along and decide that they need to use your class in multiple places such that many instances will come and go during the app lifetime. Your memory leak will become their problem.

在我们的团队中,我们经常谈论使用户启动的应用程序关闭"仅是exit()而不进行任何清理.如果我们这样做的话,我仍然会要求团队开发可以自己清理的类和组件.

On my team, we've often talked about making the user initiated "close" of the application just be exit() without doing any cleanup. If we ever do this, I would still enforce that the team develop classes and components that properly cleanup after themselves.

这篇关于哪些操作系统在程序退出时不会释放内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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