Is there a use case for not using "this" when calling GC.SuppressFinalize(this)?

c#, design-patterns, garbage-collection

Solution

According to MSDN:

http://msdn.microsoft.com/en-us/library/system.gc.suppressfinalize.aspx

It is in fact possible that your example: GC.SuppressFinalize(foo) will be used in certain scenarios, but not in the scenario of the common dispose pattern.

In example you might want to write some kind of dispose management pattern for many objects instead of implementing the common dispose pattern from within your object. another option is if you want an object to remain suppressed and later on maybe claim it? never done that.. but it's possible.

So possible yes.. likely to happen no - and probably never.

Problem

I was just implementing the Dispose pattern, and when I just typed the `GC.SuppressFinalize(this)` line, I was wondering if there is ever a use case for using something other than `this` as the parameter to the method. This is the typical pattern: ``` public void Dispose() { Dispose(true); GC.SuppressFinalize(this); // right here } ``` Does it ever make sense to call `GC.SuppressFinalize()` with something other than `this`? ``` public void Dispose() { Dispose(true); GC.SuppressFinalize(foo); // should this ever happen? } ```

Original source