That's a great example of the dangers of weak references. GC is only done when needed so an idle app is in no hurry to kick out dead objects and weak reference listeners may eat cpu time. If you make the app busy enough to force a GC you'll eventually see it get cleared, and no, adding another dialog or 20 isn't enough, you gotta really pound it. That's why, if you can, you should structure your code so it explcitly calls removeEventListener. We do that a vast majority of the time in the framework.
________________________________ From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of thegiffman Sent: Friday, August 31, 2007 1:53 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Slow Memory Leak with PopUpManager and TitleWindow Right - the listener would have to be added to the stage, with a callback on the pop up. The point is that, even without such a listener, things eventually grow (albeit slowly). Another interesting (and possibly related) case is when you add a weak reference to track if something still exists. When I add and remove dialogs, the first one seems to stay in existence forever, no matter what (though the others go away just fine). This even happens if I don't add it to the stage at all. All that needs to happen is the TitleWindow must have a child, and I get this behavior. -- CODE EXAMPLE --- --- MyApp.mxml --- <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> " xmlns:local="*" layout="vertical"> <mx:Script> <![CDATA[ import mx.managers.PopUpManager; import flash.utils.setTimeout; public var popUps:Array = [] public function addObject():void { var dialog:LoginDialog = new LoginDialog(); addEventListener("enterFrame",dialog.sayHi,false,0,true); popUps.push(dialog); trace("adding "+dialog); } public function removeAllObjects():void { while(popUps.length>0){ trace("removing "+popUps.pop()); } } ]]> </mx:Script> <mx:Button label="add" click="addObject()" /> <mx:Button label="remove" click="removeAllObjects()" /> </mx:Application> --- LoginDialog.mxml --- <?xml version="1.0" encoding="utf-8"?> <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> " title="Login" > <mx:Script> <![CDATA[ import mx.core.Application; import mx.binding.utils.ChangeWatcher; public var counter:int=0; public function sayHi(event:Event = null):void { if(counter++%30==0) trace("I'm alive - "+this); } ]]> </mx:Script> <mx:Button /> </mx:TitleWindow> --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> , "Alex Harui" <[EMAIL PROTECTED]> wrote: > > Please explain further. Calling myPopUp.addEventListener will not keep > the popup in memory. Instead the popup gets a reference to the object > that will be called when the event is dispatched. >