会忽略了IDisposable导致内存泄漏? [英] Will ignoring IDisposable cause memory leaks?

查看:247
本文介绍了会忽略了IDisposable导致内存泄漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在评论的<一个href="http://stackoverflow.com/questions/6864461/does-this-implementation-of-the-entity-framework-leaks-memory/6865002#6865002">answer我写我们约了内存泄漏的讨论和的IDisposable 在这里我们并没有得出任何实际的结论。

In the comments to an answer I wrote we had a discussion about memory leaks and IDisposable where we didn't come to any real conclusion.

这是处理非托管资源类可能的工具的IDisposable 。如果忽略了这一点,无论呼叫处置和包装物的使用 - 将领先优势的非托管资源泄漏?还是会被正确地清理时,GC收集的对象吗?

A class that handles unmanaged resources likely implements IDisposable. If ignore that and neither call Dispose nor wraps the object in a using - will that lead to the unmanaged resource being leaked? Or will it be properly cleaned up when the GC collects the object?

我们可以假设类处理非托管资源有一个正确实施的IDisposable ,包括终结等。

We can assume that the class handling the unmanaged resource has a correct implementation of IDisposable, including finalizer etc.

推荐答案

这会不会导致的内存泄漏的。事实上,配置有绝对无关,与内存管理。

It will not cause a memory leak. In fact, Dispose has absolutely nothing to do with memory management.

这将创建一个资源泄漏的。虽然GC将通常它清理干净,这可能是太罕见且为时已晚。

It will create a resource-leak. And while the GC will usually clean it up, this could be too infrequent and too late.

的省略的Dispose(使用)可以减慢甚至死机你的应用程序。在文件资源或DB连接的情况下它会导致在其它应用中的问题。

Omitting Dispose (using) can slow down or even crash your App. In the case of file resources or Db connections it can even cause problems in other applications.

这篇关于会忽略了IDisposable导致内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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