IDisposable-是否需要托管资源? [英] IDisposable - Necessary with managed resources?

查看:63
本文介绍了IDisposable-是否需要托管资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常使用完整模式,但是我很好奇,因为我使用的是托管资源,例如SlimDX中的Texture类,我猜它已经实现了完整模式,真的需要吗?

目前,我在我的课程中使用了像这样的普通调用.

I normally use the full pattern, but, I''m curious, since I''m using managed resources, for example, the Texture class from SlimDX, which, I''m guessing already implements the full pattern, is it really needed?

For the moment I''m using plain calls like this in my classes.

public class MyClass // I'm not even using the IDisposable interface right now.
{
    Texture texture;

    public void Dispose() // I'm simply calling the underlying dispose methods on objects.
    {
        texture.Dispose();
    }
}



所以,是的,切换到完整模式是否有任何好处,或者我只是在浪费时间,并使我的代码变慢(这里和那里的一点点开销,等等,它累加了).完整模式?

谢谢. :)



So, yeah, are there any benefits to switching over to the full pattern, or am I just wasting time, and making my code slower(a little overhead here, and there, etc,. It adds up.) for no reason by using the full pattern?

Thanks. :)

推荐答案

IMO,如果SLimDX类已经实现了IDisposable ,并且您可以确定,则无需重新实现它. br/>
您可以在此处阅读有关确定性垃圾收集的更多信息 [
IMO, if the SLimDX class already implements IDisposable and you are sure about that, you don''t need to re-implement it.

You can read more about Deterministic Garbage Collection here[^]. Its one of the best articles I''ve come across.


这篇关于IDisposable-是否需要托管资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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