开发者

In proxy should I remove listeners explicitly?

Currently I am working on flex application where开发者_StackOverflow 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 ?


I think you should remove the listeners explicitly. It would at least make it easier for everyone to read the code.

I'm not sure if you keep any other references to that hostController (as you got it from hostController()). If you don't have any other references (for example, if hostController() is a simple create-forget factory) and use weak references on those listeners, that would mean it's eligible for garbage collection even before it finishes it's work -- as far as I understand it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