public static void Collect(int generation, GCCollectionMode mode, bool blocking) { if (generation < 0) { throw new ArgumentOutOfRangeException("generation", SR.ArgumentOutOfRange_GenericPositive); } if ((mode < GCCollectionMode.Default) || (mode > GCCollectionMode.Optimized)) { throw new ArgumentOutOfRangeException("mode", SR.ArgumentOutOfRange_Enum); } int iInternalModes = 0; if (mode == GCCollectionMode.Optimized) { iInternalModes |= (int)InternalGCCollectionMode.Optimized; } if (blocking) { iInternalModes |= (int)InternalGCCollectionMode.Blocking; } else { iInternalModes |= (int)InternalGCCollectionMode.NonBlocking; } RuntimeImports.RhCollect(generation, (InternalGCCollectionMode)iInternalModes); }
public static void Collect(int generation, GCCollectionMode mode, bool blocking) { if (generation < 0) { throw new ArgumentOutOfRangeException("generation", SR.ArgumentOutOfRange_GenericPositive); } if ((mode < GCCollectionMode.Default) || (mode > GCCollectionMode.Optimized)) { throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_Enum); } int iInternalModes = 0; if (mode == GCCollectionMode.Optimized) { iInternalModes |= (int)InternalGCCollectionMode.Optimized; } if (blocking) { iInternalModes |= (int)InternalGCCollectionMode.Blocking; } else { iInternalModes |= (int)InternalGCCollectionMode.NonBlocking; } RuntimeImports.RhCollect(generation, (InternalGCCollectionMode)iInternalModes); }
private void HandleForceGC(string module, string[] args) { // Default is an full (gen2) but NON-forced GC. int gen = 2; GCCollectionMode mode = GCCollectionMode.Optimized; if (args.Length > 1) { // Any argument implies forced GC. mode = GCCollectionMode.Forced; switch (args[1].ToLower()) { case "now": case "*": gen = GC.MaxGeneration; break; case "0": case "1": case "2": gen = Convert.ToInt32(args[1]); break; default: m_log.Warn("Usage: forcegc [ 0|1|2|*|now ]"); return; } } GC.Collect(gen, mode, true); }
[System.Security.SecuritySafeCritical] // auto-generated public static void Collect(int generation, GCCollectionMode mode, bool blocking) { if (generation < 0) { throw new ArgumentOutOfRangeException("generation", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); } if ((mode < GCCollectionMode.Default) || (mode > GCCollectionMode.Optimized)) { throw new ArgumentOutOfRangeException(Environment.GetResourceString("ArgumentOutOfRange_Enum")); } Contract.EndContractBlock(); int iInternalModes = 0; if (mode == GCCollectionMode.Optimized) { iInternalModes |= (int)InternalGCCollectionMode.Optimized; } if (blocking) { iInternalModes |= (int)InternalGCCollectionMode.Blocking; } else { iInternalModes |= (int)InternalGCCollectionMode.NonBlocking; } _Collect(generation, iInternalModes); }
public static void Collect(int generation, GCCollectionMode mode, bool blocking, bool compacting) { if (generation < 0) { throw new ArgumentOutOfRangeException("generation", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); } if (mode < GCCollectionMode.Default || mode > GCCollectionMode.Optimized) { throw new ArgumentOutOfRangeException(Environment.GetResourceString("ArgumentOutOfRange_Enum")); } int mode1 = 0; if (mode == GCCollectionMode.Optimized) { mode1 |= 4; } if (compacting) { mode1 |= 8; } if (blocking) { mode1 |= 2; } else if (!compacting) { mode1 |= 1; } GC._Collect(generation, mode1); }
// Perform garbage collection on a range of generations with the given // collection mode public static void Collect(int generation, GCCollectionMode mode) { if (generation != 0) { throw new ArgumentOutOfRangeException ("generation", _("ArgRange_GCGeneration")); } CollectInternal(0); }
public static void Collect(int generation, GCCollectionMode mode) { if (generation < 0) { throw new ArgumentOutOfRangeException("generation", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); } if ((mode < GCCollectionMode.Default) || (mode > GCCollectionMode.Optimized)) { throw new ArgumentOutOfRangeException(Environment.GetResourceString("ArgumentOutOfRange_Enum")); } nativeCollectGeneration(generation, (int)mode); }
public static void Collect(int generation, GCCollectionMode mode) { if (generation < 0) { throw new ArgumentOutOfRangeException("generation", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); } if ((mode < GCCollectionMode.Default) || (mode > GCCollectionMode.Optimized)) { throw new ArgumentOutOfRangeException(Environment.GetResourceString("ArgumentOutOfRange_Enum")); } nativeCollectGeneration(generation, (int) mode); }
public static void Collect(int generation, GCCollectionMode mode, bool blocking, bool compacting) { if (generation < 0) { throw new ArgumentOutOfRangeException(nameof(generation), SR.ArgumentOutOfRange_GenericPositive); } if ((mode < GCCollectionMode.Default) || (mode > GCCollectionMode.Aggressive)) { throw new ArgumentOutOfRangeException(nameof(mode), SR.ArgumentOutOfRange_Enum); } int iInternalModes = 0; if (mode == GCCollectionMode.Optimized) { iInternalModes |= (int)InternalGCCollectionMode.Optimized; } else if (mode == GCCollectionMode.Aggressive) { iInternalModes |= (int)InternalGCCollectionMode.Aggressive; if (generation != MaxGeneration) { throw new ArgumentException(SR.Argument_AggressiveGCRequiresMaxGeneration, nameof(generation)); } if (!blocking) { throw new ArgumentException(SR.Argument_AggressiveGCRequiresBlocking, nameof(blocking)); } if (!compacting) { throw new ArgumentException(SR.Argument_AggressiveGCRequiresCompacting, nameof(compacting)); } } if (compacting) { iInternalModes |= (int)InternalGCCollectionMode.Compacting; } if (blocking) { iInternalModes |= (int)InternalGCCollectionMode.Blocking; } else if (!compacting) { iInternalModes |= (int)InternalGCCollectionMode.NonBlocking; } _Collect(generation, iInternalModes); }
public static void Collect_Int_GCCollectionMode(GCCollectionMode mode) { for (int gen = 0; gen <= 2; gen++) { var b = new byte[1024 * 1024 * 10]; int oldCollectionCount = GC.CollectionCount(gen); b = null; GC.Collect(gen, GCCollectionMode.Default); Assert.True(GC.CollectionCount(gen) > oldCollectionCount); } }
private static void VerifyCollectionCount(GCCollectionMode mode) { for (int gen = 0; gen <= 2; gen++) { byte[] b = new byte[1024 * 1024 * 10]; int oldCollectionCount = GC.CollectionCount(gen); b = null; GC.Collect(gen, GCCollectionMode.Default); Assert.True(GC.CollectionCount(gen) > oldCollectionCount); } }
public static void Collect_Int_GCCollectionMode(GCCollectionMode mode) { for (int gen = 0; gen <= 2; gen++) { var b = new byte[1024 * 1024 * 10]; int oldCollectionCount = GC.CollectionCount(gen); b = null; GC.Collect(gen, mode); Assert.True(GC.CollectionCount(gen) > oldCollectionCount); } }
public static void Collect(int generation, GCCollectionMode mode, bool blocking, bool compacting) { if (generation < 0) { throw new ArgumentOutOfRangeException(nameof(generation), "generation", SR.ArgumentOutOfRange_GenericPositive); } if ((mode < GCCollectionMode.Default) || (mode > GCCollectionMode.Optimized)) { throw new ArgumentOutOfRangeException(nameof(mode), SR.ArgumentOutOfRange_Enum); } InternalCollect(generation); }
public static void Collect(int generation, GCCollectionMode mode, bool blocking, bool compacting) { if (generation < 0) { throw new ArgumentOutOfRangeException(nameof(generation), SR.ArgumentOutOfRange_GenericPositive); } if ((mode < GCCollectionMode.Default) || (mode > GCCollectionMode.Optimized)) { throw new ArgumentOutOfRangeException(nameof(mode), SR.ArgumentOutOfRange_Enum); } Contract.EndContractBlock(); int iInternalModes = 0; if (mode == GCCollectionMode.Optimized) { iInternalModes |= (int)InternalGCCollectionMode.Optimized; } if (compacting) { iInternalModes |= (int)InternalGCCollectionMode.Compacting; } if (blocking) { iInternalModes |= (int)InternalGCCollectionMode.Blocking; } else if (!compacting) { iInternalModes |= (int)InternalGCCollectionMode.NonBlocking; } _Collect(generation, iInternalModes); }
private static bool CollectGarbageInternal(bool compactLoh, Action afterCollect, bool forceByUser, int maxGeneration, GCCollectionMode gcCollectionMode, bool waitForPendingFinalizers) { if (!ShouldCollectNow() && !forceByUser) { return(false); } GcCollectLock.EnterWriteLock(); try { ReleaseMemoryBeforeGC(); memoryBeforeLastForcedGC = GC.GetTotalMemory(false); if (compactLoh) { SetCompactLog.Value(); } GC.Collect(maxGeneration, gcCollectionMode); if (afterCollect != null) { afterCollect(); } if (waitForPendingFinalizers) { GC.WaitForPendingFinalizers(); } } finally { GcCollectLock.ExitWriteLock(); } memoryAfterLastForcedGC = GC.GetTotalMemory(false); memoryDifferenceLastGc = DifferenceAsDecimalPercents(MemoryBeforeLastForcedGC, MemoryAfterLastForcedGC); log.Info("Finished GC, before was {0:#,#}kb, after is {1:#,#}kb", MemoryBeforeLastForcedGC, MemoryAfterLastForcedGC); // -> reset last time, increase delay threshold and disallow GC (too early!) lastForcedGCTime = SystemTime.UtcNow; var old = delayBetweenGCInMinutes; if (memoryDifferenceLastGc < 0.1) { delayBetweenGCInMinutes = Math.Max(5 + delayBetweenGCInMinutes, MaxDelayBetweenGCInMinutes); if (old != delayBetweenGCInMinutes) { if (log.IsDebugEnabled) { log.Debug("Increasing delay for forced GC (not enough memory released, so we need to back off). " + "New interval between GCs will be {0} minutes", delayBetweenGCInMinutes); } } } else { if (old != delayBetweenGCInMinutes) { if (log.IsDebugEnabled) { log.Debug("Resetting delay for forced GC (enough memory was released to make it useful, so we don't need to back off). " + "New interval between GCs will be {0} minutes", delayBetweenGCInMinutes); } } delayBetweenGCInMinutes = DefaultDelayBetweenGCInMinutes; } return(true); }
public static void Collect(int generation, GCCollectionMode mode, bool blocking) { Collect(generation); }
public static void Collect(int generation, GCCollectionMode mode) { Collect(generation); }
private static bool CollectGarbageInternal(bool compactLoh, Action afterCollect, bool forceByUser, int maxGeneration, GCCollectionMode gcCollectionMode, bool waitForPendingFinalizers) { if (!ShouldCollectNow() && !forceByUser) return false; GcCollectLock.EnterWriteLock(); try { ReleaseMemoryBeforeGC(); memoryBeforeLastForcedGC = GC.GetTotalMemory(false); if (compactLoh) SetCompactLog.Value(); GC.Collect(maxGeneration, gcCollectionMode); if (afterCollect != null) afterCollect(); if (waitForPendingFinalizers) GC.WaitForPendingFinalizers(); } finally { GcCollectLock.ExitWriteLock(); } memoryAfterLastForcedGC = GC.GetTotalMemory(false); memoryDifferenceLastGc = DifferenceAsDecimalPercents(MemoryBeforeLastForcedGC, MemoryAfterLastForcedGC); log.Info("Finished GC, before was {0:#,#}kb, after is {1:#,#}kb", MemoryBeforeLastForcedGC, MemoryAfterLastForcedGC); // -> reset last time, increase delay threshold and disallow GC (too early!) lastForcedGCTime = SystemTime.UtcNow; var old = delayBetweenGCInMinutes; if (memoryDifferenceLastGc < 0.1) { delayBetweenGCInMinutes = Math.Max(5 + delayBetweenGCInMinutes, MaxDelayBetweenGCInMinutes); if (old != delayBetweenGCInMinutes) { log.Debug("Increasing delay for forced GC (not enough memory released, so we need to back off). " + "New interval between GCs will be {0} minutes", delayBetweenGCInMinutes); } } else { if (old != delayBetweenGCInMinutes) { log.Debug("Resetting delay for forced GC (enough memory was released to make it useful, so we don't need to back off). " + "New interval between GCs will be {0} minutes", delayBetweenGCInMinutes); } delayBetweenGCInMinutes = DefaultDelayBetweenGCInMinutes; } return true; }
public static TimeSpan StopTime(GCCollectionMode _mode, bool _block, int _generation) { CreateObjects(); Timer.Start(); GC.Collect(_generation, _mode, _block); Timer.Stop(); var time = Timer.Elapsed; Timer.Reset(); return time; }
public static bool CollectGarbage(int generation, GCCollectionMode collectionMode = GCCollectionMode.Default, bool forceByUser = false) { return CollectGarbageInternal(false, null, forceByUser, generation, collectionMode, false); }
public static void CollectGarbage(int generation, GCCollectionMode collectionMode = GCCollectionMode.Default) { GC.Collect(generation, collectionMode); }
public static void Collect(int generation, GCCollectionMode mode) { GC.Collect(generation, mode, true); }
public static void Collect(int generation, GCCollectionMode mode, bool blocking) { throw new NotImplementedException(); }
public static bool CollectGarbage(int generation, GCCollectionMode collectionMode = GCCollectionMode.Default, bool forceByUser = false) { return(CollectGarbageInternal(false, null, forceByUser, generation, collectionMode, false)); }
public static void Collection_InvalidCollectionMode_ThrowsArgumentOutOfRangeException(GCCollectionMode mode) { AssertExtensions.Throws <ArgumentOutOfRangeException>("mode", "Enum value was out of legal range.", () => GC.Collect(2, mode)); AssertExtensions.Throws <ArgumentOutOfRangeException>("mode", "Enum value was out of legal range.", () => GC.Collect(2, mode, false)); }
public static void Collect(int generation, GCCollectionMode mode) { }
public static long MeasureMilisElapsed(int generation, GCCollectionMode mode, bool blocking) { var stringArray = new Object[10000]; for (int i = 0; i < 10000; i++) { //stringArray[i] = new string[100]; //small objects stringArray[i] = new string[10000]; // big objects } stringArray = null; stopWatch.Start(); GC.Collect(generation, mode, blocking); stopWatch.Stop(); var elapsed = stopWatch.ElapsedMilliseconds; stopWatch.Reset(); return elapsed; }
public static void Collect(int generation, GCCollectionMode mode) { throw new Exception("not impl"); }
public static void CollectGarbage(int generation, GCCollectionMode collectionMode = GCCollectionMode.Default) { ReleaseMemoryBeforeGC(); GC.Collect(generation, collectionMode); }
public static void Collect(int generation, GCCollectionMode mode, bool blocking, bool compacting) { throw new Exception("not impl"); }
[System.Security.SecuritySafeCritical] // auto-generated public static void Collect(int generation, GCCollectionMode mode) { Collect(generation, mode, true); }
[System.Security.SecuritySafeCritical] // auto-generated public static void Collect(int generation, GCCollectionMode mode, bool blocking) { Collect(generation, mode, blocking, false); }
public static void Collect(int generation, GCCollectionMode mode, bool blocking) { GC.Collect(generation, mode, blocking, false); }
[System.Security.SecuritySafeCritical] // auto-generated public static void Collect(int generation, GCCollectionMode mode, bool blocking, bool compacting) { if (generation<0) { throw new ArgumentOutOfRangeException("generation", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); } if ((mode < GCCollectionMode.Default) || (mode > GCCollectionMode.Optimized)) { throw new ArgumentOutOfRangeException(Environment.GetResourceString("ArgumentOutOfRange_Enum")); } Contract.EndContractBlock(); int iInternalModes = 0; if (mode == GCCollectionMode.Optimized) { iInternalModes |= (int)InternalGCCollectionMode.Optimized; } if (compacting) iInternalModes |= (int)InternalGCCollectionMode.Compacting; if (blocking) { iInternalModes |= (int)InternalGCCollectionMode.Blocking; } else if (!compacting) { iInternalModes |= (int)InternalGCCollectionMode.NonBlocking; } _Collect(generation, iInternalModes); }
public static void Collect(int generation, GCCollectionMode mode, bool blocking) { throw new PlatformNotSupportedException(); }
public static void Collection_InvalidCollectionMode_ThrowsArgumentOutOfRangeException(GCCollectionMode mode) { AssertExtensions.Throws <ArgumentOutOfRangeException>("mode", null, () => GC.Collect(2, mode)); AssertExtensions.Throws <ArgumentOutOfRangeException>("mode", null, () => GC.Collect(2, mode, false)); }