Question on Threading

S

Steve W

I have the something like the following code to start a new thread :

Sub StartThread()
Dim oProcessingObject As New MyObj.MyClass
Dim oThread As Thread
Dim oSomeObject as New SomeObject.SomeClass
oSomeObject.Property = "A value"

oThread = New Thread(AddressOf MyObj.MyClass)
oProcessingObject.oPropertySomeObject = oSomeObject
oThread.Start()

End Sub

Do I need to worry about how oSomeObject is destroyed ? Will the garbabge
collector simply clear it up when the thread has finished ?

Thanks

Steve
 
C

Cor Ligthert

Steve,

When it is not special said you never should have to concern about how an
object is destroyed. Therefore it is managed code.

The link bellow is a large text. Where you probably can read it, what is not
in this text is that any class (by instance your form) that implements
Idisposable and where components are created in the right way there these
components (including the so called unmanaged resources) are destroyed
afterwards.

However it is advice by instance to dispose large objects as bitmaps by code
as well as a database connection where as far as I knowthey have coded
something extra in the dispose for the connectionpooling, and there are some
more.

http://msdn.microsoft.com/architecture/default.aspx?pull=/library/en-us/dnpag/html/scalenet.asp

I hope this helps?

Cor
 
H

Herfried K. Wagner [MVP]

* "Steve W said:
I have the something like the following code to start a new thread :

Sub StartThread()
Dim oProcessingObject As New MyObj.MyClass
Dim oThread As Thread
Dim oSomeObject as New SomeObject.SomeClass
oSomeObject.Property = "A value"

oThread = New Thread(AddressOf MyObj.MyClass)
oProcessingObject.oPropertySomeObject = oSomeObject
oThread.Start()

End Sub

Do I need to worry about how oSomeObject is destroyed ? Will the garbabge
collector simply clear it up when the thread has finished ?

If 'oSomeObject' is "destroyed" doesn't have anything to with the thread
you start. If there are no references to the object when the end of
'StartThread' is reachted, the GC will be allowed to destroy the object
in a cleanup pass.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top