[NUI] Add _parent in Container (#177) 5.0.0.14291
authordongsug-song <35130733+dongsug-song@users.noreply.github.com>
Fri, 23 Mar 2018 08:34:10 +0000 (17:34 +0900)
committerGitHub <noreply@github.com>
Fri, 23 Mar 2018 08:34:10 +0000 (17:34 +0900)
* [NUI] Add _parent in Container

* [NUI] Change the way of getting native handle and making c# object

16 files changed:
packaging/version.txt
src/Tizen.NUI/src/internal/Application.cs
src/Tizen.NUI/src/internal/DaliEnumConstants.cs
src/Tizen.NUI/src/internal/FrameBuffer.cs
src/Tizen.NUI/src/internal/ManualPINVOKE.cs
src/Tizen.NUI/src/internal/NDalicPINVOKE.cs
src/Tizen.NUI/src/internal/Registry.cs
src/Tizen.NUI/src/internal/VersionCheck.cs
src/Tizen.NUI/src/internal/ViewWrapperImpl.cs
src/Tizen.NUI/src/public/BaseComponents/TableView.cs
src/Tizen.NUI/src/public/BaseComponents/View.cs
src/Tizen.NUI/src/public/Container.cs
src/Tizen.NUI/src/public/FocusManager.cs
src/Tizen.NUI/src/public/Layer.cs
src/Tizen.NUI/src/public/UIComponents/Popup.cs
src/Tizen.NUI/src/public/Window.cs

index 94fc546..e370439 100755 (executable)
@@ -7,4 +7,4 @@ NUGET_VERSION=5.0.0-preview1-99999
 INTERNAL_NUGET_VERSION=5.0.0.999
 
 # RPM Version Suffix
-RPM_VERSION_SUFFIX=nui83
+RPM_VERSION_SUFFIX=nui500
index 5684c4e..02e66a0 100755 (executable)
@@ -515,6 +515,11 @@ namespace Tizen.NUI
         // Callback for Application InitSignal
         private void OnApplicationInit(IntPtr data)
         {
+            if (Version.DaliVersionMatchWithNUI() == false)
+            {
+                Tizen.Log.Fatal("NUI", "Dali and NUI are version mismatched!");
+            }
+
             // Initialize DisposeQueue Singleton class. This is also required to create DisposeQueue on main thread.
             DisposeQueue.Instance.Initialize();
 
index be815da..cf03bc7 100755 (executable)
@@ -201,7 +201,7 @@ namespace Tizen.NUI
 
 internal class NUILog
 {
-    [Conditional("DEBUG_ON")]
+    //[Conditional("DEBUG_ON")]
     public static void Debug(string msg,
         [CallerLineNumber] int lineNum = 0,
         [CallerMemberName] string caller = null,
index 085bdb1..97c91d9 100755 (executable)
@@ -99,12 +99,8 @@ namespace Tizen.NUI
 
         public Texture GetColorTexture()
         {
-            //to fix memory leak issue, match the handle count with native side.
-            global::System.IntPtr cPtr = NDalicPINVOKE.FrameBuffer_GetColorTexture(swigCPtr);
-            HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
-            Texture ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as Texture;
-            NDalicPINVOKE.delete_BaseHandle(CPtr);
-            CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            Texture texture = new Texture(NDalicPINVOKE.FrameBuffer_GetColorTexture(swigCPtr), true);
+            Texture ret = Registry.GetManagedBaseHandleFromNativePtr(texture) as Texture;
 
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
index 71945bd..f4bc28d 100755 (executable)
@@ -1742,5 +1742,8 @@ namespace Tizen.NUI
         [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint = "CSharp_ImageView_IMAGE_VISUAL_ACTION_STOP_get")]
         public static extern int ImageView_IMAGE_VISUAL_ACTION_STOP_get();
 
+        [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint = "CSharp_NUI_InternalAPIVersionCheck")]
+        public static extern bool InternalAPIVersionCheck(ref int ver1, ref int ver2, ref int ver3);
+
     }
 }
index 319265e..c80ae80 100755 (executable)
@@ -11514,5 +11514,5 @@ class NDalicPINVOKE {
   public static extern uint GetMaxTextureSize();
 
     }
-}
 
+}
index fc254b8..8f1f92f 100755 (executable)
@@ -16,7 +16,7 @@
  */
 
 using System;
-using System.Collections.Generic;
+using System.Collections.Concurrent;
 using System.Threading;
 
 namespace Tizen.NUI
@@ -41,11 +41,11 @@ namespace Tizen.NUI
         /// Given a C++ object, the dictionary allows us to find which C# object it belongs to.
         /// By keeping the weak reference only, it will allow the object to be garbage collected.
         /// </summary>
-        private Dictionary<IntPtr, WeakReference> _controlMap;
+        private ConcurrentDictionary<IntPtr, WeakReference> _controlMap;
 
         private Registry()
         {
-            _controlMap = new Dictionary<IntPtr, WeakReference>();
+            _controlMap = new ConcurrentDictionary<IntPtr, WeakReference>();
         }
 
 
@@ -55,16 +55,15 @@ namespace Tizen.NUI
         /// <param name="baseHandle">The instance of BaseHandle (C# base class).</param>
         internal static void Register(BaseHandle baseHandle)
         {
-
             // We store a pointer to the RefObject for the control
             RefObject refObj = baseHandle.GetObjectPtr();
             IntPtr refCptr = (IntPtr)RefObject.getCPtr(refObj);
 
-            //NUILog.Debug("Storing ref object cptr in control map Hex: {0:X}" + refCptr);
+            RegistryCurrentThreadCheck();
 
-            if (!Instance._controlMap.ContainsKey(refCptr))
+            if(Instance._controlMap.TryAdd(refCptr, new WeakReference(baseHandle, false)) != true)
             {
-                Instance._controlMap.Add(refCptr, new WeakReference(baseHandle, false));
+                NUILog.Debug("refCptr is already exist! OR something wrong!");
             }
 
             return;
@@ -79,9 +78,12 @@ namespace Tizen.NUI
             RefObject refObj = baseHandle.GetObjectPtr();
             IntPtr refCptr = (IntPtr)RefObject.getCPtr(refObj);
 
-            if (Instance._controlMap.ContainsKey(refCptr))
+            RegistryCurrentThreadCheck();
+
+            WeakReference removeTarget;
+            if(Instance._controlMap.TryRemove(refCptr, out removeTarget) != true)
             {
-                Instance._controlMap.Remove(refCptr);
+                NUILog.Debug("something wrong when removing refCptr!");
             }
 
             return;
@@ -92,42 +94,42 @@ namespace Tizen.NUI
             RefObject refObj = baseHandle.GetObjectPtr();
             IntPtr refObjectPtr = (IntPtr)RefObject.getCPtr(refObj);
 
-            if (refObjectPtr != null)
-            {
                 // we store a dictionary of ref-obects (C++ land) to managed obects (C# land)
                 return GetManagedBaseHandleFromRefObject(refObjectPtr);
             }
-            else
-            {
-                NUILog.Error("NUI Registry RefObjectPtr is NULL!");
-                return null;
-            }
-        }
 
         internal static BaseHandle GetManagedBaseHandleFromNativePtr(IntPtr cPtr)
         {
             IntPtr refObjectPtr = NDalicPINVOKE.GetRefObjectPtr(cPtr);
 
-            if (refObjectPtr != null)
-            {
                 // we store a dictionary of ref-obects (C++ land) to managed obects (C# land)
                 return GetManagedBaseHandleFromRefObject(refObjectPtr);
             }
-            else
+
+        internal static BaseHandle GetManagedBaseHandleFromRefObject(IntPtr refObjectPtr)
+            {
+            if (refObjectPtr == global::System.IntPtr.Zero)
             {
-                NUILog.Error("NUI Registry RefObjectPtr is NULL!");
+                NUILog.Debug("Registry refObjectPtr is NULL! This means bind native object is NULL!");
                 return null;
             }
+            else
+            {
+                NUILog.Debug($"refObjectPtr=0x{refObjectPtr.ToInt64():X}");
         }
 
-        internal static BaseHandle GetManagedBaseHandleFromRefObject(IntPtr refObjectPtr)
-        {
+            RegistryCurrentThreadCheck();
+
             // we store a dictionary of ref-obects (C++ land) to managed obects (C# land)
             WeakReference weakReference;
 
             if (Instance._controlMap.TryGetValue(refObjectPtr, out weakReference))
             {
-                if(weakReference == null) { throw new System.InvalidOperationException("Error! NUI Registry weakReference should not be NULL!"); }
+                if(weakReference == null)
+                {
+                    throw new System.InvalidOperationException("Error! NUI Registry weakReference should not be NULL!");
+                }
+
                 BaseHandle ret = weakReference.Target as BaseHandle;
                 return ret;
             }
@@ -150,5 +152,22 @@ namespace Tizen.NUI
             }
         }
 
+        private static void RegistryCurrentThreadCheck()
+        {
+            if(savedApplicationThread == null)
+            {
+                Tizen.Log.Fatal("NUI", $"Error! maybe main thread is created by other process ");
+                return;
+            }
+            int currentId = Thread.CurrentThread.ManagedThreadId;
+            int mainThreadId = savedApplicationThread.ManagedThreadId;
+
+            if(currentId != mainThreadId)
+            {
+                Tizen.Log.Fatal("NUI", $"Error! current thread({currentId}) which is NOT main thread({mainThreadId}) utilizes NUI object!");
+            }
+        }
+
+
     }
 }
index 899f087..5c2d3fc 100755 (executable)
  */
 
 using System;
+using System.Diagnostics;
 
 namespace Tizen.NUI
 {
     //This version should be updated and synced for every Dali native release
     internal static class Version
     {
-        public const int daliVer1 = 1;
-        public const int daliVer2 = 2;
-        public const int daliVer3 = 83;
-        public const int nuiVer1 = 1;
-        public const int nuiVer2 = 2;
-        public const int nuiVer3 = 83;
-        public const string nuiRelease = "";
-
+        //dali_1.3.xx : NUI internal API version 500
+        public const int nuiAPIVer = 500;
+        public const int reservedVer1 = 0;
+        public const int reservedVer2 = 0;
 
         static internal bool DaliVersionMatchWithNUI()
         {
@@ -39,27 +36,39 @@ namespace Tizen.NUI
 
             try
             {
-                if (NDalicManualPINVOKE.NativeVersionCheck(ref ver1, ref ver2, ref ver3))
+                if (NDalicManualPINVOKE.InternalAPIVersionCheck(ref ver1, ref ver2, ref ver3) == true)
                 {
-                    if (ver1 != daliVer1 || ver2 != daliVer2 || ver3 != daliVer3)
+                    if (ver1 != nuiAPIVer)
                     {
-                        NUILog.Error($"Dali native version mismatch error! nui={ nuiVer1}.{ nuiVer2}.{ nuiVer3} but dali= { ver1 }.{ ver2}.{ ver3}");
-                        throw new System.InvalidOperationException($"Dali native version mismatch error! nui={ nuiVer1}.{ nuiVer2}.{ nuiVer3} but dali={ ver1 }.{ ver2}.{ ver3}");
+                        NUILog.Error($"NUI API version mismatch error! NUI API Version: ({nuiAPIVer}) but read version from native: ({ver1}.{ver2}.{ver3})");
+                        throw new System.InvalidOperationException($"NUI API version mismatch error! NUI API version should be ({nuiAPIVer}) but read version from native: ({ver1}.{ver2}.{ver3})");
                     }
                 }
                 else
                 {
-                    NUILog.Error($"Dali native version mismatch error! nui={ nuiVer1}.{ nuiVer2}.{ nuiVer3} but dali= { ver1 }.{ ver2}.{ ver3}");
-                    throw new System.InvalidOperationException($"Dali native version mismatch error! nui={ nuiVer1}.{ nuiVer2}.{ nuiVer3} but dali={ ver1 }.{ ver2}.{ ver3}");
+                    NUILog.Error($"NUI API version mismatch error! NUI API Version: ({nuiAPIVer}) but read version from native: ({ver1}.{ver2}.{ver3})");
+                    throw new System.InvalidOperationException($"NUI API version mismatch error! NUI API version should be ({nuiAPIVer}) but read version from native: ({ver1}.{ver2}.{ver3})");
                 }
             }
             catch (Exception)
             {
-                NUILog.Error($"Dali native version mismatch error! nui={ nuiVer1}.{ nuiVer2}.{ nuiVer3} but dali= { ver1 }.{ ver2}.{ ver3}");
-                throw new System.InvalidOperationException($"Dali native version mismatch error! nui={ nuiVer1}.{ nuiVer2}.{ nuiVer3} but dali={ ver1 }.{ ver2}.{ ver3}");
+                NUILog.Error($"NUI API version mismatch error! NUI API Version: ({nuiAPIVer}) but read version from native: ({ver1}.{ver2}.{ver3})");
+                throw new System.InvalidOperationException($"NUI API version mismatch error! NUI API version should be ({nuiAPIVer}) but read version from native: ({ver1}.{ver2}.{ver3})");
             }
-            NUILog.Debug($"version info: nui={ nuiVer1}.{ nuiVer2}.{ nuiVer3}, dali= { ver1 }.{ ver2}.{ ver3}");
+
+            PrintDaliNativeVersion();
             return true;
         }
+
+        //[Conditional("DEBUG_ON")]
+        static private void PrintDaliNativeVersion()
+        {
+            int ver1 = -1;
+            int ver2 = -1;
+            int ver3 = -1;
+
+            NDalicManualPINVOKE.NativeVersionCheck(ref ver1, ref ver2, ref ver3);
+            NUILog.Debug($"DALi Version: ({ver1}.{ver2}.{ver3}), NUI API Version: ({nuiAPIVer})");
+        }
     }
 }
