Esempio n. 1
0
 public void Collect(MemoryCollectionArgs collectionArgs)
 {
 }
Esempio n. 2
0
 /// <summary>
 /// Called by the <see cref="MemoryManager"/> to collect memory from
 /// <see cref="ILargeObjectContainer"/>s, if necessary.  See <see cref="MemoryManager"/> for more details.
 /// </summary>
 public abstract void Collect(MemoryCollectionArgs collectionArgs);
Esempio n. 3
0
        public override void Collect(MemoryCollectionArgs collectionArgs)
        {
            _largeObjectEnumerator = collectionArgs.LargeObjectContainers.GetEnumerator();

            _regenerationCost = RegenerationCost.Low;

            //TODO (Time Review): Use Environment.TickCount?
            _collectionStartTime     = DateTime.Now;
            _timeSinceLastCollection = _collectionStartTime - _lastCollectionTime;
            TimeSpan thirtySeconds = TimeSpan.FromSeconds(30);

            if (_timeSinceLastCollection < thirtySeconds)
            {
                Platform.Log(LogLevel.Debug, "Time since last collection is less than 30 seconds; adjusting to 30 seconds.");
                _timeSinceLastCollection = thirtySeconds;
            }

            _maxTimeSinceLastAccess          = _timeSinceLastCollection;
            _maxTimeSinceLastAccessDecrement = TimeSpan.FromSeconds(_timeSinceLastCollection.TotalSeconds / 3);

            _totalNumberOfCollections   = 0;
            _totalBytesCollected        = 0;
            _totalLargeObjectsCollected = 0;
            _totalContainersUnloaded    = 0;

            try
            {
                CodeClock clock = new CodeClock();
                clock.Start();

                Collect();

                clock.Stop();
                PerformanceReportBroker.PublishReport("Memory", "Collect", clock.Seconds);
            }
            catch (Exception e)
            {
                Platform.Log(LogLevel.Warn, e, "Default memory management strategy failed to collect.");
            }
            finally
            {
                DateTime collectionEndTime = DateTime.Now;
                if (_totalContainersUnloaded > 0)
                {
                    _lastCollectionTime = collectionEndTime;
                }

                _largeObjectEnumerator = null;

                TimeSpan totalElapsed = collectionEndTime - _collectionStartTime;

                MemoryCollectedEventArgs finalArgs = new MemoryCollectedEventArgs(
                    _totalContainersUnloaded, _totalLargeObjectsCollected, _totalBytesCollected, totalElapsed, true);

                if (_totalNumberOfCollections != 0 ||
                    _totalBytesCollected != 0 ||
                    _totalLargeObjectsCollected != 0 ||
                    _totalContainersUnloaded != 0)
                {
                    Platform.Log(LogLevel.Info,
                                 "Large object collection summary: freed {0} MB in {1} seconds and {2} iterations, Total Containers: {3}, Total Large Objects: {4}",
                                 _totalBytesCollected / (float)OneMegabyte,
                                 totalElapsed.TotalSeconds,
                                 _totalNumberOfCollections,
                                 _totalContainersUnloaded,
                                 _totalLargeObjectsCollected);
                }

                OnMemoryCollected(finalArgs);
            }
        }