Why use GC.SuppressFinalize() when there is no Finalizer?

本秂侑毒 提交于 2019-12-11 00:47:45

问题


As the question states, I just wanted to know, because I've been asked and I don't have a clue, is there any reason for this whatsoever?


回答1:


When a class does not define a Finalizer (destructor), a call to SuppressFinalize() on an instance of that class has no effect.

When you see it, it usually is a left-over of the full Disposable implementation. Just remove it or ignore it.




回答2:


The reason might be to prevent potential error if someone adds a finalizer later on and forgets to add GC.SuppressFinalize().



来源:https://stackoverflow.com/questions/19078536/why-use-gc-suppressfinalize-when-there-is-no-finalizer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!