public MyClass BuildClass() { var dispObj = new DisposableObj(); var retVal = new MyClass(dispObj); return(retVal); }
/// <summary> /// Called from within the EE and releases all the cached data for the __ComObject. /// </summary> internal void ReleaseAllData() { // Synchronize access to the map. lock (this) { // If the map hasn't been allocated, then there is nothing to do. if (m_ObjectToDataMap != null) { foreach (object o in m_ObjectToDataMap.Values) { // Note: the value could be an object[] // We are fine for now as object[] doesn't implement IDisposable nor derive from __ComObject // If the object implements IDisposable, then call Dispose on it. if (o is IDisposable DisposableObj) { DisposableObj.Dispose(); } // If the object is a derived from __ComObject, then call Marshal.ReleaseComObject on it. if (o is __ComObject ComObj) { Marshal.ReleaseComObject(ComObj); } } // Set the map to null to indicate it has been cleaned up. m_ObjectToDataMap = null; } } }
protected virtual void Dispose(bool Disposing) { if (Disposing && Obj != null) { if (Obj is IDisposable DisposableObj) { DisposableObj.Dispose(); } } }
private bool Delete(int Id) { object Obj = DomainObjects.Delete(Id); if (Obj is IDisposable DisposableObj) { DisposableObj.Dispose(); } return(Obj != null); }
public void Delete(int Id) { if (Objs.TryRemove(Id, out object Obj)) { if (Obj is IDisposable DisposableObj) { DisposableObj.Dispose(); } Ids.DeleteId(Id); } }
public void DeleteObject(int Id) { if (Objects.TryGetValue(Id, out object Obj)) { if (Obj is IDisposable DisposableObj) { DisposableObj.Dispose(); } ObjIds.DeleteId(Id); Objects.Remove(Id); } }
public void Destroy() { lock (Table) { for (int Index = 0; Index < Size; Index++) { KHandleEntry Entry = Table[Index]; if (Entry.Obj != null) { if (Entry.Obj is IDisposable DisposableObj) { DisposableObj.Dispose(); } Entry.Obj = null; Entry.Next = NextFreeEntry; NextFreeEntry = Entry; } } } }