473,387 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Life of a thread

Hi,
If a thread goes out of scope and the working proc (ThreadStart) is done
processing, does it eventually get finalized just like unreferenced memory?

thanks!
Nov 17 '05 #1
2 1421
thread with in method Foo, and this thread is referenced by a local
variable... will the thread be finalized after it has completed it’s work and
the local reference has gone out of scope?

Then yes, once you start a thread, it can run independently of it’s
reference, but when both are gone (ie no remaining reference), then the
thread will be eligible to be GCed and you can expect to have that happen.
"Zeng" wrote:
Hi,
If a thread goes out of scope and the working proc (ThreadStart) is done
processing, does it eventually get finalized just like unreferenced memory?

thanks!

Nov 17 '05 #2

"Zeng" <Ze******@hotmail.com> wrote in message
news:ef**************@TK2MSFTNGP10.phx.gbl...
Hi,
If a thread goes out of scope and the working proc (ThreadStart) is done
processing, does it eventually get finalized just like unreferenced
memory?

thanks!

Yes. Unless, of course, you have unmanaged resources (like a database
connection) in the thread. Then you may eventually wind up with a
noticeable leak. You can use a class to govern the thread. Make sure it
inherits : IDisposable and add a ~Destructor to handle all unmanaged
resources.

You may also want to run the worker thread with the IsBackground property
set to true so destruction happens immediately if the main app is
terminated.

J. Buelna - Houston, TX
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Paul | last post by:
In real life situation, do we ever come across a situation where we would need two base objects in an object. A snippet is worth 1000 words (: so... class Base { }; class Derived1:public Base...
3
by: Keyee Hsu | last post by:
Hi, I have a C# app that creates an AppDomain, enters it, and spawns an asyn thread to do some work and then block itself. Upon the completion of the work, the async thread supposedly terminates,...
1
by: muhamad | last post by:
hi i use the com AxShockwaveFlashObjects and i use a thread ,in the thread i use this object ,if i can't use this more than 5 minutes ,i get a error i think the problem is in the life time...
3
by: bb | last post by:
Hi, Have a query regarding the life of temporaries. Here is the code... class MyNumber { public: MyNumber(int n) : n(n) { cout << "Object Constructed." << endl; }
14
by: Shimon Sim | last post by:
I have a static variable defined something like this private static Dictionary<string, string> roles = new Dictionary<string,string>(); Can I safely assume that it will be live for the live of...
7
by: salad | last post by:
It just turned to May 26th in my time zone. At 15:00 I'll be saying my marriage vows. I expect there'll be some personal changes in my life...going from single to hitched. Another adventure in...
6
by: Sid Price | last post by:
I have been reading about the managed heap and garbage collection and I have a question. I have a class that has a very simple task and that is to send a UDP message to a remote computer. The...
2
by: slapsh0t11 | last post by:
So, I've been working on this Game of Life (http://www.bitstorm.org/gameoflife/) project, and all the code has been written. However, it will not run. First, I will post the error message and the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.