[NUI] Enable Window.ViewAdded event
authorDongsug Song <dongsug.song@samsung.com>
Fri, 5 Mar 2021 07:41:07 +0000 (16:41 +0900)
committerhuiyueun <35286162+huiyueun@users.noreply.github.com>
Mon, 8 Mar 2021 08:29:15 +0000 (17:29 +0900)
- Previously, Window.ViewAdded event was blocked by memory leak
- This is enabled again by the request from Appium
- This change has beend checked locally and there was no memory leak (normal)

src/Tizen.NUI/src/public/BaseComponents/View.cs
src/Tizen.NUI/src/public/BaseComponents/ViewEvent.cs
src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs

index 54c9aea..e967580 100755 (executable)
@@ -101,9 +101,8 @@ namespace Tizen.NUI.BaseComponents
                 PositionUsesPivotPoint = false;
             }
 
-            //ToDo: this has memory leak and this is not used currently. will be fixed soon by using Event subscribing pattern.
-            //_onWindowSendEventCallback = SendViewAddedEventToWindow;
-            //this.OnWindowSignal().Connect(_onWindowSendEventCallback);
+            onWindowSendEventCallback = SendViewAddedEventToWindow;
+            this.OnWindowSignal().Connect(onWindowSendEventCallback);
 
             if (!shown)
             {
index cfdcc47..d94024c 100755 (executable)
@@ -56,7 +56,7 @@ namespace Tizen.NUI.BaseComponents
         private ResourcesLoadedCallbackType ResourcesLoadedCallback;
         private EventHandler<BackgroundResourceLoadedEventArgs> backgroundResourceLoadedEventHandler;
         private _backgroundResourceLoadedCallbackType backgroundResourceLoadedCallback;
-
+        private OnWindowEventCallbackType onWindowSendEventCallback;
         private void SendViewAddedEventToWindow(IntPtr data)
         {
             // Unused parameter
index 7e5672a..e6032e7 100755 (executable)
@@ -1279,6 +1279,14 @@ namespace Tizen.NUI.BaseComponents
                 backgroundResourceLoadedCallback = null;
             }
 
+            if (onWindowSendEventCallback != null)
+            {
+                ViewSignal signal = this.OnWindowSignal();
+                signal?.Disconnect(onWindowSendEventCallback);
+                signal?.Dispose();
+                onWindowSendEventCallback = null;
+            }
+
             // BaseHandle CPtr is used in Registry and there is danger of deletion if we keep using it here.
             // Restore current CPtr.
             SwigCPtr = currentCPtr;