[NUI] Make Unparent() in Dispose() be excuted early
authordongsug.song <dongsug.song@samsung.com>
Sat, 21 Aug 2021 07:45:54 +0000 (16:45 +0900)
committerJunsuChoi <junduru019@gmail.com>
Tue, 24 Aug 2021 05:09:56 +0000 (14:09 +0900)
- Unparent() needs to be excuted in explicit dispose() which is also same as disposing = true.
- Also it should be called prior to before the derived class of View deletes the native handle, otherwise when doing Unparent(), the child itself has empty body (native object has been deleted already).

src/Tizen.NUI/src/public/BaseComponents/ViewAccessibility.cs
src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs
src/Tizen.NUI/src/public/BaseComponents/ViewPublicMethods.cs
src/Tizen.NUI/src/public/Common/BaseHandle.cs

index 4d551b1..b392206 100755 (executable)
@@ -554,7 +554,15 @@ namespace Tizen.NUI.BaseComponents
         [EditorBrowsable(EditorBrowsableState.Never)]
         protected override void Dispose(bool disposing)
         {
-            base.Dispose(disposing);
+            if (disposed)
+            {
+                return;
+            }
+
+            if (disposing)
+            {
+                Unparent();
+            }
 
             if (accessibilityDelegate != null)
             {
@@ -562,6 +570,8 @@ namespace Tizen.NUI.BaseComponents
                 Marshal.FreeHGlobal(accessibilityDelegatePtr);
                 accessibilityDelegate = null;
             }
+
+            base.Dispose(disposing);
         }
 
         [EditorBrowsable(EditorBrowsableState.Never)]
index d2b6264..4be54a0 100755 (executable)
@@ -1230,8 +1230,6 @@ namespace Tizen.NUI.BaseComponents
                     heightConstraint.Remove();
                     heightConstraint.Dispose();
                 }
-
-                Unparent();
             }
 
             //Release your own unmanaged resources here.
index 8e7a7ff..2552788 100755 (executable)
@@ -236,7 +236,11 @@ namespace Tizen.NUI.BaseComponents
         /// <since_tizen> 4 </since_tizen>
         public override Container GetParent()
         {
-            return this.InternalParent as Container;
+            if (InternalParent)
+            {
+                return this.InternalParent as Container;
+            }
+            return null;
         }
 
         /// <summary>
index 8d1ace1..ab48757 100644 (file)
@@ -109,6 +109,7 @@ namespace Tizen.NUI
         /// Dispose.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
+        // following this guide: https://docs.microsoft.com/ko-kr/dotnet/fundamentals/code-analysis/quality-rules/ca1063?view=vs-2019 (CA1063)
         ~BaseHandle() => Dispose(false);
 
         /// <summary>