예제 #1
0
        public void RemoveReference(object reference)
        {
            if (reference == null)
            {
                throw new ArgumentNullException(nameof(reference));
            }

            SyncSource syncObject = _referencePool.GetSyncObject(reference);

            if (syncObject == null)
            {
                throw new InvalidOperationException($"{nameof(reference)} is not tracked");
            }

            if (--syncObject.ReferenceCount <= 0)
            {
                bool isAlreadySynchronized = _addedSyncSourceObjects.Remove(syncObject) == false;
                if (isAlreadySynchronized)
                {
                    // Clients do not need to be notified of deleted objects
                    // that have not yet been synchronized.
                    _removedSyncSourceObjects.Add(syncObject);
                }
                // If reference is not tracked by targets remove immediately
                else
                {
                    RemoveSyncSourceObject(syncObject);
                }
            }
        }