private static void RunCollectionThread() { const int waitTimeMilliseconds = 10000; while (true) { try { lock (_syncLock) { if (_waitingClients == 0) { Monitor.Wait(_syncLock, waitTimeMilliseconds); } if (Platform.IsLogLevelEnabled(LogLevel.Debug)) { Platform.Log(LogLevel.Debug, "Adding {0} containers and removing {1} from large object container cache.", _containersToAdd.Count, _containersToRemove.Count); } foreach (ILargeObjectContainer container in _containersToRemove) { _containerCache.Remove(container); } foreach (ILargeObjectContainer container in _containersToAdd) { _containerCache.Add(container); } _containersToRemove.Clear(); _containersToAdd.Clear(); if (_waitingClients == 0 && _containerCache.IsEmpty) { Platform.Log(LogLevel.Debug, "Exiting collection thread, container cache is empty."); _containerCache.CleanupDeadItems(true); //updates the estimates _collectionThread = null; break; } } CodeClock clock = new CodeClock(); clock.Start(); _containerCache.CleanupDeadItems(true); clock.Stop(); PerformanceReportBroker.PublishReport("Memory", "CleanupDeadItems", clock.Seconds); _strategy.Collect(new MemoryCollectionArgs(_containerCache)); } catch (Exception e) { Platform.Log(LogLevel.Warn, e, "Unexpected error occurred while collecting large objects."); } finally { if (_collecting) { Platform.Log(LogLevel.Debug, "Memory management strategy failed to fire 'complete' event; firing to avoid deadlocks."); OnMemoryCollected(null, new MemoryCollectedEventArgs(0, 0, 0, TimeSpan.Zero, true)); } } } }
public void Reset() { _cache.CleanupDeadItems(false); _current = null; _realEnumerator.Reset(); }