Re: Life of a thread

From: J. Buelna - Houston, TX (
Date: 03/22/05

Date: Tue, 22 Mar 2005 17:38:05 -0600

"Zeng" <> wrote in message
> 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

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

J. Buelna - Houston, TX

Relevant Pages

  • Re: Returning address of local variable
    ... real-world hardware) to unmap the memory when the variable ... out of scope, the whole concept of destruction is absent from plain C. ... destructor, when a auto storage variable of that type goes out of scope ...
  • Re: treeview in windowsdialog
    ... Before it goes out of scope it is clever to do use its dispose method to release the unmanaged resources. ... Therefore Yes it is wise to use the form.dispose as you have created that form new in your form and it will be go out of scope. ... Disposing ressources is something different. ...
  • Re: When a connection closes....
    ... but the destructor is not called until the GC get around to it (which ... by convention, ... resoures implements a Dispose method. ...
  • Re: Overcoming C# limitations
    ... You might as well have defined a CString and have a ... "hidden" destructor as you call it run when the function leaves. ... This would have been useful since I could use this macro in any scope ... knowing that the destructor of MyObj will be called at ...
  • Re: Is CArray best for this...
    ... CStringWgoes out of scope at function end, the memory is cleaned up by destructor, and so I think that the returned LPWSTR pointer is not valid. ...