[Applications.Common] Fix OnLowMememory (#4470)
authorhjhun <36876573+hjhun@users.noreply.github.com>
Mon, 8 Aug 2022 22:26:13 +0000 (07:26 +0900)
committerGitHub <noreply@github.com>
Mon, 8 Aug 2022 22:26:13 +0000 (07:26 +0900)
This patch adds if conditions for registering the GC timer.
If the LowMemoryStatus of the LowMemoryEventArgs of the OnLowMemory is
SoftWarning or HardWarning, the timer will be registered.

Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/Tizen.Applications.Common/Tizen.Applications/CoreApplication.cs

index 26b8284..3b0a4ac 100644 (file)
@@ -219,14 +219,17 @@ namespace Tizen.Applications
         protected virtual void OnLowMemory(LowMemoryEventArgs e)
         {
             LowMemory?.Invoke(this, e);
-            double interval = new Random().Next(10 * 1000);
-            if (interval <= 0)
-                interval = 10 * 1000;
-
-            sTimer = new System.Timers.Timer(interval);
-            sTimer.Elapsed += OnTimedEvent;
-            sTimer.AutoReset = false;
-            sTimer.Enabled = true;
+            if (e.LowMemoryStatus == LowMemoryStatus.SoftWarning || e.LowMemoryStatus == LowMemoryStatus.HardWarning)
+            {
+                double interval = new Random().Next(10 * 1000);
+                if (interval <= 0)
+                    interval = 10 * 1000;
+
+                sTimer = new System.Timers.Timer(interval);
+                sTimer.Elapsed += OnTimedEvent;
+                sTimer.AutoReset = false;
+                sTimer.Enabled = true;
+            }
         }
 
         private static void OnTimedEvent(Object source, ElapsedEventArgs e)