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

Address CA1816: Call GC.SuppressFinalize correctly #60

Merged
merged 1 commit into from
Nov 20, 2023

Conversation

tmittet
Copy link
Contributor

@tmittet tmittet commented Nov 17, 2023

Not sure the potential issue actually applies to .Net Core. But this silences the warning.

@badcel
Copy link
Owner

badcel commented Nov 17, 2023

Ah this is a complex topic. See discussion here.

According to current docs no finalizer is needed if a SafeHandle is used.

In the docs of the warning it reads like if the class gets sealed the warning should go away, too? At least it would make sense because if there is no finalizer and there is no derived class there will never be another finalizer thus making suppressing the finalizer call obsolete. See here.

So the question would be if the Device class is meant to be overriden: I'm not sure about that. As long as the SafeHandle member is private instead of protected a derived class can't really extend the functionality. It could only add new features add a higher level but those could be added if composition would be used over inheritance, too.

On the other hand I don't know what should be extended here, even if the SafeHandle member would be protected, except missing bindings. And missing bindings can be fixed with an update of this library. Everything else should be possible if the type is sealed, too.

So I tend to think let's seek the class. As this is an api break a major version bump would be needed.

What are your thoughts on this?

@tmittet
Copy link
Contributor Author

tmittet commented Nov 17, 2023

I tend to make my disposable classes sealed, when I can, to avoid this warning. Inheritance is only useful in very rare cases and for this type I share your opinion, probably not useful at all :)

And then there's this: dotnet/csharpstandard#291

@tmittet
Copy link
Contributor Author

tmittet commented Nov 17, 2023

Thanks for the link to the discussion about Dispose and SafeHandles

@badcel
Copy link
Owner

badcel commented Nov 18, 2023

Can you squash your two commits into one?

@badcel badcel added this to the 1.0.0 milestone Nov 18, 2023
Not sure the potential issue actually applies to .Net Core. But this silences the warning.
@tmittet tmittet force-pushed the Address_CA1816_Call_GC_SuppressFinalize branch from f40f0a9 to f90c1ba Compare November 20, 2023 00:49
@tmittet
Copy link
Contributor Author

tmittet commented Nov 20, 2023

Can you squash your two commits into one?

Done. I really like the ability to squash on merge in GitHub though, that way you get a tidy commit log and keep the history of the PR/feature branch

@badcel
Copy link
Owner

badcel commented Nov 20, 2023

If I remember correctly it will be my commit which is authored by you if I squash it? As I'm not sure if a contributor likes this I prefer to merge it. In this way the timeline represents what happened even if it is not a straight timeline anymore.

Anyway, thank you for your contributions 🙏

@badcel badcel merged commit 9fe3792 into badcel:main Nov 20, 2023
3 checks passed
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

Successfully merging this pull request may close these issues.

2 participants