locked
ThreadStatic Garbage collection RRS feed

  • Question

  • If I use the <System.ThreadStatic()> attribute on a variable, will the variable be Garbage collected when the thread is done?

     

    Or will I have to implement this myself?

     

    Hope the question is clear enough; otherwise tell me and I will post an example.

     

    Thanks,

     

    Peter Haislund

    Thursday, April 10, 2008 7:41 AM

Answers

  • Hi

    If you are asking if this variable can be garbage collected after thread is done then the answer is yes.

    Thursday, April 10, 2008 1:35 PM

All replies

  • Hi

    If you are asking if this variable can be garbage collected after thread is done then the answer is yes.

    Thursday, April 10, 2008 1:35 PM
  •  

    I'm using this to keep track of session data.

     

    I have a server that clients connect to by sockets.

    I then have a variable like this:

    <ThreadStatic()> Private Shared _CurrentCallData As CommunicatorDataObject

     

    Which holds an Object containing data about the current call. When the call is finished I want to make sure that the data isn't using memory anymore.

     

    I'm using the sockets async so using BeginReceive() etc.

     

    Peter Haislund

    Friday, April 11, 2008 7:02 AM
  • pen_2 said:

    Hi

    If you are asking if this variable can be garbage collected after thread is done then the answer is yes.


    Peter: Have you confirmed this?
    Tuesday, February 17, 2009 8:05 AM