4 ms·
> For example could it represent RAII with an imaginary destructor in C# reasonably well? Not going to comment on the rest of your post, but just in case you d
by josteink 10y ago
> For example could it represent RAII with an imaginary destructor in C# reasonably well?
Not going to comment on the rest of your post, but just in case you didn't know, there's no need for an imaginary destructor in C#, as it already has one.[1]
The reason it's not really much known (or used) is because of its indeterminstic GC-tied nature.
I think the only "valid" usage I've seen for it is as a fallback method for IDisposable objects which are not getting cleaned up as they should (and as a way of tracing that in debug-builds).
[1] https://msdn.microsoft.com/en-us/library/66x5fx1b.aspx https://msdn.microsoft.com/en-us/library/66x5fx1b.aspx
- vishbar 10y agoThe "canonical" implementation of IDisposable includes a finalizer. As you said, that's the only time I've seen it used. Adding finalizers to classes has performance implications as well as the CLR will add any object with a finalizer to the finalizer queue (hence the GC.SuppressFinalize(this) you always see in implementations of IDisposable).