You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ha...@apache.org on 2021/01/04 12:50:42 UTC

[royale-asjs] branch develop updated: Add method finalizeThis() to IViewCursor, and fix memory leak in MX ADG due to event listener leak due to lack of weak references in JS.

This is an automated email from the ASF dual-hosted git repository.

harbs pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new 2e4b949  Add method finalizeThis() to IViewCursor, and fix memory leak in MX ADG due to event listener leak due to lack of weak references in JS.
     new 3eac85b  Merge pull request #1030 from estanglerbm/adg-eventhandler-leak
2e4b949 is described below

commit 2e4b949f14f0c9aa18f996d9e827050d43246406
Author: Edward Stangler <es...@bradmark.com>
AuthorDate: Sun Jan 3 07:54:22 2021 -0600

    Add method finalizeThis() to IViewCursor, and fix memory leak in MX ADG due to event listener leak due to lack of weak references in JS.
---
 .../mx/collections/HierarchicalCollectionViewCursor.as    | 15 +++++++++++++++
 .../src/main/royale/mx/collections/IViewCursor.as         | 11 +++++++++++
 .../src/main/royale/mx/collections/LeafNodeCursor.as      | 14 ++++++++++++++
 .../src/main/royale/mx/collections/ListCollectionView.as  | 14 ++++++++++++++
 ...ndererFactoryForICollectionViewAdvancedDataGridData.as |  3 ++-
 .../mx/controls/treeClasses/HierarchicalViewCursor.as     | 15 +++++++++++++++
 6 files changed, 71 insertions(+), 1 deletion(-)

diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/collections/HierarchicalCollectionViewCursor.as b/frameworks/projects/MXRoyale/src/main/royale/mx/collections/HierarchicalCollectionViewCursor.as
index a2e37f0..9be0e3e 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/collections/HierarchicalCollectionViewCursor.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/collections/HierarchicalCollectionViewCursor.as
@@ -93,6 +93,21 @@ public class HierarchicalCollectionViewCursor extends EventDispatcher
         //check to see if the model has more than one top level items
         more = model.length > 1;
     }
+
+    /**
+     *  Finalizes the cursor, to clean up resources.
+     *  Required because weak references are not available in JS.
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 9
+     *  @playerversion AIR 1.1
+     *  @productversion Royale 0.9.8
+     */
+    public function finalizeThis():void
+    {
+        if (modelCursor) modelCursor.finalizeThis();
+        if (collection) collection.removeEventListener(CollectionEvent.COLLECTION_CHANGE, collectionChangeHandler);
+    }
     
     //--------------------------------------------------------------------------
     //
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/collections/IViewCursor.as b/frameworks/projects/MXRoyale/src/main/royale/mx/collections/IViewCursor.as
index 24a6e7d..09f602e 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/collections/IViewCursor.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/collections/IViewCursor.as
@@ -167,6 +167,17 @@ public interface IViewCursor extends IEventDispatcher
     //--------------------------------------------------------------------------
 
     /**
+     *  Finalizes the cursor, to clean up resources.
+     *  Required because weak references are not available in JS.
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 9
+     *  @playerversion AIR 1.1
+     *  @productversion Royale 0.9.8
+     */
+    function finalizeThis():void;
+
+    /**
      *  Finds an item with the specified properties within the collection
      *  and positions the cursor to that item.
      *  If the item cannot be found, the cursor location does not change.
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/collections/LeafNodeCursor.as b/frameworks/projects/MXRoyale/src/main/royale/mx/collections/LeafNodeCursor.as
index b4d669d..4fc538c 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/collections/LeafNodeCursor.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/collections/LeafNodeCursor.as
@@ -84,6 +84,20 @@ public class LeafNodeCursor extends EventDispatcher
 			
     }
 
+    /**
+     *  Finalizes the cursor, to clean up resources.
+     *  Required because weak references are not available in JS.
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 9
+     *  @playerversion AIR 1.1
+     *  @productversion Royale 0.9.8
+     */
+    public function finalizeThis():void
+    {
+        if (modelCursor) modelCursor.finalizeThis();
+    }
+
     //--------------------------------------------------------------------------
     //
     //  Variables
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/collections/ListCollectionView.as b/frameworks/projects/MXRoyale/src/main/royale/mx/collections/ListCollectionView.as
index 6738376..63ec5e8 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/collections/ListCollectionView.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/collections/ListCollectionView.as
@@ -2069,6 +2069,20 @@ class ListCollectionViewCursor extends EventDispatcher implements IViewCursor
             */
         }
     }
+    
+    /**
+     *  Finalizes the cursor, to clean up resources.
+     *  Required because weak references are not available in JS.
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 9
+     *  @playerversion AIR 1.1
+     *  @productversion Royale 0.9.8
+     */
+    public function finalizeThis():void
+    {
+        if (_view) _view.removeEventListener(CollectionEvent.COLLECTION_CHANGE, collectionEventHandler);
+    }
 
     //--------------------------------------------------------------------------
     //
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/advancedDataGridClasses/DataItemRendererFactoryForICollectionViewAdvancedDataGridData.as b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/advancedDataGridClasses/DataItemRendererFactoryForICollectionViewAdvancedDataGridData.as
index 2d5d587..b3ec5f8 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/advancedDataGridClasses/DataItemRendererFactoryForICollectionViewAdvancedDataGridData.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/advancedDataGridClasses/DataItemRendererFactoryForICollectionViewAdvancedDataGridData.as
@@ -97,7 +97,8 @@ package mx.controls.advancedDataGridClasses
             var dp:ICollectionView = dataProviderModel.dataProvider as ICollectionView;
             if (!dp)
                 return;
-            
+
+            if (cursor) cursor.finalizeThis();
             cursor = dp.createCursor();
             currentIndex = (dp.length > 0) ? 0 : -1;
             
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/treeClasses/HierarchicalViewCursor.as b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/treeClasses/HierarchicalViewCursor.as
index b89c206..97969ca 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/treeClasses/HierarchicalViewCursor.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/treeClasses/HierarchicalViewCursor.as
@@ -86,6 +86,21 @@ public class HierarchicalViewCursor extends EventDispatcher
 		more = model.length > 1;
     }
 
+    /**
+     *  Finalizes the cursor, to clean up resources.
+     *  Required because weak references are not available in JS.
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 9
+     *  @playerversion AIR 1.1
+     *  @productversion Royale 0.9.8
+     */
+    public function finalizeThis():void
+    {
+        if (modelCursor) modelCursor.finalizeThis();
+        if (collection) collection.removeEventListener(CollectionEvent.COLLECTION_CHANGE, collectionChangeHandler);
+    }
+
     //--------------------------------------------------------------------------
     //
     //  Variables