Valid object reference ?

  • Thread starter Thread starter Friskusen
  • Start date Start date
F

Friskusen

Hello VB.net programmers !

I'm just trying to understand what happens with an object which is
initialised
over and over again.

The code fragment below illustrates my problem. This code is simply a tcp
listener
which creates a new client object and starts a new thread inside that
object to
handle an incoming request.

But what happens when a new connection request arrives and 'the same'
client object
is initialized again ? I imagine that the 'old object' survives a clean up
as long as a thread still may be running with a reference to that object...

Running the code indicates that this is so, but i'm not sure....yet

Comments are welcome,

Thanks,
Frode


.....


Public Sub CheckQueue()
'============================================================
' Any clients knocking on my door ?
'
If MySocket.Poll(1000, SelectMode.SelectRead) Then
Select Case TcpService.ToUpper
Case "POP"
'Initialize a new PopClient..
Dim MyPop As New Pop3Client(MySocket.Accept, Idx)

'..and start a new thread to handle this client...
Dim MyThread As New Thread(AddressOf MyPop.NewClient)
MyThread.Start()

Case "SMTP"
Dim MySmtp As New SmtpClient(MySocket.Accept, Idx)
Dim MyThread As New Thread(AddressOf MySmtp.NewClient)
MyThread.Start()
End Select
ClientCount += 1
RaiseEvent StatusChanged(Idx)
End If
End Sub


......
 
Friskussen,

The answer is simple, an object lives in dotNet as long as that there is a
reference to it.

I hope this helps?

Cor
 
But is it still a reference to the object in this case ?

Or, to put it another way:

Does the thread keep a reference to the object ?

In that case, of course, my question is perfectly answered )

Nice weekend !
 

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

Back
Top