I have recently encountered an issue that is related to code running in the Finalize method overload.
I am mostly aware of issues that are related to memory management/performance, but i am interested whether there are any guidelines for “which code should/shouldn’t go in a Finalize method” ?
For example:
- Do not throw exceptions from within a Finalize method.
- Code should execute quickly.
- Do not raise events (?)
- Etc…
The behaviour in my case was seen due to an event being raised that caused some exception.
So my question is — what guidelines must i follow (perhaps even enforce using some tools) regarding finalize methods?
Finalizing is ONLY for getting rid of unmanaged resources
From MSDN