Closed lukebakken closed 6 months ago
I don't know how common it is in the .NET ecosystem to forcefully close a connection (channel, etc) in Dispose
. I assume that close it in a destructor (or similar) would be even less evident?
@michaelklishin, Close
-like invocation in Dispose
is very common and recommended.
Finalizers (destructors) should be used as a last resource and handle only unmanaged resources, as it is not guaranteed that all managed objects the class was referencing are still "alive" at the time the finalizer is invoked.
Also, using a finalizer requires one more step from the GC and will leave them in memory longer. Not to mention badly implemented finalizers that can deadlock or take down a process.
The common practice is for the Dispose
method to suppress the execution of the finalizer when invoked.
For more information, refer to Cleaning up unmanaged resources and sub-sections.
Thanks for the input @michaelklishin and @paulomorgado
…l that is disposed.
Fixes #1086