First, GC.SuppressFinalize(obj)
checks, whether the given reference is reference equal to the this-pointer of the directly calling method (see online help: "The obj parameter is required to be the caller of this method.")
- so any call other than GC.SuppressFinalize(this)
will throw an exception!
Second, calling GC.SuppressFinalize(this)
indicates the GC NOT to run finalization code (the instance is removed from the finalization queue). The shorter the finalization queue, the faster the garbage collector runs... but as all objects inherit a finalizer...
Third, calling GC.SuppressFinalize(this)
will effectively prevent any destructor from running. I personally consider destructors a code smell! Writing correct finalizer code is anything but trivial (remember, all references could have gone... (freed already)). Besides that, dealing with unmanaged resources should be done implementing IDisposable
correctly and calling Dispose()
BEFORE the object gets collected. Having a finalizer is only the last line of defense - when no one has called Dispose()
. Usually one should use constructs like using()
- which will take care of calling Dispose()
.
For a detailed explanation of the subject see Proper use of the IDisposable interface
So - make the call at all - and if - where to place the call?
Make the call, if You don't handle unmanaged resources and therefore have no destructor. Common place is inside Dispose()
- but that's not required. Another favourite of mine is .ctor() - although the this
reference isn't fully constructed yet...
The ReSharper warning is a bit misleading here. It appears in two situations - when the argument is not the caller and when the call isn't in Dispose()
. In Your particular case, You should not make the call.