index 3c009a6..e4071e4 100755 (executable)
@@ -252,12 +252,8 @@ namespace Tizen.NUI
 
         public VisualBase GetVisual(int index)
         {
-            //to fix memory leak issue, match the handle count with native side.
-            System.IntPtr cPtr = NDalicManualPINVOKE.ViewWrapperImpl_GetVisual(swigCPtr, index);
-            HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
-            VisualBase ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as VisualBase;
-            NDalicPINVOKE.delete_BaseHandle(CPtr);
-            CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            VisualBase visualBase = new VisualBase(NDalicManualPINVOKE.ViewWrapperImpl_GetVisual(swigCPtr, index), true);
+            VisualBase ret = Registry.GetManagedBaseHandleFromNativePtr(visualBase) as VisualBase;
 
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
index be2115c..a617586 100755 (executable)
@@ -379,12 +379,8 @@ namespace Tizen.NUI.BaseComponents
         /// <since_tizen> 3 </since_tizen>
         public View GetChildAt(TableView.CellPosition position)
         {
-            //to fix memory leak issue, match the handle count with native side.
-            IntPtr cPtr = NDalicPINVOKE.TableView_GetChildAt(swigCPtr, TableView.CellPosition.getCPtr(position));
-            HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
-            View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View;
-            NDalicPINVOKE.delete_BaseHandle(CPtr);
-            CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            View view = new View(NDalicPINVOKE.TableView_GetChildAt(swigCPtr, TableView.CellPosition.getCPtr(position)), true, true);
+            View ret = Registry.GetManagedBaseHandleFromNativePtr(view) as View;
 
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
@@ -398,12 +394,8 @@ namespace Tizen.NUI.BaseComponents
         /// <since_tizen> 3 </since_tizen>
         public View RemoveChildAt(TableView.CellPosition position)
         {
-            //to fix memory leak issue, match the handle count with native side.
-            IntPtr cPtr = NDalicPINVOKE.TableView_RemoveChildAt(swigCPtr, TableView.CellPosition.getCPtr(position));
-            HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
-            View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View;
-            NDalicPINVOKE.delete_BaseHandle(CPtr);
-            CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            View view = new View(NDalicPINVOKE.TableView_RemoveChildAt(swigCPtr, TableView.CellPosition.getCPtr(position)), true, true);
+            View ret = Registry.GetManagedBaseHandleFromNativePtr(view) as View;
 
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
index 2745def..fb208c5 100755 (executable)
@@ -38,6 +38,11 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        internal View(global::System.IntPtr cPtr, bool cMemoryOwn, bool ignore) : base(NDalicPINVOKE.View_SWIGUpcast(cPtr), cMemoryOwn)
+        {
+            swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
+        }
+
         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(View obj)
         {
             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
@@ -63,6 +68,7 @@ namespace Tizen.NUI.BaseComponents
                 if (NDalicPINVOKE.SWIGPendingException.Pending)
                     throw NDalicPINVOKE.SWIGPendingException.Retrieve();
                 Children.Add(child);
+                child.SetParent(this);
             }
         }
 
@@ -78,6 +84,7 @@ namespace Tizen.NUI.BaseComponents
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
 
             Children.Remove(child);
+            child.SetParent(null);
         }
 
         /// <summary>
@@ -114,17 +121,7 @@ namespace Tizen.NUI.BaseComponents
         /// <since_tizen> 4 </since_tizen>
         protected override Container GetParent()
         {
-            //to fix memory leak issue, match the handle count with native side.
-            IntPtr cPtr = NDalicPINVOKE.Actor_GetParent(swigCPtr);
-            HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
-            BaseHandle basehandle = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle);
-            NDalicPINVOKE.delete_BaseHandle(CPtr);
-            CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
-
-            if (NDalicPINVOKE.SWIGPendingException.Pending)
-                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-
-            return basehandle as Container;
+            return Parent;
         }
 
         internal bool IsTopLevelView()
