Hi Alex,

Even I have a similar memory leak issue when using sub application.

Attached the source code of both the main and the sub applications.

The main application has a button which loads the sub application in its swf 
loader control.
Another button which loads another sub application in the same swf loader.

Before either of the applications are loaded 'unloadAndStop' method of the 
swfloader is called so that the garbage collector is triggered and memory is 
released.

Also have a button in which explicitly 'unloadAndStop' is called.

After reading your 'modules-memory-leaks' article, followed some changes like 
adding a focusable control and having a declaration for systemManager in the 
sub application.

After these changes noticed only a small bit of memory gets released but not 
the complete memory which is allocated for the sub application.

Currently using Flex SDK 4.11.


Main application:


<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009";
   xmlns:s="library://ns.adobe.com/flex/spark"
   xmlns:mx="library://ns.adobe.com/flex/mx"  >

<fx:Script>
<![CDATA[
protected function button6_clickHandler(event:MouseEvent):void
{
System.gc();

}
]]>
</fx:Script>

<s:Scroller width="100%" height="100%">
<s:VGroup width="100%" height="100%" gap="20">
<s:SWFLoader id="swfLoader" width="100%" height="100%" scaleContent="true" 
autoLoad="false"/>
<s:HGroup width="100%" height="30%" horizontalAlign="center" 
verticalAlign="middle" gap="20" >
<s:Button label="Load SWF 1" click="button1_clickHandler(event)" />
<s:Button label="Load SWF 2" click="button2_clickHandler(event)" />
<s:Button label="UnLoad" click="button3_clickHandler(event)" />
<s:Button label="Clear The Source" click="button4_clickHandler(event)" />
<s:Button label="Set the source as null" click="button5_clickHandler(event)" />
<s:Button label="Run Garbage Collector" click="button6_clickHandler(event)" />
<s:TextInput id="dummy" />
</s:HGroup>






</s:VGroup>
</s:Scroller>


<fx:Script>
<![CDATA[
protected function button5_clickHandler(event:MouseEvent):void
{

swfLoader.source = null;
swfLoader.load();
dummy.setFocus();
}
]]>
</fx:Script>


<fx:Script>
<![CDATA[
protected function button4_clickHandler(event:MouseEvent):void
{
swfLoader.source = "";
swfLoader.load();

}
]]>
</fx:Script>


<fx:Script>
<![CDATA[
protected function button3_clickHandler(event:MouseEvent):void
{

swfLoader.unloadAndStop();
dummy.setFocus();

}
]]>
</fx:Script>


<fx:Script>
<![CDATA[
protected function button2_clickHandler(event:MouseEvent):void
{
dummy.setFocus();
swfLoader.unloadAndStop();
swfLoader.source = "SampleApplication2.swf";
swfLoader.load();
}
]]>
</fx:Script>

<fx:Script>
<![CDATA[
protected function button1_clickHandler(event:MouseEvent):void
{
dummy.setFocus();
swfLoader.unloadAndStop();
swfLoader.source =null;
swfLoader.source = "SampleApplication1.swf";
swfLoader.load();

}
]]>
</fx:Script>

</s:Application>


Sub Application:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009";
   xmlns:s="library://ns.adobe.com/flex/spark"
   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<s:layout>
<s:VerticalLayout gap="10" horizontalAlign="center" verticalAlign="middle" />
</s:layout>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.styles.StyleManager;StyleManager;
import mx.managers.PopUpManager; PopUpManager;
 import mx.managers.DragManager; DragManager;
 import mx.managers.FocusManager; FocusManager;
import mx.managers.SystemManager; SystemManager;

[Bindable]
public var complexDP:ArrayCollection = new ArrayCollection(
[    {ingredient:"Salmon", category:"Meat"},
{ingredient:"Potato", category:"Starch"},
{ingredient:"Cucumber", category:"Vegetable"},
{ingredient:"Steak", category:"Meat"},
{ingredient:"Rice", category:"Starch"},
{ingredient:"Cumin", category:"Spice"}
]
);
import mx.collections.ArrayCollection;
//private var styleManager:StyleManager;
[Bindable]
private var dpFlat:ArrayCollection = new ArrayCollection([
{Region:"Southwest", Territory:"Arizona",
Territory_Rep:"Barbara Jennings", Actual:38865, Estimate:40000},
{Region:"Southwest", Territory:"Arizona",
Territory_Rep:"Dana Binn", Actual:29885, Estimate:30000},
{Region:"Southwest", Territory:"Central California",
Territory_Rep:"Joe Smith", Actual:29134, Estimate:30000},
{Region:"Southwest", Territory:"Nevada",
Territory_Rep:"Bethany Pittman", Actual:52888, Estimate:45000},
{Region:"Southwest", Territory:"Northern California",
Territory_Rep:"Lauren Ipsum", Actual:38805, Estimate:40000},
{Region:"Southwest", Territory:"Northern California",
Territory_Rep:"T.R. Smith", Actual:55498, Estimate:40000},
{Region:"Southwest", Territory:"Southern California",
Territory_Rep:"Alice Treu", Actual:44985, Estimate:45000},
{Region:"Southwest", Territory:"Southern California",
Territory_Rep:"Jane Grove", Actual:44913, Estimate:45000}
]);


]]>
</fx:Script>
<s:Label horizontalCenter="0" text="Application 1" fontSize="20" />

<s:VGroup width="100%" gap="5" >
<s:Button label="Sample button" />
<s:ComboBox id="cb" dataProvider="{complexDP}" width="150"
selectedIndex="0"
labelField="ingredient"/>
</s:VGroup>
<mx:Panel title="AdvancedDataGrid Control Example"
  height="100%" width="100%" layout="horizontal"
  paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">

<mx:AdvancedDataGrid id="myADG"
 width="100%" height="100%"
 dataProvider="{dpFlat}">


<mx:columns>
<mx:AdvancedDataGridColumn dataField="Region"/>
<mx:AdvancedDataGridColumn dataField="Territory"/>
<mx:AdvancedDataGridColumn dataField="Territory_Rep"
   headerText="Territory Rep"/>
<mx:AdvancedDataGridColumn dataField="Actual"/>
<mx:AdvancedDataGridColumn dataField="Estimate"/>
</mx:columns>
</mx:AdvancedDataGrid>
</mx:Panel>
</s:Application>

Thanx is advance.

-Sasi Kumar K




-----Original Message-----
From: Alex Harui [mailto:aha...@adobe.com]
Sent: 17 March 2014 22:09
To: users@flex.apache.org; bchalu...@t-online.de
Subject: Re: Garbage collection of modules

And if you have further questions, please provide a snippet of code that shows 
how you are loading the modules.

On 3/17/14 1:29 AM, "Pete Thomas" <pete.tho...@dunnhumby.com> wrote:

>http://blogs.adobe.com/aharui/tag/modules-memory-leaks
>
>
>-----Original Message-----
>From: bchalu...@t-online.de [mailto:bchalu...@t-online.de]
>Sent: 17 March 2014 08:16
>To: users@flex.apache.org
>Subject: Garbage collection of modules
>
>Hi,
>
>I'm currently trying to get my modules garbage collected after
>unloading but I can't get it to work.
>During the search for a fix I noticed that the styleManager of the
>module is the same as the one of the main application. I read that Flex
>4 should have a style manager per module.
>Is that a bug or was it never implemented that way?
>
>
>Is there a better way to unload modules completely? I removed the
>declared styles manually, removed the resource bundles, removed all
>event listeners set by me, removed all elements from the UI and set all
>references to null and it still doesn't get gc'd (I added the gc hack
>to verify the gc is run and loaded and unloaded the module several
>times). I don't have any remote classes.
>The problem is that the module has much code and using the profiler or
>scout seems not be an option, because in debug mode it's even more
>unlikely that modules get gc'd.
>
>Is there someone that experienced a similar problem and has some
>information to help me?
>
>Thanks in advance,
>Ben
>
>
>dunnhumby limited is a limited company registered in England and Wales
>with registered number 02388853 and VAT registered number 927 5871 83.
>Our registered office is at Aurora House, 71-75 Uxbridge Road, London
>W5 5SL.
>The contents of this message and any attachments to it are confidential
>and may be legally privileged.
>If you have received this message in error you should delete it from
>your system immediately and advise the sender.
>dunnhumby may monitor and record all emails. The views expressed in
>this email are those of the sender and not those of dunnhumby.

DISCLAIMER: Information contained in and transmitted by this e-mail is 
proprietary to Ramco Systems Limited and/or its parents, subsidiaries and other 
affiliates, including Ramco Systems Corporation, (collectively "Ramco 
Systems"), is a confidential communication between Ramco Systems and the 
intended recipient(s) and is intended for use only by the individual or entity 
to which it is addressed, and may contain information that is privileged, 
confidential or exempt from disclosure under applicable law. If this is a 
forwarded message, the content of this e-mail may not have been sent with the 
authority of Ramco Systems. Any unauthorized disclosure, dissemination, 
forwarding, printing, copying or other use of this email, and/or any action 
taken in reliance on the contents of this e-mail is strictly prohibited and may 
be unlawful. Ramco Systems shall not be liable or responsible to an unintended 
recipient of this email in any way for the contents of this email, or for the 
consequences of any such use or action. If you have received this communication 
in error, either directly or through forwarding, please notify Ramco Systems 
immediately at mailad...@ramco.com and delete/destroy this email and any copies 
of this email. In the absence of a consistent formal hard copy or electronic 
contract or waiver or other instrument duly executed on behalf of Ramco Systems 
by duly authorized officer(s) or agent(s), Ramco Systems shall not be 
contractually bound by any email sent on its behalf. Emails will be used by 
Ramco Systems only for making proposals, conducting negotiations, providing 
information and positions on issues and for similar purposes.

Reply via email to