I read the accepted answer to a similar question, part of the answer is:
when structs are passed as parameters, they get passed by value: they are copied. Now you've got two structs with the same internal fields, and they're both going to attempt to clean up the same object. One will happen first, and so code that is using the other one afterwards will start to fail mysteriously... and then its own cleanup will fail
Doesn't this same problem apply to Dispose()
? If structs can implement IDisposable
, what is the reasoning behind not allowing them to have finalizers?
If the whole point of a finalizer is to call Dispose(false)
in case the programmer forgot to call Dispose()
, and structs can have IDisposable.Dispose()
, then why disallow finalizers for structs but allow them for reference types?