@@ -2559,12 +2556,8 @@ namespace Tizen.NUI.BaseComponents
         /// <since_tizen> 5 </since_tizen>
         public Layer GetLayer()
         {
-            //to fix memory leak issue, match the handle count with native side.
-            IntPtr cPtr = NDalicPINVOKE.Actor_GetLayer(swigCPtr);
-            HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
-            Layer ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as Layer;
-            NDalicPINVOKE.delete_BaseHandle(CPtr);
-            CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            Layer layer = new Layer(NDalicPINVOKE.Actor_GetLayer(swigCPtr), true);
+            Layer ret = Registry.GetManagedBaseHandleFromNativePtr(layer) as Layer;
 
             if (NDalicPINVOKE.SWIGPendingException.Pending)
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
@@ -2591,12 +2584,8 @@ namespace Tizen.NUI.BaseComponents
         /// <since_tizen> 3 </since_tizen>
         public View FindChildByName(string viewName)
         {
-            //to fix memory leak issue, match the handle count with native side.
-            IntPtr cPtr = NDalicPINVOKE.Actor_FindChildByName(swigCPtr, viewName);
-            HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
-            View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View;
-            NDalicPINVOKE.delete_BaseHandle(CPtr);
-            CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            View view = new View(NDalicPINVOKE.Actor_FindChildByName(swigCPtr, viewName), true, true);
+            View ret = Registry.GetManagedBaseHandleFromNativePtr(view) as View;
 
             if (NDalicPINVOKE.SWIGPendingException.Pending)
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
@@ -2605,12 +2594,8 @@ namespace Tizen.NUI.BaseComponents
 
         internal View FindChildById(uint id)
         {
-            //to fix memory leak issue, match the handle count with native side.
-            IntPtr cPtr = NDalicPINVOKE.Actor_FindChildById(swigCPtr, id);
-            HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
-            View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View;
-            NDalicPINVOKE.delete_BaseHandle(CPtr);
-            CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            View view = new View(NDalicPINVOKE.Actor_FindChildById(swigCPtr, id), true, true);
+            View ret = Registry.GetManagedBaseHandleFromNativePtr(view) as View;
 
             if (NDalicPINVOKE.SWIGPendingException.Pending)
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
@@ -3204,12 +3189,8 @@ namespace Tizen.NUI.BaseComponents
         /// <since_tizen> 3 </since_tizen>
         public Renderer GetRendererAt(uint index)
         {
-            //to fix memory leak issue, match the handle count with native side.
-            IntPtr cPtr = NDalicPINVOKE.Actor_GetRendererAt(swigCPtr, index);
-            HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
-            Renderer ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as Renderer;
-            NDalicPINVOKE.delete_BaseHandle(CPtr);
-            CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            Renderer renderer = new Renderer(NDalicPINVOKE.Actor_GetRendererAt(swigCPtr, index), true);
+            Renderer ret = Registry.GetManagedBaseHandleFromNativePtr(renderer) as Renderer;
 
             if (NDalicPINVOKE.SWIGPendingException.Pending)
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
index b7d8514..6bb48c6 100755 (executable)
@@ -30,6 +30,7 @@ namespace Tizen.NUI
     {
 
         private List<View> _childViews = new List<View>();
+        private Container _parent = null;
 
         /// <summary>
         /// List of children of Container.
@@ -62,6 +63,10 @@ namespace Tizen.NUI
             base.Dispose(type);
         }
 
+        /// <summary>
+        /// This should be implemented in derived child classes such as View and Layer
+        /// </summary>
+        /// <returns>parent object of mine, which will be Container class</returns>
         protected abstract Container GetParent();
 
         /// <summary>
@@ -110,10 +115,15 @@ namespace Tizen.NUI
         {
             get
             {
-                return GetParent();
+                return _parent;
             }
         }
 
+        internal void SetParent(Container parent)
+        {
+            _parent = parent;
+        }
+
         /// <summary>
         /// Gets the number of children for this container.
         /// Read only
index 7cffacb..744f64d 100755 (executable)
@@ -449,12 +449,8 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public View GetCurrentFocusView()
         {
-            //to fix memory leak issue, match the handle count with native side.
-            IntPtr cPtr = NDalicManualPINVOKE.FocusManager_GetCurrentFocusActor(swigCPtr);
-            HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
-            View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View;
-            NDalicPINVOKE.delete_BaseHandle(CPtr);
-            CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            View view = new View(NDalicManualPINVOKE.FocusManager_GetCurrentFocusActor(swigCPtr), true, true);
+            View ret = Registry.GetManagedBaseHandleFromNativePtr(view) as View;
 
             return ret;
         }
@@ -557,12 +553,8 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public View GetFocusGroup(View view)
         {
-            //to fix memory leak issue, match the handle count with native side.
-            IntPtr cPtr = NDalicManualPINVOKE.FocusManager_GetFocusGroup(swigCPtr, View.getCPtr(view));
-            HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
-            View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View;
-            NDalicPINVOKE.delete_BaseHandle(CPtr);
-            CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            View localView = new View(NDalicManualPINVOKE.FocusManager_GetFocusGroup(swigCPtr, View.getCPtr(view)), true, true);
+            View ret = Registry.GetManagedBaseHandleFromNativePtr(localView) as View;
 
             return ret;
         }
@@ -592,12 +584,8 @@ namespace Tizen.NUI
 
         internal View GetFocusIndicatorView()
         {
-            //to fix memory leak issue, match the handle count with native side.
-            IntPtr cPtr = NDalicManualPINVOKE.FocusManager_GetFocusIndicatorActor(swigCPtr);
-            HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
-            View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View;
-            NDalicPINVOKE.delete_BaseHandle(CPtr);
-            CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            View view = new View(NDalicManualPINVOKE.FocusManager_GetFocusIndicatorActor(swigCPtr), true, true);
+            View ret = Registry.GetManagedBaseHandleFromNativePtr(view) as View;
 
             return ret;
         }
index 4e31810..f2b9730 100755 (executable)
@@ -61,6 +61,7 @@ namespace Tizen.NUI
                 if (NDalicPINVOKE.SWIGPendingException.Pending)
                     throw NDalicPINVOKE.SWIGPendingException.Retrieve();
                 Children.Add(child);
+                child.SetParent(this);
             }
         }
 
@@ -77,6 +78,7 @@ namespace Tizen.NUI
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
 
             Children.Remove(child);
+            child.SetParent(null);
         }
 
         /// <summary>
@@ -98,6 +100,10 @@ namespace Tizen.NUI
             }
         }
 
