#### aejaz.muslim

11 Sep, 2011 06:43 AM

Hi,

I have already made a post regarding this topic. I just wanted to say that I
also tried the module example at,

& although it runs fine behavior wise but I don't see the messages on console in debug mode which tell that the modules have been unloaded.
Typically they look as follows,

Unfortunately I am not seeing such messages with module examples which
I have tried so far. Please let me know if I am missing anything.

Thanks,
Aejaz

1. Posted by aejaz.muslim on 20 Sep, 2011 12:47 AM

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 ?

I like all aspects of RL, this is the only major blocking factor....

2. Posted by Weyert on 20 Sep, 2011 09:30 AM

Aah, yes, that takes some effort. I am using the following code in my modules:

    /**
* @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();
}
}

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;
}

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' ) );
}

3. Posted by aejaz.muslim on 20 Sep, 2011 09:49 PM

Thanks a lot Weyert .

I really hope that RL2 handles module cleanup...

Above code seems complex, if you could please
simplify & explain, I am sure it will benefit others as
well.

Aejaz

4. Posted by Weyert on 21 Sep, 2011 07:20 AM

In my solution the shell will call the dispose()-method on the document class of the loaded the module. When the dispose()-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 onRemove() on it's mediators.

After the waiting of a few frame ticks it will call the shutdown-method on the context of the module which then does all kind of unmappings and other opposite things from the startup-method. Then after again a few frame ticks it call the dispose-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.

5. Ondina D.F. closed this discussion on 21 Nov, 2011 09:21 AM.

Comments are currently closed for this discussion. You can start a new one.

# Keyboard shortcuts

### Generic

? Show this help Blurs the current field

### Comment Form

r Focus the comment reply box Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

## Recent Discussions

 11 Aug, 2017 07:03 AM injectViewAs in RL2 21 Jun, 2017 08:37 AM Modularity 06 Mar, 2017 03:48 PM How do I access the stage from a Mediator? 21 Dec, 2016 11:37 AM Robotlegs loosing swc data upon code update (Flashbuilder) 28 Nov, 2016 02:18 PM Mediated view inside of item ItemRenderer

## Recent Articles

 Common Problems Why can't I inject Mediators into other Actors? Can I Mediate my Root Application? Is Robotlegs Compatible with the Flash IDE (CS3/CS4) Why doesn't my event trigger the command it is mapped to?