Re: Life of a thread

From: J. Buelna - Houston, TX (jbuelna-not_at_microsoft...yet.com)
Date: 03/22/05


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


"Zeng" <Zeng5000@hotmail.com> wrote in message
news:efdWI4xLFHA.3812@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



Relevant Pages

  • 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. ...
    (microsoft.public.dotnet.languages.vb)
  • 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 ...
    (comp.lang.c)
  • 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. ...
    (microsoft.public.dotnet.framework.adonet)
  • 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 ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Why no language improvements?
    ... cleanup, then rethrow the exception, you just have the destructor ... cleanup when scope is exited... ... including when due to an exception. ...
    (borland.public.delphi.non-technical)