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: In proxy should I remove listeners explicitly ?  (Read 3042 times)
ankurpshah
Newbie
*
Posts: 3



View Profile Email
« on: April 08, 2010, 12:01:28 »

Hi All,

              Currently I am working on flex application where I am using multicore variant of puremvc. My question is in my proxy I am making remote call and attaching some (RESULT and FAULT) event listener. So in my event handler code should I remove listeners explicitly for making remoteObject class eligible for garbage collecton ?
:
public function getTableGridData():void
{
var hostController:RemoteObject=this.hostController("ABC");
hostController.addEventListener(ResultEvent.RESULT, handleResult);
hostController.addEventListener(FaultEvent.FAULT, handleFault);
hostController.getTableData();
}

private function handleResult(event:ResultEvent):void
{
ApplicationFacade.getInstance(key).sendNotification("abc", event.result);
}

So here hostController holds strong reference of both the listeners. So after resultEvent does hostController is eligible for garbage collection or I have to mention weak reference for listeners for making hostController eligible for garbage collectioin ?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: April 08, 2010, 05:53:02 »

Yes, you need to either remove the listeners explicitly, or specify a true for the weakRef argument to addEventListener (which is false by default).

And you don't need to do those backflips to get the facade; every proxy, mediator and command comes with a built in reference to their Facade. Further, you don't have to reference sendNotification on the facade, because every proxy, mediator and command has its own sendNotification convenience method.

Therefore, while this works:
:
private function handleResult(event:ResultEvent):void
{
ApplicationFacade.getInstance(key).sendNotification("abc", event.result);
}

This is simpler and equivalent:
:
private function handleResult(event:ResultEvent):void
{
sendNotification("abc", event.result);
}

-=Cliff>
« Last Edit: April 08, 2010, 05:56:44 by puremvc » Logged
ankurpshah
Newbie
*
Posts: 3



View Profile Email
« Reply #2 on: April 08, 2010, 06:07:21 »

Thanks cliff for quick help.
Logged
Pages: [1]
Print