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

Posted by mr.b on Stack Overflow See other posts from Stack Overflow or by mr.b
Published on 2010-06-14T15:38:22Z Indexed on 2010/06/14 15:42 UTC
Read the original article Hit count: 315

I have code that looks like this:

/// <summary>
/// Dispose of the instance
/// </summary>
public void Dispose()
{
    if (_instance != null)
    {
        _instance = null;
        // Call GC.SupressFinalize to take this object off the finalization
        //  queue and prevent finalization code for this object from
        //  executing a second time.
        GC.SuppressFinalize(this);
    }
}

Although there is a comment that explains purpose of that GC-related call, I still don't understand why it's there.

Isn't object destined for garbage collection once all instances cease from existence (like, when used in using() block)?

What's the use case scenario where this would play important role?

Thanks!

© Stack Overflow or respective owner

Related posts about c#

Related posts about garbage-collection