Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7982943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:49:04+00:00 2026-06-04T10:49:04+00:00

Should I explicitly set thread reference to null after thread completes it’s work or

  • 0

Should I explicitly set thread reference to null after thread completes it’s work or it’s not necessary? If I want to set it as null then where in the code should I do this?

Should I check if thread is alive or not using thread.isalive flag and then set it to null if it’s not alive?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T10:49:05+00:00Added an answer on June 4, 2026 at 10:49 am

    Should i explicitly set thread reference to null after thread
    completes it’s work or it’s not necessary?

    Personally, I would not bother. There are a few cases where explicitly setting object references to null really matters anyway. Regardless of type those cases are:

    • If the variable is a static member and the object it references consumes a lot of memory.
    • If the variable is an instance member contained within a longer living object which references an object that consumes a lot of memory.
    • If the variable is a local to a long running method which references an object that consumes a lot of memory.1

    Those are the ones I could think of. Perhaps there are more, but probably not many. The common denominator here is that the variable references an object that consumes a lot of memory. The managed Thread object itself is not going to consume a lot of memory so I cannot imagine that setting a variable of type Thread to null is going to accomplish a whole lot for you regardless of how it is used. Most of the resources are allocated when the thread starts and then get deallocated when the thread ends.

    Should i check if thread is alive or not using thread.isalive flag and
    then set it to null if it’s not alive.

    I prefer to use Thread.Join to test and wait for the completion of a thread. In fact, I have never used Thread.IsAlive for anything useful…ever.


    1The GC is actually smart enough to dispose local object references before a method ends if it can detect that the reference is no longer used.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

should be simple right? but have not found any anwsers :
Should model objects that go to the view be checked for null before going
Should entry_set be cached with select_related? My DB is still getting calls even after
Should a business object contain a reference to other objects (as in the id
I have a thread that sits in a blocking recv() loop and I want
I'm a little confused. I haven't explicitly set the Web.config <pages ViewStateEncryptionMode=Always /> ,
I have a table that has a smalldatetime NOT NULL field with a default
I have a JSF ManagedBean which has a property that should be set by
An open source JavaScript project I work on includes code: if (color) { tapeDiv.style.backgroundColor
Should I need to have explicit custom ID attribute as PK for each of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.