Take the 2-minute tour ×

The application is too big to describe here, but I can tell you I have up to 20 modules or more that the client can use at any time. And if I go on loading screen after screen, my application can ocuppy 500MB and more.

The script that I use to load and unload modules is:

public function createModule(modulo:String):void {
                if(moduleLoader != null){
                    //moduleLoader.url = null;
                    moduleLoader.url = "com/oss/facturable/components/" + modulo + "?version=" + model.configXML.versionApp;    
            private function errorHandler(e:ModuleEvent):void {
                Alert.show("No se ha podido cargar el modulo. Contacte al departamento técnico.");

The Container in which the module is loaded:

<s:BorderContainer width="98%" height="98%" includeIn="mainState" styleName="bcModuleLoader" top="100">
                        <s:HorizontalLayout paddingLeft="10" paddingRight="10" paddingTop="10" paddingBottom="10"/>
                            <mx:ModuleLoader id="moduleLoader" error="errorHandler(event)" width="100%" height="100%" horizontalAlign="center" verticalAlign="top" creationComplete="createModule('bandejaEntrada.swf')"/>              

The createModule function is called whenever I click on a menu option that I think is irrelevant to post here. All in all, this is everything I have for now to make it work and leak :S

This is the official unloadModule function, I thought, by the looks of it, that the memory should be well allocated with this thing, I mean, look! It removes all the eventListeners and child objects. How come my memory stays the same when unloading, and loads more memory on top of it when I open a new module?! Augh!

public function unloadModule():void
        if (child)
            child = null;

        if (module)
            module.removeEventListener(ModuleEvent.SETUP, moduleSetupHandler);
            module.removeEventListener(ModuleEvent.READY, moduleReadyHandler);
            module.removeEventListener(ModuleEvent.ERROR, moduleErrorHandler);

            module.removeEventListener(ModuleEvent.UNLOAD, moduleUnloadHandler);
            module = null;
share|improve this question
Make sure each module's children components also have their eventListeners removed. I don't suppose any of these modules have AdvancedDataGrids with HierarchicalData do they? –  Jason Towne Aug 1 '11 at 15:10
Yes, they all have Advanced Datagrids. Some modules have popups which leak too, but I don't need to open them for the app to leak data when navigating different modules. –  overmann Aug 1 '11 at 15:20
Do those AdvancedDataGrids use HierarchicalData? I ran into a similar issue where my AdvancedDataGrids were causing memory leaks. –  Jason Towne Aug 1 '11 at 15:23
I don't know what you mean by HierarchicalData, sorry :S. The DataGrids are written in every Module as traditional mxml, and are assigned dataProviders as arrayCollections from result handlers. –  overmann Aug 1 '11 at 15:27
add comment

2 Answers

up vote 1 down vote accepted

From this article:

When using HierachicalData with an AdvancedDataGrid, the control keeps track of hierarchical and grouped data by using the IHierarchicalCollectionView interface. The interface has an openNodes property contains an Array of objects that represent the nodes of the data provider that are currently open in the AdvancedDataGrid.

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 garbage collection. 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.

Add an event listener to the data provider’s CollectionEvent.COLLECTION_CHANGE event to clear the openNodes property.

// Handle the colectionChange event.
private function removeOpenNodes(event:CollectionEvent):void 
  if(event.kind == CollectionEventKind.RESET)
    IHierarchicalCollectionView(adg.dataProvider).openNodes = {};
share|improve this answer
Ok this is gonna sound embarassing, but I don't know where to add that event listener in the CollectionEvent class. Or am I completely lost? –  overmann Aug 1 '11 at 17:51
@overmann No worries. :) Check out kb2.adobe.com/cps/897/cpsid_89785.html for a quick example. –  Jason Towne Aug 1 '11 at 17:59
Wait. There's a problem here, my dg.dataProvider object is not recognized as IHierarchicalCollectionView. –  overmann Aug 1 '11 at 20:08
@overmann Are you displaying your data with collapsible groups or in a tree-like format? If you're just showing the data in a traditional single row format, it probably doesn't use a IHierachicalCollectionView because there are no nodes to keep track of. –  Jason Towne Aug 1 '11 at 20:25
It's a traditional format :S –  overmann Aug 1 '11 at 20:31
show 7 more comments

If you are using Flex 4.5, try to use <s:ModuleLoader/> instead. More details : here

share|improve this answer
I'm using Flex 4, and now it's too late to swtich, the proyect is go, and there are clients using it already. I'm currently using the <mx:ModuleLoader/> –  overmann Aug 1 '11 at 15:36
add comment

Your Answer


