Using a dictionary isn’t completely reliable because the garbage collector will only free up what it needs.  If the window isn’t taking too much space the collector may not go ahead and clean it up for a while.  The weak reference only says “take it if you need it” but it’s not guaranteed that if the only reference is weak that it will disappear immediately.  That’s why we trigger garbage collection by creating a bunch of objects, it’s to force the GC into thinking it needs the space for allocation.

 

Matt

 


From: [email protected] [mailto:[email protected]] On Behalf Of jeff tapper
Sent: Thursday, July 27, 2006 9:41 AM
To: [email protected]
Subject: [flexcoders] Re: Tools for listing objects

 

Really, what im looking for, is some way to check if an object no
longer exists. I thought a weak reference in the dictionary might
work for me, but after 14 hours of inactivity, those weak references
are still there.

Am i misunderstanding the nature of a weak reference? Is there some
other way that I can test to see if a given object still exists?

--- In [EMAIL PROTECTED]ups.com, "Matt Chotin" <[EMAIL PROTECTED]> wrote:
>
> There's no way to know if garbage collection was forced. Create a
> method does does a for loop that creates 10,000 objects into mid-
air.
>
>
>
> For (var i:int=0; I < 10000; i++)
>
> New Object();
>
>
>
> That should trigger the garbage collector hopefully.
>
>
>
> ________________________________
>
> From: [EMAIL PROTECTED]ups.com
[mailto:[EMAIL PROTECTED]ups.com] On
> Behalf Of jeff tapper
> Sent: Thursday, July 27, 2006 5:56 AM
> To: [EMAIL PROTECTED]ups.com
> Subject: [flexcoders] Re: Tools for listing objects
>
>
>
> Well, that experiment failed as well. 14 hours later, the same
> objects are still listed in the dictionary.
> Wed Jul 26 17:07:23 GMT-0400 2006
> Testing56:Testing56
> Testing19:Testing19
> Testing38:Testing38
> Thu Jul 27 08:50:31 GMT-0400 2006
> Testing56:Testing56
> Testing19:Testing19
> Testing38:Testing38
>
> Am I misunderstanding the usage of Weak References in the
> Dictionary? Does anyone have any idea how this can be used to keep
> track of what objects exist and which dont?
>
> --- In [EMAIL PROTECTED]ups.com <mailto:flexcoders%
40yahoogroups.com>
> , "jeff tapper" <jeff@> wrote:
> >
> > Ok, heres a sketch of what im trying now.
> > App.mxml
> > ====
> > <?xml version="1.0" encoding="utf-8"?>
> > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml
> <http://www.adobe.com/2006/mxml> "
> > layout="vertical" creationComplete="initApp()">
> > <mx:Script>
> > <![CDATA[
> > import mx.managers.PopUpManager;
> > import mx.managers.PopUpManagerChildList;
> > import mx.core.IFlexDisplayObject;
> > private var screenDict:Dictionary;
> > private var scr1:IFlexDisplayObject;
> > private function initApp():void{
> > screenDict = new Dictionary(true);
> > }
> > public function createScreen
> > (parent:DisplayObjectContainer,
> > screen:Class,modal:Boolean=false):IFlexDisplayObject{
> > var s:IFlexDisplayObject =
> > PopUpManager.createPopUp(parent, screen,
> > modal,PopUpManagerChildList.APPLICATION);
> > screenDict[s] = s.name
> > return s;
> > }
> > public function showObjects():void{
> > trace(new Date());
> > for (var i:* in screenDict){
> > trace(i+":"+screenDict[i]);
> > }
> > }
> > public function removeScreen
> > (screen:IFlexDisplayObject):void{
> > PopUpManager.removePopUp(screen);
> > }
> > private function makeScreen():void{
> > if(scr1 == null){
> > scr1 = createScreen
> > (this,Testing,false);
> > }
> > }
> > private function destroyScreen():void{
> > removeScreen(scr1);
> > scr1 = null;
> > }
> >
> > ]]>
> > </mx:Script>
> > <mx:Button click="makeScreen()" label="make"/>
> > <mx:Button click="destroyScreen()" label="kill"/>
> > <mx:Button click="showObjects()" label="show"/>
> > </mx:Application>
> >
> > Testing.mxml
> > =====
> > <?xml version="1.0" encoding="utf-8"?>
> > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml
> <http://www.adobe.com/2006/mxml> " width="400"
> > height="300">
> > <mx:Button click="this.dispatchEvent(new Event('foo'))"/>
> > </mx:Panel>
> >
> > Now, as i run this, if i click make, kill, make, kill, show, The
> > trace shows:
> > Wed Jul 26 17:07:14 GMT-0400 2006
> > Testing58:Testing58
> > Testing20:Testing20
> > Testing39:Testing39
> >
> > Implying that the screens arent really being destroyed. Perhaps
I
> > didnt wait long enough, so 5 minutes later, I tried the same
> thing,
> > with the same results. Maybe 5 minutes isnt long enough, so I'll
> > leave it running over night and try again in the morning. But,
> the
> > fundemental question is, have i done enough to remove the
> screens?
> > Should the garbage collector clean the unused ones up, or have i
> > somehow left a reference lingering?
> >
> > We have a very complex app, which I want to ensure we clean up
all
> > unused objects, but im having trouble finding a way to verify
they
> > are removed.
> >
>

__._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




__,_._,___

Reply via email to