Search code examples
c#.netgarbage-collectionsuppressfinalize

In the TimedLock why is SuppressFinalize(tl.leakDetector) needed?


http://www.interact-sw.co.uk/iangblog/2004/04/26/yetmoretimedlocking

Why is this line needed?

System.GC.SuppressFinalize(tl.leakDetector);

I would have thought the finalizer should not be suppress to run the code that alerts to a left over monitor.

Obviously I'm looking at the debug version only.

Thanks


Solution

  • That code is working by making the finalizer for leakDetector cause a Debug.Fail, so you see problems in the debugger when that object is finalized.

    By putting the SuppressFinalize(..) call in the Dispose() method, it's causing that object to only trigger the Debug.Fail when Dispose is NOT called.