tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/374-additional-observation-regarding-module-unloadingRobotlegs: Discussion 2011-11-21T09:22:00Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/98837812011-09-20T00:47:58Z2011-09-20T00:48:00ZAdditional observation regarding module unloading<div><p>Still wondering if anyone else has seen steadily growing number
of module instances in the profiler(for this application, even
though dispose() function does get called) or this is not an
important enough issue ?</p>
<p>I like all aspects of RL, this is the only major blocking
factor....</p></div>aejaz.muslimtag:robotlegs.tenderapp.com,2009-10-18:Comment/98837812011-09-20T09:30:13Z2011-09-20T09:32:28ZAdditional observation regarding module unloading<div><p>Aah, yes, that takes some effort. I am using the following code
in my modules:</p>
<pre>
<code> /**
* @inheritDoc
*/
public function dispose():void
{
trace("breaker_module.dispose(): context=" + context);
if ( context )
{
trace("breaker_module.dispose(): Calling 'removeViews' to remove all children of the context");
context.removeEventListener( SequenceItemViewEvent.COMPLETED, onModuleCompleted );
BreakerModuleContext(context).removeViews();
this.addEventListener(Event.ENTER_FRAME, onGarbageCycleEvent);
}
}
private var _gcCount: uint = 0;
private function onGarbageCycleEvent(event:Event):void
{
if ( _gcCount >= 5 ) {
trace("bingo!");
this.removeEventListener(Event.ENTER_FRAME, onGarbageCycleEvent);
trace("suggesting to cleanup the context");
cleanupContext();
return;
}
trace("wait a bit of time...");
_gcCount++;
}
private function cleanupContext():void
{
trace(breaker_module.cleanupContext()");
// check the contents
trace("breaker_module.cleanupContext(): numChildren=" + _moduleContainer.numChildren);
//
if ( _moduleContainer ) {
trace("breaker_module.cleanupContext(): Removing module container view");
removeChild(_moduleContainer);
_moduleContainer = null;
}
trace("breaker_module.cleanupContext(): CALLING context.dispose()");
_injector = null;
context.shutdown();
_gcCount = 0;
this.addEventListener(Event.ENTER_FRAME, onGarbageCycle2Event);
}
private function onGarbageCycle2Event(event:Event):void
{
if ( _gcCount >= 5 ) {
trace("bingo!");
this.removeEventListener(Event.ENTER_FRAME, onGarbageCycle2Event);
trace("onGarbageCycle2Event(): suggesting kill everything and dispatch event");
finalModuleDisposed();
return;
}
trace("onGarbageCycle2Event(): wait a bit of time...");
_gcCount++;
}
private function finalModuleDisposed(): void
{
trace("finalModuleDisposed()");
context.dispose();
context = null;
trace("Trying to dispatch an event: moduleDisposed");
dispatchEvent( new Event('moduleDisposed' ) );
}</code>
</pre></div>Weyerttag:robotlegs.tenderapp.com,2009-10-18:Comment/98837812011-09-20T21:49:37Z2011-09-20T21:49:38ZAdditional observation regarding module unloading<div><p>Thanks a lot Weyert .</p>
<p>I really hope that RL2 handles module cleanup...</p>
<p>Above code seems complex, if you could please<br>
simplify & explain, I am sure it will benefit others as<br>
well.</p>
<p>Aejaz</p></div>aejaz.muslimtag:robotlegs.tenderapp.com,2009-10-18:Comment/98837812011-09-21T07:20:39Z2011-09-21T07:20:39ZAdditional observation regarding module unloading<div><p>In my solution the shell will call the
<code>dispose</code>()-method on the document class of the loaded
the module. When the <code>dispose</code>()-method gets called it
starts with recursively deleted all the views (of the module) and
then wait n frames to give Flash and Robotlegs a chance to the
delete all the views and call <code>onRemove</code>() on it's
mediators.</p>
<p>After the waiting of a few frame ticks it will call the
<code>shutdown</code>-method on the context of the module which
then does all kind of unmappings and other opposite things from the
<code>startup</code>-method. Then after again a few frame ticks it
call the <code>dispose</code>-method on the context and then
nullify this variable. After this all is done it wil finish with
informing the shell the module has been disposed.</p></div>Weyert