RE: [flexcoders] Variable instances behavior in Actionscript

2007-09-05 Thread Gordon Smith
a, b, and c all contain references to the same instance of Book.
References are always to objects, not to vars. Nulling out c has no
effect on a and b, which continue to refer to the instance of Book.
 
- Gordon



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Steve Hueners
Sent: Tuesday, September 04, 2007 6:31 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Variable instances behavior in Actionscript



Beauty. looking 2 know too.


On 9/4/07, williamkusumo [EMAIL PROTECTED]
mailto:[EMAIL PROTECTED]  wrote: 

Very stupid question which has been bugging me for a while and
just
might be the most basic question in this group.

How does a object instance behave in Actionscript? Say if I have
this:

var a:Book = new Book();
var b:Book = a;
var c:Book = b;

So does c actually point to the instance that a and b is
pointing to
or is it pointing to b?

And if I do this:

c = null;

Does a and b get nulled too or does it act more like a pointer
where
it means c is now pointing to null, a and b still points to the
object
instance?

Thanks!






 


Re: [flexcoders] Variable instances behavior in Actionscript

2007-09-05 Thread Jeremy French
Another good way to think of it is that a reference to an object is actually
an integer that holds the object's address in memory.  You'll see this in
the debugger as @3342fe334, etc.  So when you copy 'a' into 'b'  a la
'b=a;', you're making a copy of the address - not the object.  So when you
later say 'b = null;', it doesn't affect 'a' at all, because 'a' still holds
the address to the object.

You've probably heard of the garbage collector.  This special process is
basically running all the time and goes through all the objects and looks to
see if any variables hold their address, and if not, delete the object.  But
as long as some variable has that address, the object still exists.  So for
example:

a = new Book();
b = a;
a = null;
c = b;
b = null;

The same object exists all the way through.


On 9/4/07, williamkusumo [EMAIL PROTECTED] wrote:

   Very stupid question which has been bugging me for a while and just
 might be the most basic question in this group.

 How does a object instance behave in Actionscript? Say if I have this:

 var a:Book = new Book();
 var b:Book = a;
 var c:Book = b;

 So does c actually point to the instance that a and b is pointing to
 or is it pointing to b?

 And if I do this:

 c = null;

 Does a and b get nulled too or does it act more like a pointer where
 it means c is now pointing to null, a and b still points to the object
 instance?

 Thanks!

 



[flexcoders] Variable instances behavior in Actionscript

2007-09-04 Thread williamkusumo
Very stupid question which has been bugging me for a while and just
might be the most basic question in this group.

How does a object instance behave in Actionscript? Say if I have this:

var a:Book = new Book();
var b:Book = a;
var c:Book = b;

So does c actually point to the instance that a and b is pointing to
or is it pointing to b?

And if I do this:

c = null;

Does a and b get nulled too or does it act more like a pointer where
it means c is now pointing to null, a and b still points to the object
instance?

Thanks!



Re: [flexcoders] Variable instances behavior in Actionscript

2007-09-04 Thread Steve Hueners
Beauty. looking 2 know too.

On 9/4/07, williamkusumo [EMAIL PROTECTED] wrote:

   Very stupid question which has been bugging me for a while and just
 might be the most basic question in this group.

 How does a object instance behave in Actionscript? Say if I have this:

 var a:Book = new Book();
 var b:Book = a;
 var c:Book = b;

 So does c actually point to the instance that a and b is pointing to
 or is it pointing to b?

 And if I do this:

 c = null;

 Does a and b get nulled too or does it act more like a pointer where
 it means c is now pointing to null, a and b still points to the object
 instance?

 Thanks!