Neither System.gc() nor does ModuleLoader.unloadModule() release the used memory of a loaded module.

24 views
Skip to first unread message

Ram

unread,
Oct 19, 2009, 3:59:14 AM10/19/09
to Flex India Community, ram...@hcl.in
Hi All,

I used ModuleLoader tag to load and unload my modules. Each module is
a very simple file and does not have any events etc.

When I load and unload modules continuoysly on IE, the memory
utilization goes upto 70% and the size consumed by application crosses
1GB. All of the sudden, IE crashes and application gets closed!

I used below code to unload the module.

_moduleLoader.unloadModule();
_moduleLoader.url = null;
_moduleLoader = null;
System.gc();


1) Are there alternatives to ModuleLoader? I tried ModuleManager, no
luck!
2) Is there any way I can get memory allocated to a module back?
3) Should I make any customizations to ModuleLoader to release the
memory?

We have already developed a product and have schduled release dates
now clients are on top of me and want me to solve this issue though
this is player bug.

ANy immediate help is highly appreciated.

Thanks,
R

nagu

unread,
Oct 19, 2009, 8:27:47 AM10/19/09
to Flex India Community
Hi,
Normally the reasons for crashing flash player would be due to
infinite loop or continues creation of display objects using a some
loop functionality so avoid infinite loop.
for loading modules you have no other option.

1.its better you create the object of the module programmatically
eg:var mo:ModuleLoader=new ModuleLoader();
2. and add it to one conatiner which fits the displayobject.
3.and when ever you are removing, remove it from display and call gc
();
4.and then create new object like step one;

this would work....

Ram

unread,
Oct 19, 2009, 9:36:38 AM10/19/09
to Flex India Community
Hi Nagu,

Thanks for your comments. However, I used below code to get my module
loaded.
_moduleLoader = new ModuleLoader();
_moduleLoader.url = "Module1.swf";
addChild(_moduleLoader);

My Module does not contain anything except <mx:Button ..... />

Even after doing the steps you said, I dont see any improvements!
Not only my app but every app, shown on net, which uses ModuleLoader
has this issue. :(

Please help me!

Thanks,
R
> > R- Hide quoted text -
>
> - Show quoted text -

Tunde Famakinwa

unread,
Oct 19, 2009, 12:22:04 PM10/19/09
to flex_...@googlegroups.com
I use the moduleloader a lot and I even load them into several tabs and I dont have this Issue and this is my code snippet

  var tab:Box = new Box();
            
            
            
if (uniqueId)
{
uniqueTabs[uniqueId] = tab;
}
var child:ModuleLoader = new ModuleLoader();
if (showProgress)
{
child.addEventListener(ModuleEvent.PROGRESS, progressHandler);
child.addEventListener(ModuleEvent.READY, readyCompleteHandler);
}
child.url = modulename;
child.loadModule();
child.percentHeight = 100;
child.percentWidth = 100;
tab.addChild(child);
//PopUpManager.centerPopUp(pbar);
tab.label = lbl;
tab.icon = icon;
tab.percentHeight = 100;
tab.percentWidth = 100;
tabNav.addChild(tab);
if (showProgress)
{
PopUpManager.addPopUp(pbar,child.parent.parent, true);
PopUpManager.centerPopUp(pbar);
    //pbar.bar.value = 0;
pbar.validateNow();
}
tabNav.selectedChild = tab;

And to unload;
  var tab:Container = uniqueTabs[uniqueId];
    var mm:ModuleLoader = tab.getChildAt(0) as ModuleLoader;
                mm.unloadModule();


I hope this helps;

On Mon, Oct 19, 2009 at 2:36 PM, Ram <ram.2...@gmail.com> wrote:
//var tab:Container = new tabClass();
          



--
Famakinwa Babatunde
Software Developer/ 3d Animator
Blog: http://dukefama.wordpress.com

Jitendra Jain

unread,
Oct 19, 2009, 1:48:34 PM10/19/09
to flex_...@googlegroups.com
Hi

You have to set the events as weak references. When yu addEventListener, yu have to make sure to remove those event listeners using removeEventListener and then nullify the object. This way your object will get garbage collected. Otherwise the memory will be increased every time. Please read about how to create weak references to the events. Be careful while using tab Navigator as in every tab there would be living objects. So when any one clicks any tab, try to preserve the state of the tab. Hope this will be helpful.. It helped me a lot..

Ram

unread,
Oct 20, 2009, 12:19:54 AM10/20/09
to Flex India Community
Hi,

Thanks for quick response.

Below is my App code.

private function load():void
{
if (!_moduleLoader)
{
_moduleLoader = new ModuleLoader();
_moduleLoader.url = "Module1.swf";
addChild(_moduleLoader);
_moduleLoader.percentHeight = 100;
_moduleLoader.percentWidth = 100;
_moduleLoader.y = hbox.y+ 50;
_moduleLoader.loadModule();
}

}

private function unload():void
{
if (_moduleLoader)
{

_moduleLoader.unloadModule();
_moduleLoader.unloadModule();
_moduleLoader.url = null;
_moduleLoader = null;
System.gc();

}
}
Here is the module code.

<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
width="100%" height="100%">
<mx:RichTextEditor title="Title" width="349" height="249" x="457"
y="10"/>
<mx:DateChooser x="446.5" y="302"/>
</mx:Module>

I dont think there is any such events or any hard references in the
module. If I run this app on IE7, FP 10, Flex SDK 3.4, the memory leak
happens :(

I am digging into google but could find nothing!
Pls help me.

Regards,
Ram

On Oct 19, 10:48 pm, Jitendra Jain <warriorofheavens...@gmail.com>
wrote:
> Hi
>
> You have to set the events as weak references. When yu addEventListener, yu
> have to make sure to remove those event listeners using removeEventListener
> and then nullify the object. This way your object will get garbage
> collected. Otherwise the memory will be increased every time. Please read
> about how to create weak references to the events. Be careful while using
> tab Navigator as in every tab there would be living objects. So when any one
> clicks any tab, try to preserve the state of the tab. Hope this will be
> helpful.. It helped me a lot..
>
> On Mon, Oct 19, 2009 at 9:52 PM, Tunde Famakinwa
> <tunde.famaki...@gmail.com>wrote:
> > Blog:http://dukefama.wordpress.com- Hide quoted text -

Jitendra Jain

unread,
Oct 20, 2009, 6:02:09 AM10/20/09
to flex_...@googlegroups.com
When yu unload the ModuleLoader, first try to remove the reference from the current display object by saying removeChild and then add your logic to unload the module.

nagu

unread,
Oct 20, 2009, 2:05:08 PM10/20/09
to Flex India Community
you have and followed the third step i think

if(_moduleLoader!=null){
removeChild(_moduleLoader);
_moduleLoader=null;
System.gc();
}
_moduleLoader = new ModuleLoader();
_moduleLoader.url = "Module1.swf";
addChild(_moduleLoader);



nagu

unread,
Oct 21, 2009, 9:03:09 AM10/21/09
to Flex India Community
you have not followed the third step i think

if(_moduleLoader!=null){
removeChild(_moduleLoader);
_moduleLoader=null;
System.gc();
}

_moduleLoader = new ModuleLoader();
_moduleLoader.url = "Module1.swf";
addChild(_moduleLoader);

Arjun

unread,
Oct 21, 2009, 9:09:37 AM10/21/09
to Flex India Community

Ram

unread,
Oct 22, 2009, 1:40:15 AM10/22/09
to Flex India Community
Hi Nagu,

Although the above code does not contain the 3rd step, I developed a
small POC as you said.
1) Create ModuleLoader everytime I load the module
2)Remove it from its parent container while unloading the module.
3) Repeat 1 for loading module again.

I still see there the memory leak! I dont think Modules are really
being released even after remove everything!

Some said, if we click or type in some text fields which are not part
of Module after unlaoding a module, it forces GC.
Pls take a look. These JIRA tcickets DONT HAVE ANY CONCRETE SOLUTION
from Adobe. They talk about weird workarounds which dont seem to solve
my prob!

https://bugs.adobe.com/jira/browse/SDK-18551
https://bugs.adobe.com/jira/browse/SDK-16613
https://bugs.adobe.com/jira/browse/SDK-12025


Pls save me!

-Ram
> > > > - Show quoted text -- Hide quoted text -

Jitendra Jain

unread,
Oct 22, 2009, 5:38:51 AM10/22/09
to flex_...@googlegroups.com
can yu please paste the whole code. I'm afraid you had some references when yu unload the module.

Ram

unread,
Oct 22, 2009, 8:07:47 AM10/22/09
to Flex India Community
Hi,

Here is the code.

private function load
():void
{

if (!_moduleLoader)
{
_moduleLoader = new ModuleLoader();
_moduleLoader.url = "Module1.swf";
addChild(_moduleLoader);
_moduleLoader.percentHeight = 100;
_moduleLoader.percentWidth = 100;
_moduleLoader.y = hbox.y+ 50;
_moduleLoader.loadModule();
}

}

private function unload():void
{
if (_moduleLoader)
{
_moduleLoader.unloadModule();
_moduleLoader.url = null;
removeChild(_moduleLoader);
_moduleLoader = null;
}
}


I am using Flex SDK 3.4, FP 10.0.32.18 (non-debug)....memory goes up
on both the browsers (IE, FF).

Thanks in advance.
-R

On Oct 22, 2:38 pm, Jitendra Jain <warriorofheavens...@gmail.com>
wrote:

Ram

unread,
Oct 22, 2009, 8:08:38 AM10/22/09
to Flex India Community
here is my Module code.

<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
width="100%" height="100%">
<mx:RichTextEditor title="Title" width="349" height="249" x="457"
y="10"/>
<mx:DateChooser x="446.5" y="302"/>

</mx:Module>



On Oct 22, 2:38 pm, Jitendra Jain <warriorofheavens...@gmail.com>
wrote:

Arjun

unread,
Oct 22, 2009, 2:01:03 PM10/22/09
to Flex India Community
one more problem would due to eventlisteners
mainly
1.Timer
2.setInterval
3.setTimeout

if these are not stoped or destoryed the object memory wont get
cleared. so if any listeners exists in your module destroy them before
removing the module

eg:
Application:
_module.destroy();
removechild(_module);

module:
function destroy():void{
timer.stop();
clearInterval(intervalID);
clearTimeout(timeoutID);

Ram

unread,
Oct 23, 2009, 1:51:57 AM10/23/09
to Flex India Community
Hi Arjun,

The above module code does not have any such events/timers etc.

Still the same issue :(


Regards,
Ram
Reply all
Reply to author
Forward
0 new messages