操作系统;资源自动清理 [英] OS; resources automatically clean up

查看:118
本文介绍了操作系统;资源自动清理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从此答案开始:何时C ++终止处理正确的东西(TM)?

最好有一个在应用程序退出时由操作系统自动清除的是"和不是"资源列表.如果您可以指定操作系统/资源,并且最好是指向某些文档的链接(如果适用),则在您的答案中会很好.

It would be nice to have a list of resources that 'are' and 'are not' automatically cleaned up by the OS when an application quits. In your answer it would be nice if you can specify the OS/resource and preferably a link to some documentaiton (if appropriate).

显而易见的一个:

内存:是,将自动清除. 问题.有什么例外吗?

Memory: Yes automatically cleaned up. Question. Are there any exceptions?

推荐答案

在应用崩溃或退出而未显式释放它们的情况下,Windows无法清理一些晦涩的资源,主要是因为操作系统不知道它们是否不管有没有重要.

There are some obscure resources that Windows does not clean up when an app crashes or exits without explicitly releasing them, mostly because the OS doesn't know if they're important to leave around or not.

  1. 临时文件-正如其他人所提到的.
  2. 全局注册的WNDCLASS es(卸载DLL时,没有注册由DLL注册的窗口类.当DLL卸载时,DLL必须显式注销其类." ATOM s(相对有限的资源).
  3. 使用 RegisterWindowMessage .因为没有UnregisterWindowMessage,所以这些都是为了泄漏而设计的.
  4. 信号灯和事件在技术上没有泄漏,但是当拥有的应用程序消失而不发出信号时,其他进程可能会挂起.对于互斥对象则不是这样.如果拥有的应用程序消失了,则等待该Mutex的其他进程将被释放.
  5. 如果您不注销
  1. Temporary files -- as others have mentioned.
  2. Globally registered WNDCLASSes ("No window classes registered by a DLL are unregistered when the DLL is unloaded. A DLL must explicitly unregister its classes when it is unloaded." MSDN) If your global window class also has a class DC, then that DC will leak as well.
  3. Global ATOMs (a relatively limited resource).
  4. Window message IDs created with RegisterWindowMessage. These are designed to leak, since there's no UnregisterWindowMessage.
  5. Semaphores and Events aren't technically leaked, but when the owning application goes away without signalling them, then other processes can hang. This is not true for a Mutex. If the owning application goes away, other processes waiting on that Mutex are released.
  6. There may be some residual weirdness on Windows XP and earlier if you don't unregister a hot key before exiting. Other applications may be unable to register the same hot key.
  7. On Windows XP and earlier, it's not uncommon to have a zombie console window live on after a process crashes. (Specifically, a GUI application that also creates a console window.) It shows up on the task bar. All you can do is minimize, restore, or move the window.
  8. Buggy drivers can be aggravated by apps that don't explicitly release resources when they exit. Non-paged pool leaks are fairly common.
  9. Data copied to the clipboard. I guess that doesn't really count because it's owned by the OS at that point, not the application that put it there.
  10. Globally installed hooks aren't unloaded when the installing process crashes before removing the hook.

这篇关于操作系统;资源自动清理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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