You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2014/07/30 20:41:27 UTC

[1/2] git commit: CB-7028 fixed memory leak in wp with plugins

Repository: cordova-wp8
Updated Branches:
  refs/heads/master 63749767c -> fb9cf558c


CB-7028 fixed memory leak in wp with plugins

When navigating between a native and hybrid page in wp8, if the
network-information or device plugins are installed the hybrid page will
never get garbage collected. Fixed by removing event handlers for commands
when the web browser is unloaded.


Project: http://git-wip-us.apache.org/repos/asf/cordova-wp8/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-wp8/commit/28ed6f59
Tree: http://git-wip-us.apache.org/repos/asf/cordova-wp8/tree/28ed6f59
Diff: http://git-wip-us.apache.org/repos/asf/cordova-wp8/diff/28ed6f59

Branch: refs/heads/master
Commit: 28ed6f5922384661e0d111710dbc683cc1955efd
Parents: 9181154
Author: Staci Cooper <sm...@us.ibm.com>
Authored: Thu Jul 3 16:12:35 2014 -0400
Committer: Staci Cooper <sm...@us.ibm.com>
Committed: Thu Jul 3 16:12:35 2014 -0400

----------------------------------------------------------------------
 wp8/template/cordovalib/Commands/BaseCommand.cs | 10 +++++++++
 wp8/template/cordovalib/NativeExecution.cs      | 23 ++++++++++++++++++++
 2 files changed, 33 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/28ed6f59/wp8/template/cordovalib/Commands/BaseCommand.cs
----------------------------------------------------------------------
diff --git a/wp8/template/cordovalib/Commands/BaseCommand.cs b/wp8/template/cordovalib/Commands/BaseCommand.cs
index 9de0e4d..3e2e690 100644
--- a/wp8/template/cordovalib/Commands/BaseCommand.cs
+++ b/wp8/template/cordovalib/Commands/BaseCommand.cs
@@ -172,6 +172,16 @@ namespace WPCordovaClassLib.Cordova.Commands
             this.OnCommandResult = null;
         }
 
+        public void DetachHandlers()
+        {
+            this.OnCommandResult = null;
+            this.OnCustomScript = null;
+            foreach (string callbackId in new List<string>(ResultHandlers.Keys))
+            {
+                RemoveResultHandler(callbackId);
+            }
+        }
+
         public static string GetBaseURL()
         {
 #if CORDOVA_CLASSLIB

http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/28ed6f59/wp8/template/cordovalib/NativeExecution.cs
----------------------------------------------------------------------
diff --git a/wp8/template/cordovalib/NativeExecution.cs b/wp8/template/cordovalib/NativeExecution.cs
index e8bda8f..18ca910 100644
--- a/wp8/template/cordovalib/NativeExecution.cs
+++ b/wp8/template/cordovalib/NativeExecution.cs
@@ -18,6 +18,7 @@ using System.Threading;
 using Microsoft.Devices;
 using Microsoft.Phone.Controls;
 using WPCordovaClassLib.Cordova.Commands;
+using System.Collections.Generic;
 using System.Windows;
 
 namespace WPCordovaClassLib.Cordova
@@ -34,6 +35,11 @@ namespace WPCordovaClassLib.Cordova
         private readonly WebBrowser webBrowser;
 
         /// <summary>
+        /// List of commands with attached handlers
+        /// </summary>
+        private List<BaseCommand> commands;
+
+        /// <summary>
         /// Creates new instance of a NativeExecution class.
         /// </summary>
         /// <param name="browser">Reference to web part where application is hosted</param>
@@ -45,6 +51,22 @@ namespace WPCordovaClassLib.Cordova
             }
 
             this.webBrowser = browser;
+            this.commands = new List<BaseCommand>();
+            webBrowser.Unloaded += webBrowser_Unloaded;
+        }
+
+        /// <summary>
+        /// Detaches event handlers to prevent memory leak on page navigation
+        /// </summary>
+        void webBrowser_Unloaded(object sender, RoutedEventArgs e)
+        {
+            for (int i = commands.Count - 1; i >= 0; i--)
+            {
+                if (commands[i] != null)
+                {
+                    commands[i].DetachHandlers();
+                }
+            }
         }
 
         /// <summary>
@@ -120,6 +142,7 @@ namespace WPCordovaClassLib.Cordova
                     try
                     {
                         bc.InvokeMethodNamed(commandCallParams.CallbackId, commandCallParams.Action, commandCallParams.Args);
+                        commands.Add(bc);
                     }
                     catch (Exception ex)
                     {


[2/2] git commit: Merge branch 'CB-7028' of https://github.com/stacic/cordova-wp8

Posted by pu...@apache.org.
Merge branch 'CB-7028' of https://github.com/stacic/cordova-wp8


Project: http://git-wip-us.apache.org/repos/asf/cordova-wp8/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-wp8/commit/fb9cf558
Tree: http://git-wip-us.apache.org/repos/asf/cordova-wp8/tree/fb9cf558
Diff: http://git-wip-us.apache.org/repos/asf/cordova-wp8/diff/fb9cf558

Branch: refs/heads/master
Commit: fb9cf558c65bd0e580915f2a6d7ab96986e85965
Parents: 6374976 28ed6f5
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Wed Jul 30 11:40:57 2014 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Wed Jul 30 11:40:57 2014 -0700

----------------------------------------------------------------------
 wp8/template/cordovalib/Commands/BaseCommand.cs | 10 +++++++++
 wp8/template/cordovalib/NativeExecution.cs      | 23 ++++++++++++++++++++
 2 files changed, 33 insertions(+)
----------------------------------------------------------------------