What are finalisers for?

后端 未结 5 917
独厮守ぢ
独厮守ぢ 2021-01-17 23:16

I have been programming in .NET for four years (mostly C#) and I use IDiposable extensively, but I am yet to find a need for a finaliser. What are finalisers for?

5条回答
  •  不要未来只要你来
    2021-01-17 23:45

    Finalizers are for cleaning up resources if they were not disposed.

    IE, nothing enforces that you ever call Dispose(), but Finalizers are called automatically by the garbage collector.

    This functionality should not be relied upon, as there is no guarantee when (or if) garbage collection will get to your object.

提交回复
热议问题