Adobe
Products

Top destinations

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • SiteCatalyst
  • Students
  • Elements family

Adobe Creative Cloud

  • What is Adobe Creative Cloud?
  • Design
  • Web
  • Photography
  • Video
  • Students
  • Teams
  • Enterprise
  • Educational institutions

Design and photography

  • Photoshop
  • Illustrator
  • InDesign
  • Adobe Muse
  • Lightroom

Video

  • Adobe Premiere
  • After Effects

Web development and HTML5

  • Edge Tools & Services [opens in a new window]
  • Dreamweaver
  • Gaming [opens in a new window]

Adobe Marketing Cloud

  • What is Adobe Marketing Cloud?
  • Digital analytics
  • Social marketing
  • Web experience management
  • Testing and targeting
  • Media optimization

Analytics

  • SiteCatalyst
  • Adobe Discover
  • Insight

Social

  • Adobe Social

Experience Manager

  • CQ
  • Scene7

Target

  • Test&Target
  • Recommendations
  • Search&Promote

Media Optimizer

  • AdLens
  • AudienceManager
  • AudienceResearch

Document services

  • Acrobat
  • EchoSign [opens in a new window]
  • FormsCentral [opens in a new window]
  • SendNow [opens in a new window]
  • Acrobat.com [opens in a new window]

Publishing

  • Digital Publishing Suite

  • See all products
Business solutions

By business need

  • Digital analytics
  • Digital publishing
  • Document management
  • Media optimization
  • Social marketing
  • Testing and targeting
  • Video editing and serving
  • Web development [opens in a new window]
  • Web experience management
  • See all business needs

By industry

  • Broadcast
  • Education
  • Financial services
  • Government
  • Publishing
  • Retail
  • See all industries
Support & Learning

I need help

  • Products
  • Adobe Creative Cloud
  • Adobe Marketing Cloud
  • Forums [opens in a new window]

I want to learn

  • Training and tutorials
  • Certification [opens in a new window]
  • Adobe Developer Connection
  • Adobe Design Center
  • Adobe TV [opens in a new window]
  • Adobe Marketing Center
  • Adobe Labs [opens in a new window]
Download
  • Product trials
  • Adobe Flash Player
  • Adobe Reader
  • Adobe AIR
  • See all downloads
Company
  • Careers at Adobe
  • Investor Relations
  • Newsroom
  • Privacy
  • Corporate Social Responsibility
  • Customer Showcase
  • Contact us
  • More company info
Buy
  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers
  • Adobe Marketing Cloud sales [opens in a new window]
Search
 
Info Sign in
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Welcome,
My Adobe
My orders
My information
My preferences
My products and services
Sign out
My cart
Privacy My Adobe
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out Privacy My Adobe
Date Date
Qty:
Subtotal
Promotions
Estimated Shipping
VAT
Calculated at checkout
Total
Checkout
Flex Help / 

Free memory | Replace data provider of AdvancedDataGrid control

Adobe Community Help


Products Affected

  • Flex

Contact support

 
By clicking Submit, you accept the Adobe Terms of Use.
 

Issue

The AdvancedDataGrid control does not clear the openNodes property if you replace the data provider with a new data provider. Because the openNodes property contains references to objects in the old data provider, the objects cannot be removed from memory by the garbage collection mechanism

To the top

Solution

When using the AdvancedDataGrid control, you can update the control's data provider at runtime. There are several different ways to update the data provider. For example, you can add items, remove items, or reset the data provider. A reset typically means that you replaced the entire contents of the data provider with new content. 

Internally, the AdvancedDataGrid control represents hierarchical and grouped data by using the IHierarchicalCollectionView interface. The IHierarchicalCollectionView interface defines the openNodes property. This property contains an Array of objects that represent the nodes of the data provider that are currently open in the AdvancedDataGrid. In most cases, you can ignore the openNodes property when you update the data provider. 

However, if you replace the data provider with a new data provider, the AdvancedDataGrid control does not clear the openNodes property. Because the openNodes property contains references to objects in the old data provider, the objects cannot be removed from memory by the garbage collection mechanism.  To ensure that the old data provider can be removed from memory, use an event handler to clear the openNodes property when you replace the data provider.

When you modify the data provider, the data provider dispatches a collectionChange event, which an object of type mx.events represents.CollectionEvent. In the event handler for the collectionChange event, you can  use the CollectionEvent.type property to determine the type of modification.  If the type is RESET, clear the openNodes property as shown below: 

<?xml version="1.0"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:mx="library://ns.adobe.com/flex/mx" 
    xmlns:s="library://ns.adobe.com/flex/spark">
    
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.collections.IHierarchicalCollectionView;
            import mx.events.CollectionEvent;
            import mx.events.CollectionEventKind;            
            
            // Define the data provider
            [Bindable]
            private var results:ArrayCollection;
            
            // Refresh the data provider.
            private function refresh():void{
                // Add the removeOpenNodes event handler to the dataProvider.
                if (adg.dataProvider is IHierarchicalCollectionView)
                    IHierarchicalCollectionView(adg.dataProvider).addEventListener(CollectionEvent.COLLECTION_CHANGE, removeOpenNodes);
                
                // generateMyData() returns data for the ADG.
                results = generateMyData();
                myGC.refresh();

                // Remove the removeOpenNodes event handler when done updating the dataProvider.
                if (adg.dataProvider is IHierarchicalCollectionView)
                    IHierarchicalCollectionView(adg.dataProvider).removeEventListener(CollectionEvent.COLLECTION_CHANGE, removeOpenNodes);
            }       
            
            // Handle the colectionChange event.
            private function removeOpenNodes(event:CollectionEvent):void { 
                if(event.kind == CollectionEventKind.RESET) 
                    IHierarchicalCollectionView(adg.dataProvider).openNodes = {}; 
            }
                
            // Generate the data for the dataProvider.
            private function generateMyData():ArrayCollection {
                var newData:ArrayCollection = new ArrayCollection();
                // Returns a new ArrayCollection.
                
                return newData;
            }
        ]]>
    </fx:Script>
    
    <mx:AdvancedDataGrid id="adg" creationComplete="refresh()">
        <mx:dataProvider>
            <mx:GroupingCollection2 source="{results}" id="myGC">
                <mx:grouping>
                    ...
                </mx:grouping>            
            </mx:GroupingCollection2>
        </mx:dataProvider>
        <mx:columns>
            <mx:AdvancedDataGridColumn dataField="Name"/>
            <mx:AdvancedDataGridColumn dataField="Age"/>
            <mx:AdvancedDataGridColumn dataField="Phone"/>
        </mx:columns>
    </mx:AdvancedDataGrid>
    <s:Button label="Refresh" click="refresh()"/>
</s:Application>

 

In this example, you update the dataProvider by replacing the entire ArrayCollection on a refresh. Therefore, attach the event handler for the collectionChange event to the dataProvider of the AdvancedDataGrid.

Alternatively, you can update the source property of the ArrayCollection to replace just the data. In that case, attach the event handler for the collectionChange event to the results ArrayCollection, as shown below:

results.addEventListener(CollectionEvent.COLLECTION_CHANGE, removeOpenNodes);

 

Keywords: cpsid_89785

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy

Products

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • Digital Publishing Suite
  • Elements family
  • SiteCatalyst
  • For education

Download

  • Product trials
  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR

Support & Learning

  • Product help
  • Forums

Buy

  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2013 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

Ad Choices

Reviewed by TRUSTe: site privacy statement