@@ -56,6 +56,10 @@ internal sealed class RamController
5656 /// The list of processes that should be excluded from memory optimisation
5757 /// </summary>
5858 private List < string > _processExceptionList ;
59+ /// <summary>
60+ /// An integer value representative of the percentage of RAM usage that should be reached before RAM optimisation should be called
61+ /// </summary>
62+ private double _autoOptimizeRamThreshold ;
5963 #endregion
6064
6165 #region Properties
@@ -87,7 +91,10 @@ internal sealed class RamController
8791 /// Property displaying whether the standby cache should be cleared or not during memory optimisation
8892 /// </summary>
8993 internal bool ClearStandbyCache { get ; set ; }
90-
94+ /// <summary>
95+ /// Property displaying whether automatic RAM optimisation should occur after a certain RAM usage percentage was reached
96+ /// </summary>
97+ internal bool AutoOptimizePercentage { get ; set ; }
9198 #endregion
9299
93100 /// <summary>
@@ -127,6 +134,12 @@ internal RamController(Dispatcher dispatcher, SfCircularGauge gauge, Label lblTo
127134 _logController . AddLog ( new ApplicationLog ( "Done initializing RamController" ) ) ;
128135 }
129136
137+ internal void SetAutoOptimizeThreshold ( double threshold )
138+ {
139+ if ( threshold < 25 ) throw new ArgumentException ( "Threshold is dangerously low!" ) ;
140+ _autoOptimizeRamThreshold = threshold ;
141+ }
142+
130143 /// <summary>
131144 /// Enable or disable automatic timed RAM optimisation
132145 /// </summary>
@@ -278,6 +291,12 @@ private void UpdateRamUsage()
278291 RamUsagePercentage = perc ;
279292 RamTotal = total ;
280293
294+ if ( RamUsagePercentage >= _autoOptimizeRamThreshold && AutoOptimizePercentage )
295+ {
296+ // This is dangerous. Needs to be fixed by checking last call time
297+ ClearMemory ( ) ;
298+ }
299+
281300 _logController . AddLog ( new ApplicationLog ( "Finished updating RAM usage" ) ) ;
282301 }
283302 }
0 commit comments