完成处置VS [英] Finalize vs Dispose

查看:194
本文介绍了完成处置VS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么有些人使用过的Dispose 方法敲定的方法?

Why do some people use the Finalize method over the Dispose method?

在什么情况下你会使用在的Dispose 方法敲定方法,反之亦然?

In what situations would you use the Finalize method over the Dispose method and vice versa?

推荐答案

其他人已经覆盖处置的区别敲定(顺便说一句的敲定方法仍然是所谓的语言规范析构函数),所以我就添加有关的场景有点其中敲定方法就派上用场了。

Others have already covered the difference between Dispose and Finalize (btw the Finalize method is still called a destructor in the language specification), so I'll just add a little about the scenarios where the Finalize method comes in handy.

某些类型的方式在这里很容易使用,并且在一个单一的动作予以处置封装一次性资源。一般用法往往是这样的。打开,读写,关闭(处置)。它非常适合与使用构造。

Some types encapsulates disposable resources in a manner where it is easy to use and dispose of them in a single action. The general usage is often like this. Open, read or write, close (Dispose). It fits very well with the using construct.

其他的都有点困难。因为它们是用于指示从一个线程到另一个 WaitEventHandles 用于实例不使用这样。那么问题就变成谁应该叫的Dispose 这些?作为一种安全措施类型,如这些实施敲定方法,这使得当实例不再由应用程序引用确保资源配置。

Others are a bit more difficult. WaitEventHandles for instances are not used like this as they are used to signal from one thread to another. The question then becomes who should call Dispose on these? As a safeguard types like these implement a Finalize method, which makes sure resources are disposed when the instance is no longer referenced by the application.

这篇关于完成处置VS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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