1
Vote

Device finalized after disposal

description

Working with DotSpatial.Positioning and Device.cs
 
After disposing of a Device even though GC.SuppressFinalize(this); is called in the dispose method the object gets finalized anyways and causes a null reference exception when calling CancelDetection(); because _detectionStartedWaitHandle and _detectionCompleteWaitHandle are null from disposal.
 
If I comment out GC.ReRegisterForFinalize(this); on line 706 in Device.cs, the object does not get finalized after already being disposed. GC.ReRegisterForFinalize(this); is never called after the disposal only before, during detection.

comments

theDeutschman wrote Jun 7, 2012 at 2:08 PM

Sorry, to be more clear the CancelDetection() method call that is causing the null reference exception is being called during the finalize from the GC because the method call is located in - protected virtual void Dispose(bool disposing) which gets called from the destructor.