本文介绍了在finalize方法中调用配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是面试问题之一...我们可以在finalize
方法中调用dispose
方法,因为finalize()
是由垃圾收集器自动调用的,所以我们在finalize
中可以全部使用dispose
吗? dispose
和finalize
之间有什么区别?
This is one of the interview questions... can we call dispose
method inside finalize
method because finalize()
is called automatically by the Garbage Collector, so can we all dispose
in finalize
.
What''s the difference between dispose
and finalize
?
推荐答案
Public Class ClsTesting
Implements IDisposable
Public Overloads Sub Dispose()Implements IDisposable.Dispose
' write ytour clean up code here
GC.SuppressFinalize(Me)
End Sub
Protected Overrides Sub Finalize()
Dispose()
End Sub
End Class
希望这可以对您有所帮助. :)
Hope this may help you. :)
这篇关于在finalize方法中调用配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!