[Mono-dev] Finalizers in CriticalHandle

Dick Porter dporter at codicesoftware.com
Fri Jan 14 10:30:52 EST 2011


Hi all

I'm currently debugging an issue that appears to be caused by the
non-release of unmanaged resources in CriticalHandle.  I'm using the git
master branch.

In CriticalHandle.cs:

                [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
                ~CriticalHandle ()
                {
                        Dispose (false);
                }

                [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
                protected virtual void Dispose (bool disposing)
                {
                        if (_disposed)
                                return;

                        _disposed = true;
                        if (IsInvalid)
                                return;

                        if (disposing == true && !IsInvalid){
                                if (!ReleaseHandle ()) {
                                        GC.SuppressFinalize (this);
                                } else {
                                        // Failed in release...
                                }
                        }
                }


Unless I'm missing something, this looks to me that when the
CriticalHandle object is finalized, the unmanaged resources won't be
released: ReleaseHandle() isn't called.

Is this a bug?

- Dick




More information about the Mono-devel-list mailing list