Re: Local var passed to thread. May it get reclaimed by GC???

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 08/31/04


Date: Tue, 31 Aug 2004 21:42:01 +0100

Bob Rock <pelledoca@letterboxes-dot-org.no-spam.invalid> wrote:
> my questiong is, I believe, very simple.
> I have a method and inside it I'm passing a local variable (of a
> reference type) to a newly created thread (created inside the method
> itself). Since the method may end while the thread may not have yet
> completed its work, I was wondering if anything must be done to avoid
> the garbage collector reclaiming the variable before the thread has
> completed.

If the other thread has a reference to the object, you needn't worry
about the garbage collector reclaiming it early.

-- 
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Relevant Pages

  • Local var passed to thread. May it get reclaimed by GC???
    ... my questiong is, I believe, very simple. ... I have a method and inside it I'm passing a local variable (of a ... reference type) to a newly created thread (created inside the method ... Bob Rock ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Passing by ref or by value
    ... I think String is a reference type. ... Passing a reference type by value means what? ... > If you wanted to pass a struct to a method solely to supply needed ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Can a ref parameter be saved for later use?
    ... but in this scenario the 'passing back' will have to happen later. ... It's only if you need access to the actual variable passed to the method that you need the ref keyword, and for a reference type this would only be needed if you want to replace the object with a completely new object. ... stringstrLstFromCaller; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Passing an object reference 1000 times
    ... Nicholas Paldino ... i do know i am passing a *reference* to the object; ... >> I think that the assumption you are making is that when you are>> passing a reference type around, you are copying it as you make the call ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: new operator
    ... managed on the heap. ... Passing a value type ByRef = a pointer to the value is passed ... Passing a reference type ByVal = a copy of a pointer to the object is passed ...
    (microsoft.public.dotnet.framework)