TinyIoC
TinyIoC copied to clipboard
Unnecessary SuppressFinalizes
Why do SafeDictionary and TinyIoCContainer both call GC.SuppressFinalize when neither have finalizers? 🤔
From https://github.com/NancyFx/Nancy/issues/2896
I'm really not sure, were you able to get to the bottom of this?
Either they used to have finalisers, they should have them and I forgot to add them, or its a mistake :)
You dont have to have a finalizer to gain benefit from GC.SuppressFinalize When you call it, the object is removed from the finalizer queue. With it not in the finalizer queue, theres no wasted performance of having the object on the queue, fetching from the queue, and the GC having to reflect and figure out there's no finalizer to run.
The generally accepted pattern is objects that implement IDisposable call this, since IDisposable objects will get thrown into the finalizer queue whereas objects without IDisposable, I believe get GC'd practically immediately.