+        /// <summary>
+        /// protected override method derived from Container abstract parent class
+        /// </summary>
+        /// <returns>always return null, because in NUI, Layer can be added under Window</returns>
         protected override Container GetParent()
         {
             return null;
@@ -191,12 +197,8 @@ namespace Tizen.NUI
         /// <since_tizen> 3 </since_tizen>
         public View FindChildById(uint id)
         {
-            //to fix memory leak issue, match the handle count with native side.
-            IntPtr cPtr = NDalicPINVOKE.Actor_FindChildById(swigCPtr, id);
-            HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
-            View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View;
-            NDalicPINVOKE.delete_BaseHandle(CPtr);
-            CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            View view = new View(NDalicPINVOKE.Actor_FindChildById(swigCPtr, id), true, true);
+            View ret = Registry.GetManagedBaseHandleFromNativePtr(view) as View;
 
             if (NDalicPINVOKE.SWIGPendingException.Pending)
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
index 1a557ee..b8a65ed 100755 (executable)
@@ -405,12 +405,8 @@ namespace Tizen.NUI.UIComponents
 
         internal View GetTitle()
         {
-            //to fix memory leak issue, match the handle count with native side.
-            IntPtr cPtr = NDalicPINVOKE.Popup_GetTitle(swigCPtr);
-            HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
-            View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View;
-            NDalicPINVOKE.delete_BaseHandle(CPtr);
-            CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            View view = new View(NDalicPINVOKE.Popup_GetTitle(swigCPtr), true, true);
+            View ret = Registry.GetManagedBaseHandleFromNativePtr(view) as View;
 
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
@@ -429,12 +425,8 @@ namespace Tizen.NUI.UIComponents
 
         internal View GetContent()
         {
-            //to fix memory leak issue, match the handle count with native side.
-            IntPtr cPtr = NDalicPINVOKE.Popup_GetContent(swigCPtr);
-            HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
-            View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View;
-            NDalicPINVOKE.delete_BaseHandle(CPtr);
-            CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            View view = new View(NDalicPINVOKE.Popup_GetContent(swigCPtr), true, true);
+            View ret = Registry.GetManagedBaseHandleFromNativePtr(view) as View;
 
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
@@ -453,12 +445,8 @@ namespace Tizen.NUI.UIComponents
 
         internal View GetFooter()
         {
-            //to fix memory leak issue, match the handle count with native side.
-            IntPtr cPtr = NDalicPINVOKE.Popup_GetFooter(swigCPtr);
-            HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
-            View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View;
-            NDalicPINVOKE.delete_BaseHandle(CPtr);
-            CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            View view = new View(NDalicPINVOKE.Popup_GetFooter(swigCPtr), true, true);
+            View ret = Registry.GetManagedBaseHandleFromNativePtr(view) as View;
 
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
index cb44337..81d4628 100755 (executable)
@@ -1398,7 +1398,8 @@ namespace Tizen.NUI
         /// </summary>
         /// <param name="transparent">Whether the window is transparent.</param>
         /// <since_tizen> 5 </since_tizen>
-        public void SetTransparency(bool transparent) {
+        public void SetTransparency(bool transparent) 
+        {
             NDalicManualPINVOKE.SetTransparency(swigCPtr, transparent);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }