Search the web
Sign In
New User? Sign Up
flexcoders · RIA Development with Adobe Flex
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
AS3 object reference changes?   Message List  
Reply | Forward Message #63153 of 150592 |
Re: [flexcoders] AS3 object reference changes?

Thanks for the explanation Gordon.  I guess I wish there were pointers to pointers in AS3 based on what you described.  I wasn't necessarily looking to null out object a in my example, but just carry the pointer along.  The following example is closer to what I'm getting at:

var a:Object = new Object();
var b:Object = new Object();

ChangeWatcher.watch(a, ...

....

a = b

I may set up the ChangeWatcher in one screen but make the change to a in another.  Based on what you described how would I make sure that a ChangeWatcher doesn't hold onto the reference?

Thanks,

Jaime

On 1/30/07, Gordon Smith <gosmith@...> wrote:

It sounds like you're thinking that a = null somehow wipes out the object itself. It doesn't. It simply nulls out the variable 'a', which is a different thing from the object that 'a' refers to.

 

Think of variables like 'a' and 'b' as "pointers" to objects. (Technically, they're 4-byte areas of memory that store the memory address where an object exists.) After executing the first two lines, you have two different pointers pointing to the same object. After executing a = null, the 'a' pointer no longer points to the object but the 'b' pointer still does.

 

So now you might be wondering how you wipe out the object itself. You can't do this directly; only the garbage collector can destroy an object. It is allowed to do so whenever there are no references (pointers) to the object. So you could indirectly wipe out your object by setting both 'a' and 'b' to something else. The object would then become eligible for garbage collection at some indefinite time in the future.

 

- Gordon

 


From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of Jaime Bermudez
Sent: Tuesday, January 30, 2007 1:52 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] AS3 object reference changes?

 

I have a simple question that may be dumb but I find somewhat interesting.  I have something similar to the following simplified AS3 code:

var a:Object = new Object();
var b:Object = a;
             
a = null;

-------------------------------------------

Why does object b hold on to a's object reference?  I would expect b to become null.



Thanks,

Jaime




Wed Jan 31, 2007 2:03 am

therockmeets...
Offline Offline
Send Email Send Email

Forward
Message #63153 of 150592 |
Expand Messages Author Sort by Date

I have a simple question that may be dumb but I find somewhat interesting. I have something similar to the following simplified AS3 code: var a:Object = new...
Jaime Bermudez
therockmeets...
Offline Send Email
Jan 30, 2007
10:02 pm

It sounds like you're thinking that a = null somehow wipes out the object itself. It doesn't. It simply nulls out the variable 'a', which is a different thing...
Gordon Smith
gsmithsf
Online Now Send Email
Jan 30, 2007
11:15 pm

Thanks for the explanation Gordon. I guess I wish there were pointers to pointers in AS3 based on what you described. I wasn't necessarily looking to null...
Jaime Bermudez
therockmeets...
Offline Send Email
Jan 31, 2007
2:03 am

Sorry, I don't understand what you're trying to accomplish. Why do you need to use a ChangeWatcher? What are you watching in a? I'm not very familiar with...
Gordon Smith
gsmithsf
Online Now Send Email
Feb 1, 2007
11:48 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help