Additional observation regarding module unloading

aejaz.muslim's Avatar

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,

https://github.com/Aaronius/robotlegs-examples-ModularDoodads

& 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,

[Unload SWF] path\to\module.swf

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. 1 Posted by aejaz.muslim on 20 Sep, 2011 12:47 AM

    aejaz.muslim's Avatar

    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. 2 Posted by Weyert on 20 Sep, 2011 09:30 AM

    Weyert's Avatar

    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();
                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' ) );
        }
    
  3. 3 Posted by aejaz.muslim on 20 Sep, 2011 09:49 PM

    aejaz.muslim's Avatar

    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. 4 Posted by Weyert on 21 Sep, 2011 07:20 AM

    Weyert's Avatar

    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
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac