完成并处置 [英] finalize and dispose

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

问题描述

finalize和dispose有什么区别?

What is the difference between finalize and dispose?

推荐答案

来自第一个Google链接 [ ^ ]:

对象的用户调用Dispose()来表明他已完成此操作,从而使该对象可以释放其拥有的任何非托管资源.运行时将调用Finalize()来允许尚未调用Dispose()的对象执行相同的操作.但是

Dispose()以终结方式运行,但是不能保证当对象超出范围时(或实际上,如果程序在该对象被GCed之前结束了),将立即调用Finalize(),因此Dispose()通常是首选.
From first google link[^]:

Dispose() is called by the user of an object to indicate that he is finished with it, enabling that object to release any unmanaged resources it holds. Finalize() is called by the run-time to allow an object which has not had Dispose() called on it to do the same. However

Dispose() operates determinalistically, whereas there is no guarantee that Finalize() will be called immediately when an object goes out of scope - or indeed at all, if the program ends before that object is GCed - and as such Dispose() is generally preferred.


http://www.allinterview.com/showanswers/67809.html [^ ]

检查一下
http://www.allinterview.com/showanswers/67809.html[^]

Check this out


参阅这些


http://techphernalia.com/blog/what-is -the-difference-between-finalize-and-dispose-garbage-collection/ [ http://mstechexplore.wordpress.com/2011/03/27/dotnet-framework-difference-between-finalize-and-dispose-how-is -the-using-pattern-useful-what-is-program-database-pdb-day-27-of-30/ [ ^ ]

http: //stackoverflow.com/questions/752792/what-is-the-the-point-of-finalize-and-dispose-methods-in-net-see-details-before-a [ http://www.geekinterview.com/question_details/37506 [
Refer these


http://techphernalia.com/blog/what-is-the-difference-between-finalize-and-dispose-garbage-collection/[^]

http://mstechexplore.wordpress.com/2011/03/27/dotnet-framework-difference-between-finalize-and-dispose-how-is-the-using-pattern-useful-what-is-program-database-pdb-day-27-of-30/[^]

http://stackoverflow.com/questions/752792/what-is-the-point-of-finalize-and-dispose-methods-in-net-see-details-before-a[^]

http://www.geekinterview.com/question_details/37506[^]


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

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