You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You shouldn't declare finalizers unless you have to. You should only declare a finalizer if you have unmanaged resources to dispose. The CLR deals with finalizable objects differently, even if SuppressFinalize is called. More info on msdn
publicclassBus:IBus,IDisposable{publicvoidDispose(){
Dispose(true);
GC.SuppressFinalize(this);}// No need in finalizer~Bus(){
Dispose(false);}protectedvirtualvoidDispose(booldisposing){// Because no unmanaged resources hereif(!disposing)return;//...}}
The text was updated successfully, but these errors were encountered:
Thanks for the tip. I did a bunch more reading and it would appear that you're right - the recommended best practice is now to only use a finalizer if the class itself has unmanaged resources. Looks like I'm showing my age.
The "Basic IDisposable Pattern" here is different to the one here. Both from MSDN. I thought that CA1063 required a finalizer but that appears to not be the case, either.
You shouldn't declare finalizers unless you have to. You should only declare a finalizer if you have unmanaged resources to dispose. The CLR deals with finalizable objects differently, even if SuppressFinalize is called. More info on msdn
The text was updated successfully, but these errors were encountered: