Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Help!ApplicationFacade getInstance return null.  (Read 15392 times)
sigismund
Newbie
*
Posts: 3


View Profile Email
« on: August 07, 2009, 03:23:32 »

first i load a module , then i unload it ,
when i load it again , module's ApplicationFacade return a null instance.

i trace it in code, find that instanceMap[ key ] is not null,but cast it return null.

who can help me?

:
        public static function getInstance( key:String ) : ApplicationFacade
        {
        trace(key);
        trace("instanceMap[ key ]:");
        trace(( instanceMap[ key ] == null )?"nothing":instanceMap[ key ]);
       
            if ( instanceMap[ key ] == null ) instanceMap[ key ]  = new ApplicationFacade( key );
        trace("instanceMap[ key ]:");
        trace(( instanceMap[ key ] == null )?"nothing":instanceMap[ key ]);
        trace(instanceMap[ key ] as ApplicationFacade);
            return instanceMap[ key ] as ApplicationFacade;
        }

:
               
 moduleLoader.applicationDomain = ApplicationDomain.currentDomain;
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: August 07, 2009, 08:20:13 »

I think it's going to be somewhere else in your code. Probably has to do with the loader and not talking to it at the right time.

-=Cliff>
Logged
sigismund
Newbie
*
Posts: 3


View Profile Email
« Reply #2 on: August 07, 2009, 08:03:19 »

My loader is nested in a tabnavigator .

When I add a tab , I new a loader as a child of the tab . The tab is closed,loader will be unloaded .
Logged
sigismund
Newbie
*
Posts: 3


View Profile Email
« Reply #3 on: August 07, 2009, 11:46:59 »

I fixed it.

But I have a new problem , right now.

When I load a module again , I click a button in it ,
The button can't dispatchEvent to mediator.

The question is only the first time module load will call onRegister method.
what should I do to call onRegister method each time I load module?


« Last Edit: August 08, 2009, 02:41:41 by sigismund » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #4 on: August 09, 2009, 08:10:34 »

Are you loading the same module multiple times? If so, you should be using a unique key for each to get the Facade. That will ensure that each instance of the module has its own core. '

If you're always unloading the module before loading it again, it should be safe to use the same multiton key each time as long as you do a removeCore when you unload.

Have a look at Simon Bailey's article on MultiCore and Garbage Collection to see the right way to load and unload:
http://www.nutrixinteractive.com/blog/?p=132

-=Cliff>
Logged
titouille
Newbie
*
Posts: 3


View Profile Email
« Reply #5 on: November 15, 2009, 08:56:07 »

Hello,

Sigismund, can you explain how do you resolve your first problem ?? I have the same problem, the casting return null to me...

For more explanation :

I have a "shell" application who load some modules. It's a flash website with some sub-content. Each sub-content is a "module" casted as IModule into the shell. Sub-contents are "presentation", "services", "products", etc...

Actually I have only 2 sub-modules with basic implementation to test the loading. I load "presentation" first time, it's ok. After that select the "products" menu. Application unload "presentation" module (first removeChild, and next remove core). I load "services" first time, all is ok too.
Now I already select "presentation", the module is re-loaded successfully. I select a second time "services", and it return the error about the null facade instance... I don't understand why, because presentation is loaded correctly.

Any suggestion is welcome.

Thanks in advance :-)
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #6 on: November 16, 2009, 02:43:45 »

I select a second time "services", and it return the error about the null facade instance...

Where in the code is this error coming from? Are you using Flex Builder? If so, use the debugger. Set a breakpoint at the place just before this error is occurring and check out the properties in memory.

-=Cliff>
Logged
titouille
Newbie
*
Posts: 3


View Profile Email
« Reply #7 on: November 17, 2009, 06:48:09 »

Hello Cliff and thanks for your answer.

The error is the same as sigismund. The applicationFacade.getInstance return null, but when I run into the getInstance method with the debugger, the instanceMap[key] variable is defined as ch.fasa.modules.services.ApplicationFacade (@1b96cc11).

I noticed some mistakes with debugger...

I load Presentation module first time, module has the memory address "abcd".

I load Services module first time (Presentation module is unloaded), module has the memory address "efgh".

I load Presentation module second time (Services module is unloaded), module has the memory address "ijkl". The instanceMap doesn't contains any "Presentation" key, so it recreate it.

I load Services module second time (Presentation module is unloaded), module has the same memory address as the first time ("efgh"). Services module isn't unloaded from instanceMap and memory. The instanceMap contains already the module and take it to display it.

The think I don't understand is all modules uses the same "Shell", and it's the Shell who load / unload modules... So all modules use the same process to be loaded / unloaded, but only Presentation module is successfully removed from instanceMap and memory...

And... sometimes I'm a stupid animal... Copy and paste is the hell of developer... Each module has it's own "Dispose" command... and I have changed all things into each command, except the "RemoveCore" directive... All dispose command had removeCore( Presentation.NAME )... I changed the directive correctly (Services = removeCore( Services.NAME ), Products = removeCore( Products.NAME ), etc...) and all is ok now

Sorry for the disturbance  ::)
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #8 on: November 18, 2009, 09:48:29 »

No problem. Amazing what the debugger can reveal :)

For getting a better handle on garbage collection of modules in a PureMVC MultiCore AS3 app, check out this great article from Simon Bailey:

http://www.newtriks.com/?p=132

-=Cliff>
Logged
Pages: [1]
Print