From: Jiyun Yang Date: Fri, 6 Dec 2024 02:18:12 +0000 (+0900) Subject: Add method to hold objects to the native life bound X-Git-Tag: submit/tizen_7.0/20250207.112137~1^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a2a9a81c36fb991c37728cc224e2aa54c089586d;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git Add method to hold objects to the native life bound Signed-off-by: Jiyun Yang --- diff --git a/src/Tizen.NUI/src/public/Common/BaseHandle.cs b/src/Tizen.NUI/src/public/Common/BaseHandle.cs index 641ef73ac..9883a7c18 100755 --- a/src/Tizen.NUI/src/public/Common/BaseHandle.cs +++ b/src/Tizen.NUI/src/public/Common/BaseHandle.cs @@ -15,6 +15,7 @@ * */ using System; +using System.Collections.Generic; using System.ComponentModel; using System.Runtime.CompilerServices; using Tizen.NUI.Binding; @@ -33,6 +34,8 @@ namespace Tizen.NUI /// 3 public class BaseHandle : Element, global::System.IDisposable { + private static Dictionary> nativeBindedHolder = new Dictionary>(); + /// /// swigCMemOwn /// @@ -555,6 +558,9 @@ namespace Tizen.NUI if (SwigCPtr.Handle != IntPtr.Zero) { var nativeSwigCPtr = swigCPtr.Handle; + + ClearHolder(nativeSwigCPtr); + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); if (swigCMemOwn) { @@ -587,6 +593,49 @@ namespace Tizen.NUI Interop.BaseHandle.DeleteBaseHandle(swigCPtr.Handle); } + /// + /// Adds the specified object to the set of objects that have been bound to the native object. + /// + /// The object to add. + [EditorBrowsable(EditorBrowsableState.Never)] + protected void AddToNativeHolder(object obj) + { + if (IsDisposedOrQueued) + { + return; + } + + if (!nativeBindedHolder.TryGetValue(swigCPtr.Handle, out var holders)) + { + nativeBindedHolder.Add(swigCPtr.Handle, holders = new HashSet()); + } + + holders.Add(obj); + } + + /// + /// Removes the specified object from the set of objects that have been bound to the native object. + /// + /// The object to remove. + [EditorBrowsable(EditorBrowsableState.Never)] + protected void RemoveFromNativeHolder(object obj) + { + if (IsDisposedOrQueued) + { + return; + } + + if (nativeBindedHolder.TryGetValue(swigCPtr.Handle, out var holders)) + { + holders.Remove(obj); + + if (holders.Count == 0) + { + nativeBindedHolder.Remove(swigCPtr.Handle); + } + } + } + /// /// Contains event arguments for the FocusChangeRequested event. /// @@ -660,6 +709,14 @@ namespace Tizen.NUI [EditorBrowsable(EditorBrowsableState.Never)] protected internal bool IsDisposeQueued => isDisposeQueued; + [EditorBrowsable(EditorBrowsableState.Never)] + protected internal bool IsDisposedOrQueued => disposed || isDisposeQueued; + + static private void ClearHolder(IntPtr handle) + { + nativeBindedHolder.Remove(handle); + } + [Conditional("NUI_DISPOSE_DEBUG_ON")] private void disposeDebuggingCtor() {