Re: Newbie Question about Value and Reference Types
- From: david <david@xxxxxxxxxxxxxxxx>
- Date: Sat, 22 Apr 2006 08:25:31 -0700
On 2006-04-21, Gabor Törö <gfm@xxxxxxxxxx> wrote:
You're pretty much correct about all this, but one quibble.
If an instance is passed by value semantics then a copy of the data on
the stack is made and the adress of this copy is passed to the
implementation while by reference semantics pass the adress of the
original data on the stack.
The address of the copy isn't passed to the implementation. Rather, the
caller simply puts the value on the stack, and the caller *already*
knows where to find the value relative to the stack pointer. IAW,
public void foo(int i, int j, int k) {
A caller doesn't need to send foo the addresses of i,j and k. It just
sets up the stack correctly, and the foo function knows that it can find
i,j and k at the appropriate positions on the stack.
If so then I have another question: If a reference type is passed by
reference to a procedure and within this procedure a new instance of
the same type is generated and assigned to the passed reference
variable what happens to the instacne on the heap if the program
execution leaves the procedure? I think the original instacne on the
heap is now in danger to be killed by the garbage collector as no
reference points to it anymore:
Correct.
.
- Follow-Ups:
- Re: Newbie Question about Value and Reference Types
- From: GFM GToeroe
- Re: Newbie Question about Value and Reference Types
- References:
- Newbie Question about Value and Reference Types
- From: Gabor Törö
- Newbie Question about Value and Reference Types
- Prev by Date: Re: difference between cstr vs .ToString vs Ctype
- Next by Date: Re: Newbie Question about Value and Reference Types
- Previous by thread: Re: Newbie Question about Value and Reference Types
- Next by thread: Re: Newbie Question about Value and Reference Types
- Index(es):
Relevant Pages
|