From: Umar Date: Wed, 12 Jul 2017 14:43:57 +0000 (+0100) Subject: [Tizen] Create another native handle to make sure Registry.Unregister works fine. X-Git-Tag: submit/trunk/20170823.075128~91^2~99 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=817a69a2d5296a81fc4a61e80d9c77d265fdfbc3;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [Tizen] Create another native handle to make sure Registry.Unregister works fine. This is much simpler solution with less code maintenance as derived classes do not have to call Registry.Unregister(this);. Only BaseHandle class will be responsible for Registry.Register and Registry.UnRegister which is much simpler and symmetric solution. The only drawback is that we have to create an extra native handle. Change-Id: I2e3ab7b3311befb25141ae0816b7d2d77a2e3485 --- diff --git a/src/Tizen.NUI/src/public/BaseHandle.cs b/src/Tizen.NUI/src/public/BaseHandle.cs index 8ac41e0..d14f943 100755 --- a/src/Tizen.NUI/src/public/BaseHandle.cs +++ b/src/Tizen.NUI/src/public/BaseHandle.cs @@ -27,6 +27,18 @@ namespace Tizen.NUI swigCMemOwn = cMemoryOwn; swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + // using copy constructor to create another native handle so Registry.Unregister works fine. + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, NDalicPINVOKE.new_BaseHandle__SWIG_2(swigCPtr)); + + // Register this instance of BaseHandle in the registry. + Registry.Register(this); + } + + internal BaseHandle(global::System.IntPtr cPtr) + { + swigCMemOwn = true; + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + // Register this instance of BaseHandle in the registry. Registry.Register(this); } @@ -93,11 +105,8 @@ namespace Tizen.NUI if (swigCPtr.Handle != global::System.IntPtr.Zero) { - if (swigCMemOwn) - { - swigCMemOwn = false; - NDalicPINVOKE.delete_BaseHandle(swigCPtr); - } + swigCMemOwn = false; + NDalicPINVOKE.delete_BaseHandle(swigCPtr); swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); } @@ -228,12 +237,12 @@ namespace Tizen.NUI } - public BaseHandle() : this(NDalicPINVOKE.new_BaseHandle__SWIG_1(), true) + public BaseHandle() : this(NDalicPINVOKE.new_BaseHandle__SWIG_1()) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } - public BaseHandle(BaseHandle handle) : this(NDalicPINVOKE.new_BaseHandle__SWIG_2(BaseHandle.getCPtr(handle)), true) + public BaseHandle(BaseHandle handle) : this(NDalicPINVOKE.new_BaseHandle__SWIG_2(BaseHandle.getCPtr(handle))) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); }