Note that there are some explanatory texts on larger screens.

plurals
  1. POExceptions during Finalize(): what methodology are you using to detect garbage collector-time exceptions?
    primarykey
    data
    text
    <p>I am developing a pretty extensive system in .NET, which involves a lot of system programming. Most time, I'm using the IDisposable pattern to handle resource disposal, but sometimes this isn't applicable (or left out by mistake) and resource gets destroyed during Finalize(). This might happen in COM interop, or when destructor calls Dispose() and there is an exception inside of it.</p> <p>Basically: it is not always possible to clearly see and handle each scenario when finalizer might throw. And when it happens, the application will most certainly crash.</p> <p>The reason why I'm concerned with specifically this class of problems is that finalizers are not called by a thread that created or used an object, so it is almost impossible task to tie the exception to the context in which the object was created. All you are getting is some generic GC thread.</p> <p><strong>So, question to the public now</strong>: if you account for those kind of issues, what do you do to control them? Tag the objects? Use a 3rd party tool which allows tracking those issues?</p> <p>Also: is it possible to trigger some sort of global "Finalizer threw" event, to at least log that this very problem has happened?</p> <p><strong>EDIT1</strong>: Many thanks to everyone who submitted valuable input, I think I'm somewhat clearer now on what needs to be done. Last thing I would really like to get from this discussion is if somebody knows the methodology to trigger code on exception in finalizer (even if app crash is still inevitable), so that I could at least log it, without having to modify destructor of every class.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload