What's the purpose of GC.SuppressFinalize(this) in Dispose() method?

后端 未结 5 385
北荒
北荒 2020-12-04 13:47

I have the following code:

public void Dispose()
{
    if (_instance != null)
    {
        _instance = null;
        // Call GC.SupressFinalize to take this         


        
5条回答
  •  盖世英雄少女心
    2020-12-04 13:52

    If your type implements a finalizer (~MyType() { }), it keeps the garbage collector from running it. Used when your finalizer takes care of unmanaged types, but the user has already called Dispose() (either explicitly or via a using() { } block), freeing those unmanaged types.

提交回复
热议问题