Basically, why is there a finalize destructor in C++/CLI. It seems like the GC, before collecting an object, checks to see if delete was called manually and, if not, call the finalizer. So, why can't the GC just call the normal destructor if delete was not called?
It is for the same reasons that you have a Dispose method and a Finalizer in C#. Roughly speaking, in C++/CLI, the destructor corresponds to Dispose and the Finalilzer corresponds to the finalizer. I say roughly speaking, because C++/CLI implements the Dispose pattern for you. That is, if delete is called (i.e. the destructor is called), it ensures that the finalizer is suppressed. If delete is not called, then the finalizer will run at GC time.
Just like in C#
If you have a finalizer, it is common (and good practice) for the destructor to call the finalizer.
These two links may help as well:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With