终结器和析构函数,维基百科怎么说? [英] Finalizers and destructors, what's Wikipedia saying?

查看:94
本文介绍了终结器和析构函数,维基百科怎么说?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解,有两个阵营涉及这个问题-第一个阵营认为终结器是C#的析构函数。因此,他们认为这两件事是相同的。

As I understand there are two camps concerning this question - the first one thinks that finalizer is a destructor specific to C#. So they think that these two things are the same.

第二个阵营认为两者之间存在细微差异-用Wikipedia编写-术语析构函数通常用于意思是确定性地调用清除,而当垃圾收集器说运行它时,将运行 finalizer。

The second camp thinks that there's a slight difference - written in Wikipedia - "the term "destructor" is typically used to mean a deterministically-invoked cleanup, whereas a "finalizer" runs when the garbage collector says to run it."

但是让我为自己澄清一下。确定性调用清理?根据C#规范和msdn的规定,析构函数不能被调用(它们将被自动调用)。可以自动调用它们的唯一情况是由垃圾收集器。

But let me clarify something for myself. Deterministically-invoked cleanup? In C# specification and msdn it's written that destructors cannot be invoked(they are invoked automatically). The only case when they may be invoked automatically is by garbage collector.

因此,我认为确定性调用的清理与垃圾回收器之间没有任何区别。

So I don't see any difference between deterministically-invoked cleanup and the case with the garbage collector.

是否这样?

推荐答案

在C#中,终结器和析构函数是同一事物的不同名称。

In C# finalizer and destructor are different names for the same thing.

C#语言规范(1.6.7.6)实际上将它们称为析构函数。但是,由于名称析构函数很容易被误认为是C ++对应词(与C#中的析构函数完全不同),因此可以使用术语终结器代替。

The C# language specification (1.6.7.6) actually refers to these as Destructors. However, as the name destructor may easily be mistaken for the C++ counterpart(which is quite different from a destructor in C#) it makes sense to use the term finalizer instead.

这篇关于终结器和析构函数,维基百科怎么说?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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