/// <summary> /// Clear all non-essential RAM /// </summary> /// <returns>A Task object</returns> internal async Task ClearMemory() { _lastAutoOptimizeTime = DateTime.Now; _logController.AddLog(new ApplicationLog("Clearing RAM memory")); await Task.Run(async() => { try { UpdateRamUsage(); double oldUsage = _ramUsageHistory[_ramUsageHistory.Count - 1].TotalUsed; if (FillRam) { _ramOptimizer.FillRam(_info, FillRamMaxRuns); } if (EmptyWorkingSets) { _ramOptimizer.EmptyWorkingSetFunction(_processExceptionList); await Task.Delay(10000); } if (ClearFileSystemCache) { _ramOptimizer.ClearFileSystemCache(ClearStandbyCache); } if (InvokeGarbageCollector) { GC.Collect(); GC.WaitForPendingFinalizers(); } UpdateRamUsage(); double newUsage = _ramUsageHistory[_ramUsageHistory.Count - 1].TotalUsed; RamSavings = oldUsage - newUsage; } catch (Exception ex) { _logController.AddLog(new ErrorLog(ex.Message)); } }); if (ClearClipboard) { _ramOptimizer.ClearClipboard(); } RamClearingCompletedEvent?.Invoke(); _logController.AddLog(new ApplicationLog("Done clearing RAM memory")); }
/// <summary> /// Clear all non-essential RAM /// </summary> /// <returns>A Task</returns> internal async Task ClearMemory() { _lastAutoOptimizeTime = DateTime.Now; _logController.AddLog(new ApplicationLog("Clearing RAM memory")); await Task.Run(async() => { UpdateRamUsage(); double oldUsage = RamUsage; if (EmptyWorkingSets) { _ramOptimizer.EmptyWorkingSetFunction(_processExceptionList); await Task.Delay(10000); } if (ClearFileSystemCache) { _ramOptimizer.ClearFileSystemCache(ClearStandbyCache); } GC.Collect(); GC.WaitForPendingFinalizers(); UpdateRamUsage(); UpdateGuiStatisticsEvent.Invoke(); double newUsage = RamUsage; RamSavings = oldUsage - newUsage; }); if (ClearClipboard) { Clipboard.Clear(); } RamClearingCompletedEvcent.Invoke(); _logController.AddLog(new ApplicationLog("Done clearing RAM memory")); }