From 5231b3739847c2b5dbe6e0f1aa5b357392510e9f Mon Sep 17 00:00:00 2001 From: Eunki Hong Date: Sat, 28 Jan 2023 23:19:21 +0900 Subject: [PATCH] [NUI][Scene3D][API10] Fix memory leak issue for Model's Animation Since we create new handle at csharp binder, we should call DeleteHandle function. Signed-off-by: Eunki Hong --- src/Tizen.NUI.Scene3D/src/public/Controls/Model.cs | 62 ++++++++++++++++++++-- 1 file changed, 57 insertions(+), 5 deletions(-) diff --git a/src/Tizen.NUI.Scene3D/src/public/Controls/Model.cs b/src/Tizen.NUI.Scene3D/src/public/Controls/Model.cs index b51327f..8d997c0 100755 --- a/src/Tizen.NUI.Scene3D/src/public/Controls/Model.cs +++ b/src/Tizen.NUI.Scene3D/src/public/Controls/Model.cs @@ -181,7 +181,20 @@ namespace Tizen.NUI.Scene3D /// 10 public Animation GetAnimation(uint index) { - Animation ret = new Animation(Interop.Model.GetAnimation(SwigCPtr, index), false); + global::System.IntPtr cPtr = Interop.Model.GetAnimation(SwigCPtr, index); + Animation ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Animation; + if(ret == null) + { + // Register new animation into Registry. + ret = new Animation(cPtr, true); + } + else + { + // We found matched NUI animation. Reduce cPtr reference count. + HandleRef handle = new HandleRef(this, cPtr); + Tizen.NUI.Interop.Animation.DeleteAnimation(handle); + handle = new HandleRef(null, IntPtr.Zero); + } if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } @@ -195,7 +208,20 @@ namespace Tizen.NUI.Scene3D /// 10 public Animation GetAnimation(string name) { - Animation ret = new Animation(Interop.Model.GetAnimation(SwigCPtr, name), false); + global::System.IntPtr cPtr = Interop.Model.GetAnimation(SwigCPtr, name); + Animation ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Animation; + if(ret == null) + { + // Register new animation into Registry. + ret = new Animation(cPtr, true); + } + else + { + // We found matched NUI animation. Reduce cPtr reference count. + HandleRef handle = new HandleRef(this, cPtr); + Tizen.NUI.Interop.Animation.DeleteAnimation(handle); + handle = new HandleRef(null, IntPtr.Zero); + } if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } @@ -211,7 +237,20 @@ namespace Tizen.NUI.Scene3D [EditorBrowsable(EditorBrowsableState.Never)] public Animation LoadBvhAnimation(string bvhFilename, Vector3 scale = null) { - Animation ret = new Animation(Interop.Model.LoadBvhAnimation(SwigCPtr, bvhFilename, Vector3.getCPtr(scale)), false); + global::System.IntPtr cPtr = Interop.Model.LoadBvhAnimation(SwigCPtr, bvhFilename, Vector3.getCPtr(scale)); + Animation ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Animation; + if(ret == null) + { + // Register new animation into Registry. + ret = new Animation(cPtr, true); + } + else + { + // We found matched NUI animation. Reduce cPtr reference count. + HandleRef handle = new HandleRef(this, cPtr); + Tizen.NUI.Interop.Animation.DeleteAnimation(handle); + handle = new HandleRef(null, IntPtr.Zero); + } if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } @@ -222,9 +261,22 @@ namespace Tizen.NUI.Scene3D /// Root View of the model. // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] - private View GetModelRoot() + private Animatable GetModelRoot() { - View ret = new View(Interop.Model.GetModelRoot(SwigCPtr), false); + global::System.IntPtr cPtr = Interop.Model.GetModelRoot(SwigCPtr); + Animatable ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Animatable; + if (ret == null) + { + // Register new animatable into Registry. + ret = new Animatable(cPtr, true); + } + else + { + // We found matched NUI animatable. Reduce cPtr reference count. + HandleRef handle = new HandleRef(this, cPtr); + Tizen.NUI.Interop.BaseHandle.DeleteBaseHandle(handle); + handle = new HandleRef(null, IntPtr.Zero); + } if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } -- 2.7.4