Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnecessary SuppressFinalizes #122

Open
benaadams opened this issue May 23, 2018 · 3 comments
Open

Unnecessary SuppressFinalizes #122

benaadams opened this issue May 23, 2018 · 3 comments

Comments

@benaadams
Copy link

Why do SafeDictionary and TinyIoCContainer both call GC.SuppressFinalize when neither have finalizers? 🤔

From NancyFx/Nancy#2896

@niemyjski
Copy link
Collaborator

I'm really not sure, were you able to get to the bottom of this?

@grumpydev
Copy link
Owner

Either they used to have finalisers, they should have them and I forgot to add them, or its a mistake :)

@ericnewton76
Copy link

ericnewton76 commented Dec 28, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants