GC, OOM kill issue fix 94/125694/5
authordongsug.song <dongsug.song@samsung.com>
Tue, 18 Apr 2017 11:32:48 +0000 (20:32 +0900)
committerdongsug.song <dongsug.song@samsung.com>
Fri, 21 Apr 2017 06:30:58 +0000 (15:30 +0900)
Conflicts:
NUISamples/NUISamples/NUISamples.TizenTV/examples/Main.cs

Change-Id: I84b6b9363a0006eb0a33f4700c1052f38db7cbda
Signed-off-by: dongsug.song <dongsug.song@samsung.com>
NUISamples/NUISamples/NUISamples.TizenTV/NUISamples.TizenTV.csproj
NUISamples/NUISamples/NUISamples.TizenTV/examples/Main.cs
NUISamples/NUISamples/NUISamples.TizenTV/examples/gc-test.cs [new file with mode: 0755]
Tizen.NUI/src/internal/DisposeQueue.cs
Tizen.NUI/src/internal/EventThreadCallback.cs
Tizen.NUI/src/public/NUIApplication.cs

index 4769ce7..657f5d4 100755 (executable)
@@ -61,6 +61,7 @@
     <Compile Include="examples\date-picker-using-json.cs" />\r
     <Compile Include="examples\date-picker.cs" />\r
     <Compile Include="examples\flex-container.cs" />\r
+    <Compile Include="examples\gc-test.cs" />\r
     <Compile Include="examples\hello-test.cs" />\r
     <Compile Include="examples\hello-world.cs" />\r
     <Compile Include="examples\image-view.cs" />\r
index 46451ce..8af6814 100755 (executable)
@@ -14,7 +14,7 @@ namespace NUISamples.TizenTV.examples
         [STAThread]
         static void Main(string[] args)
         {
-            new ControlDashboard.Example().Run(args);                 //o
+            //new ControlDashboard.Example().Run(args);                 //o
             //new DatePickerTest.Example().Run(args);                   //o
             //new DatePickerUsingJson.Example().Run(args);              //o
             //new HelloTest.Example().Run(args);                        //o
@@ -34,6 +34,7 @@ namespace NUISamples.TizenTV.examples
             //new VisualsUsingCustomView.VisualsExample().Run(args);    //o
             //new FirstScreen.FirstScreenApp().Run(args);               //o
             //new PositionUsesAnchorPointTest.Example().Run(args);
+            new TizenVDUIApplication19.Program().Run(args);
         }
     }
 }
diff --git a/NUISamples/NUISamples/NUISamples.TizenTV/examples/gc-test.cs b/NUISamples/NUISamples/NUISamples.TizenTV/examples/gc-test.cs
new file mode 100755 (executable)
index 0000000..394754b
--- /dev/null
@@ -0,0 +1,119 @@
+using Tizen.Applications;
+
+using System.Collections.Generic;
+using System;
+
+namespace TizenVDUIApplication19
+{
+    using Tizen.NUI;
+
+    internal class Program : NUIApplication
+    {
+        private Timer myTimer;
+        private List<View> myViewList;
+        private const int numberOfObjects = 500;
+        private Random myRandom;
+
+        protected override void OnCreate()
+        {
+            base.OnCreate();
+
+            Stage.Instance.BackgroundColor = Color.White;
+
+            myViewList = new List<View>();
+
+            myRandom = new Random();
+
+            for (int i = 0; i < numberOfObjects; i++)
+            {
+                View v = new View();
+
+                float intensity = myRandom.Next(0, 255) / 255.0f;
+                v.BackgroundColor = new Color(intensity, intensity, intensity, 1);
+                v.Position = new Position(myRandom.Next(0, 1820), myRandom.Next(0, 980), 0);
+                v.AnchorPoint = AnchorPoint.TopLeft;
+                v.Size = new Size(100, 100, 0);
+
+                myViewList.Add(v);
+
+                Stage.Instance.GetDefaultLayer().Add(v);
+            }
+
+            myTimer = new Timer(1000);
+
+            myTimer.Tick += MyTimer_Tick;
+
+            myTimer.Start();
+        }
+
+        private bool MyTimer_Tick(object source, System.EventArgs e)
+        {
+            //Remove current Scene,
+            foreach (View v in myViewList)
+            {
+                Stage.Instance.GetDefaultLayer().Remove(v);
+            }
+
+            myViewList.Clear();
+
+            ////Add View
+
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+
+            for (int i = 0; i < numberOfObjects; i++)
+            {
+                View v = new View();
+
+                float intensity = myRandom.Next(0, 255) / 255.0f;
+                v.BackgroundColor = new Color(intensity, intensity, intensity, 1);
+                v.Position = new Position(myRandom.Next(0, 1820), myRandom.Next(0, 980), 0);
+                v.AnchorPoint = AnchorPoint.TopLeft;
+                v.Size = new Size(100, 100, 0);
+
+                myViewList.Add(v);
+
+                Stage.Instance.GetDefaultLayer().Add(v);
+            }
+
+            return true;
+        }
+
+        protected override void OnPause()
+        {
+            //This function is called when the window's visibility is changed from visible to invisible.
+            base.OnPause();
+        }
+
+        protected override void OnResume()
+        {
+            //This function is called when the window's visibility is changed from invisible to visible.
+            base.OnResume();
+        }
+
+        protected override void OnTerminate()
+        {
+            //This function is called when the app exit normally.
+            base.OnTerminate();
+        }
+
+        protected override void OnLowMemory(LowMemoryEventArgs e)
+        {
+            //This function is called when the system is low on memory.
+            base.OnLowMemory(e);
+        }
+
+        protected override void OnLocaleChanged(LocaleChangedEventArgs e)
+        {
+            //This function is called when the language is changed.
+            base.OnLocaleChanged(e);
+        }
+
+        private static void _Main(string[] args)
+        {
+            //Create an Application
+            Program myProgram = new Program();
+            myProgram.Run(args);
+        }
+    }
+}
\ No newline at end of file
index f3b2016..64bb3ab 100755 (executable)
@@ -18,10 +18,9 @@ namespace Tizen.NUI
         private static readonly DisposeQueue _disposableQueue = new DisposeQueue();
         private List<IDisposable> _disposables = new List<IDisposable>();
         private Object _listLock = new object();
-        /* temporary removal because of crash issue. this will be fixed later. 2017-04-04
         private EventThreadCallback _eventThreadCallback;
         private EventThreadCallback.CallbackDelegate _disposeQueueProcessDisposablesDelegate;
-        */
+
         private DisposeQueue()
         {
         }
@@ -37,10 +36,8 @@ namespace Tizen.NUI
 
         public void Initialize()
         {
-            /* temporary removal because of crash issue. this will be fixed later. 2017-04-04
             _disposeQueueProcessDisposablesDelegate = new EventThreadCallback.CallbackDelegate(ProcessDisposables);
             _eventThreadCallback = new EventThreadCallback(_disposeQueueProcessDisposablesDelegate);
-            */
         }
 
         public void Add(IDisposable disposable)
@@ -50,9 +47,10 @@ namespace Tizen.NUI
                 _disposables.Add(disposable);
             }
 
-            /* temporary removal because of crash issue. this will be fixed later. 2017-04-04
-            _eventThreadCallback.Trigger();
-            */
+            if (_eventThreadCallback != null)
+            {
+                _eventThreadCallback.Trigger();
+            }
         }
 
         private void ProcessDisposables()
index 18a25b7..2362fec 100755 (executable)
@@ -65,11 +65,14 @@ namespace Tizen.NUI
 
         public void Trigger()
         {
-            NDalicManualPINVOKE.EventThreadCallback_Trigger(swigCPtr);
+            if ((System.IntPtr)swigCPtr != global::System.IntPtr.Zero)
+            {
+                NDalicManualPINVOKE.EventThreadCallback_Trigger(swigCPtr);
+            }
+
             if (NDalicPINVOKE.SWIGPendingException.Pending)
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
-
     }
 
 }
index 58ec099..3b893d2 100755 (executable)
@@ -111,6 +111,10 @@ namespace Tizen.NUI
         /// </summary>
         protected override void OnPreCreate()
         {
+            // Initialize DisposeQueue Singleton class.
+            DisposeQueue disposeQ = DisposeQueue.Instance;
+            Tizen.Log.Debug("NUI", "##### 1) DisposeQueue.Instance.Initialize()!");
+
             switch (_appMode)
             {
                 case AppMode.Default:
@@ -128,6 +132,10 @@ namespace Tizen.NUI
             _applicationExt = new ApplicationExtensions(_application);
             _applicationExt.Init();
 
+            // This is also required to create DisposeQueue on main thread.
+            disposeQ.Initialize();
+            Tizen.Log.Debug("NUI", "##### 2) DisposeQueue.Instance.Initialize()!");
+
             _stage = Stage.Instance;
             _stage.SetBackgroundColor(Color.White);
             LOG("OnPreCreate() is called!");