public void Dispose() { Debug.WriteLine("Wrapper: " + WrapperGuid.ToString()); Debug.WriteLine(" Pre-dispose of: " + ID); var elementManager = ElementIDLifecycleManager <int> .GetInstance(); int remainingBindings = elementManager.UnRegisterAssociation(id, this); // Do not delete Revit owned elements if (remainingBindings == 0) { //Do the real dispose here WrappersTest.CleanedObjects.Add( new Tuple <Guid, int>(WrapperGuid, ID)); Debug.WriteLine(" Dispose of wrapper target: " + ID); } else { //This element has gone //but there was something else holding onto the Revit object so don't purge it id = -1; } }
/// <summary> /// Returns the LifecycleManager for the specific type /// WARNING: This is only a singleton for a given TypeArg /// </summary> /// <returns></returns> public static ElementIDLifecycleManager <T> GetInstance() { lock (singletonMutex) { if (manager == null) { manager = new ElementIDLifecycleManager <T>(); } return(manager); } }