[NUI] Remove potential of memory leak
authorEunki, Hong <eunkiki.hong@samsung.com>
Thu, 7 Apr 2022 12:22:27 +0000 (21:22 +0900)
committerJaehyun Cho <jaehyun0cho@gmail.com>
Wed, 20 Apr 2022 08:38:08 +0000 (17:38 +0900)
Some Interop API required Delete pairwisely.
This is cause IntPtr have same role as Native size's BaseHandle.
It mean, they increase Native side reference count of BaseObject,
and should decrease the reference by delete it self.
But that IntPtr created in c++ side, so also should delete in c++ side.

Registry.cs use IntPtr as Key so, some API us it as wrong way.
If someone find matched value in Registry, it is just one of BaseHandle.
inputed IntPtr required to delete but some API didn't delete it!

This patch find that case, and make them remove well.

Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
src/Tizen.NUI/src/public/Common/PropertyNotification.cs
src/Tizen.NUI/src/public/Window/Window.cs

index 48b0a98..b36701b 100755 (executable)
@@ -176,9 +176,10 @@ namespace Tizen.NUI
         /// <since_tizen> 4 </since_tizen>
         public Animatable GetTarget()
         {
-            BaseHandle ret = Registry.GetManagedBaseHandleFromNativePtr(Interop.PropertyNotification.GetTarget(SwigCPtr));
+            //to fix memory leak issue, match the handle count with native side.
+            Animatable ret = this.GetInstanceSafely<Animatable>(Interop.PropertyNotification.GetTarget(SwigCPtr));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            return ret as Animatable;
+            return ret;
         }
 
         /// <summary>
index f9ebf3b..fcfd78e 100644 (file)
@@ -79,8 +79,9 @@ namespace Tizen.NUI
                 return null;
             }
 
-            Window ret = Registry.GetManagedBaseHandleFromNativePtr(Interop.Window.Get(View.getCPtr(view))) as Window;
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            //to fix memory leak issue, match the handle count with native side.
+            Window ret = view.GetInstanceSafely<Window>(Interop.Window.Get(View.getCPtr(view)));
+            if (NDalicPINVOKE.SWIGPendingException.Pending)throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
 
@@ -1211,7 +1212,7 @@ namespace Tizen.NUI
             {
                 NUILog.Error("This device does not support surfaceless_context. So Window cannot be created. ");
             }
-            Window ret = Registry.GetManagedBaseHandleFromNativePtr(Interop.Window.GetParent(SwigCPtr)) as Window;
+            Window ret = this.GetInstanceSafely<Window>(Interop.Window.GetParent(SwigCPtr));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }