View Full Version : Memory unload question
hardcoremore
11-16-2009, 02:36 PM
i just recently watched some tutorial about memory performance in flex 3 and discovered that modules would not unload from memory until all references to the module are first removed. I am just curious why is that necessary, why can't garbage collector remove them automatically and then unload module?
I would really love to hear your thoughts about this. Am i missing something, because i don't understand why unloading module should be any harder then just calling unloadModule() method?
And sorry for the mistake in title. It should be module unload question instead memory unload question
Peter Cowling
11-16-2009, 07:25 PM
Alex Harui's post (http://blogs.adobe.com/aharui/2009/08/what_we_know_about_unloading_m.html) is probably as good a general roundup as there is on the subject - certainly from the Adobe perspective of things.
A stab at answering the question about why unload cannot just get rid of these references would be that either:
Adobe has figured that the time required to create such a facility could be better used elsewhere
Adobe has figured that the overhead of creating such a facility is greater than the benefit it brings
Who knows, but I can see a case for both, and re-reading Alex's post kind of reminds me that I could do with tightening up some of my own practices... :)
hardcoremore
11-22-2009, 03:25 PM
I understand that but can you help me here.
This is my main test application mxml file where i load module.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="init()">
<mx:Script>
<![CDATA[
import modules.testModule;
import mx.events.ModuleEvent;
import mx.modules.ModuleLoader;
private var _moduleLoader:ModuleLoader;
private function init():void
{
_moduleLoader = new ModuleLoader();
_moduleLoader.url = 'modules/testModule.swf';
_moduleLoader.x = 400;
}
private function ucitajProkletiModul(event:MouseEvent):void
{
_moduleLoader.loadModule();
_moduleLoader.addEventListener(ModuleEvent.READY, moduleReadyHandler);
}
private function moduleReadyHandler(event:ModuleEvent):void
{
addChild(_moduleLoader);
}
private function unloadTestSuperFunkcijaModule(event:MouseEvent):vo id
{
var g:* = _moduleLoader.child as testModule;
g.unloadThisModlue();
_moduleLoader.unloadModule();
removeChild(_moduleLoader);
System.gc();
}
]]>
</mx:Script>
<mx:Button label="loadModule" click="ucitajProkletiModul(event)" id="loadModuleBtn" />
<mx:Button label="UnloadMOdule" click="{unloadTestSuperFunkcijaModule(event)}" id="unloadModuleBtn" />
</mx:Application>
and this is my module mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script>
<![CDATA[
public function unloadThisModlue():void
{
this.stage.focus = null;
}
]]>
</mx:Script>
<mx:TextArea id="testArea" />
</mx:Module>
I read that before unloading module you should remove all focuses. So, for example when you click on text field in this module and try to unload it it doesn't unload. When i look inside flex profiler instance is still there and memory doesn't decrease. But if you don't click everything is fine and module unload properly. I try to remove focus with 'this.stage.focus' inside module before unloading it but without success.
So do you know how to remove focus from text field properly before unloading module so that module unloads if that is even possible. Thanks in advance.
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.