File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -95,6 +95,10 @@ internal sealed class RamController
9595 /// Property displaying whether automatic RAM optimisation should occur after a certain RAM usage percentage was reached
9696 /// </summary>
9797 internal bool AutoOptimizePercentage { get ; set ; }
98+ /// <summary>
99+ /// The last time automatic RAM optimisation was called in terms of RAM percentage threshold settings
100+ /// </summary>
101+ private DateTime _lastAutoOptimizeTime ;
98102 #endregion
99103
100104 /// <summary>
@@ -251,6 +255,7 @@ private void OnTimedEvent(object source, ElapsedEventArgs e)
251255 /// <returns>Nothing</returns>
252256 internal async Task ClearMemory ( )
253257 {
258+ _lastAutoOptimizeTime = DateTime . Now ;
254259 _logController . AddLog ( new ApplicationLog ( "Clearing RAM memory" ) ) ;
255260
256261 await Task . Run ( async ( ) =>
@@ -297,8 +302,13 @@ private void UpdateRamUsage()
297302
298303 if ( RamUsagePercentage >= _autoOptimizeRamThreshold && AutoOptimizePercentage )
299304 {
300- // This is dangerous. Needs to be fixed by checking last call time
301- ClearMemory ( ) ;
305+ double diff = ( DateTime . Now - _lastAutoOptimizeTime ) . TotalSeconds ;
306+ if ( diff > 10 )
307+ {
308+ #pragma warning disable 4014
309+ ClearMemory ( ) ;
310+ #pragma warning restore 4014
311+ }
302312 }
303313
304314 _logController . AddLog ( new ApplicationLog ( "Finished updating RAM usage" ) ) ;
You can’t perform that action at this time.
0 commit comments