internal IntPtr Remove(IntPtr handle) {
if( handle == IntPtr.Zero )
{
return handle;
}
int currentCount = 0;
lock(this) {
handleCount--;
#if DEBUG_HANDLECOLLECTOR
Debug.Assert(handles.Contains(handle));
handles.Remove(handle);
#endif
if (handleCount < 0) {
System.Diagnostics.Debug.Fail("Handle collector underflow for type '" + name + "'");
handleCount = 0;
}
currentCount = handleCount;
}
lock (internalSyncObject){
if (HandleCollector.HandleRemoved != null) {
HandleCollector.HandleRemoved(name, handle, currentCount);
}
}
return handle;
}
}