Action <am***@hotmail.com> wrote:
Does this mean that
Point a = new Point(1,2);
Write (a.X);
Write (a.Y);
1. a new Point is created
2. Value of the newly created Point is assigned to Point "a"
3. the "new Point" is destroyed, as Point "a" is a struct, it didn't really
points to the "new Point", so the "new Point" has zero reference => GC clean
it up....
is this the case?
Not quite - because Point is a value type, there *is* nothing on the
heap to be cleaned up. It's just the same as doing:
int a=5;
int b=10;
int x = a+b;
- the addition is performed, and the value is assigned to x. Exactly
the same kind of thing is happening here - the point is created, and
then assigned to the variable. At no point does anything need to be on
the heap - there are no references involved.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too