PureMVC Architects Lounge

PureMVC Manifold => MultiCore Version => Topic started by: tennst_s on April 16, 2009, 05:47:03



Title: removeCore( key ) and onRemove()
Post by: tennst_s on April 16, 2009, 05:47:03
Hi,

I am working on an multimodular Flexapplication with PureMVC. Sometimes a PureMVC core must be removed.

In that case I expected that the onRemove() function will be called by the framework. In our case we want to close an open Popup if it is still open if the core removes. But nothing happens. So I have cheated the View.as and modified the removeCore( key ) function like that:

:
public static function removeView( key:String ):void
{
var view:View = getInstance( key ) as View;
if (view != null) {
for (var mediator:String in view.mediatorMap) {
view.removeMediator( mediator );
}
}

delete instanceMap[ key ];
}

In my opinion this is the unsurprisingly behavior. I would enjoy it if the framework behavior would be changed like that.

kind regards
Sven



Title: Re: removeCore( key ) and onRemove()
Post by: puremvc on April 16, 2009, 12:37:33
I've recently answered this at great length. the short answer is it works. Its not necessary to unhook the internals of a module before removing it, only to null external references to anything in the core.

Please check the garbage collection demo / tutorial by Simon Bailey on the MultiCore menu.

-=Cliff>


Title: Re: removeCore( key ) and onRemove()
Post by: puremvc on April 16, 2009, 01:07:42
Search the forums for 'removeCore'

-=Cliff>


Title: Re: removeCore( key ) and onRemove()
Post by: tennst_s on April 22, 2009, 02:20:22
Thank you for your reply!

I have searched the forums for that issue and after faithful reading the posts I think you have missunderstood my concern.

I have no problem with the garbage collector. I want the mediators or proxies to be informed via onRemove() if the core is being removed.

Everything in the facade is fine. All Singletons will be removed an then they could be garbage collected.

:
public static function removeCore( key:String ) : void
{
if (instanceMap[ key ] == null) return;
Model.removeModel( key );
View.removeView( key );
Controller.removeController( key );
delete instanceMap[ key ];
}

But if you dig deeper e.g. into the removeModel function you will see the model will be removed and will be eaten up by the GC. But the proxies will not notice that they are to be removed.

:
public static function removeModel( key:String ):void
{
delete instanceMap[ key ];
}

For my understanding this is an unexpected behavior. Especially when you take a look at the removeProxy function:

:
public function removeProxy( proxyName:String ) : IProxy
{
var proxy:IProxy = proxyMap [ proxyName ] as IProxy;
if ( proxy )
{
proxyMap[ proxyName ] = null;
proxy.onRemove();
}
return proxy;
}

A multiton.removeSomething() produces an onRemove-Call in the corresponding object. Under this condition, I think the removeCore function must do the same.

kind regards

Sven


Title: Re: removeCore( key ) and onRemove()
Post by: puremvc on April 22, 2009, 04:39:25
The onRemove method is called when the Proxy or Mediator is removed from its Model or View respectively. Not when the core itself is removed.

Removing all mediators and proxies from every core would not be performant behavior in many cases, and would certainly not be acceptable default behavior.

For instance in my current app, I could have hundreds of classes instantiated and registered when a user logs out. If I wait for every core to remove all its actors first it would be a pretty nasty wait, and not necessary at all. I suggest sending messages to your cores that require cleanup and collecting acknowledgments before removing the cores if it is a requirement. This would give you time to do async operations at that time as well, such as signing out of services.

-=Cliff>