F
fniles
I am using VB.NET 2008.
My application has many clients that connect to it using socket.
When a client connect to it, it creates a session class and runs a
thread for that session class.
When a client disconnect from it, I set the socket and all the
variables inside that session to nothing before I EXIT SUB from that
session.
After the client disconnects, the memory usage didn't go back to
before the client connected. There is about additional 200 K of memory
loss. For example: before the client connects memory usage of my
program is 35,544 K, after the client connects it was 36,004 K, and
after the client disconnects it was 35,756 K, which is about 200 K
more than before the client connects.
What would cause this and is there a way to clean up the memory ?
(again, before EXIT SUB out of the session, I clear, dispose and set
all variables to nothing).
When I END SUB in the Sub ThreadMain of the SessionClass, does it get
rid of the SessionClass (like setting it to nothing) and its thread ?
Thank you.
This code is called when a client connect to the program
Dim oSession As SessionClass
Dim oThread As Threading.Thread
Static nSession As Long
nSession = nSession + 1
oSession = New SessionClass
oSession.Socket = Sock
oSession.Handle = 0
oThread = New Threading.Thread(AddressOf oSession.ThreadMain)
oThread.SetApartmentState(ApartmentState.STA)
oThread.Name = CLng(nSession)
oThread.Start()
This is the code in the SessionClass
Public Class SessionClass
Private Quotes As New Queue
Private QuotesSync As Queue = Queue.Synchronized(Quotes)
Public Socket As SocketTools.SocketWrench
Public Handle As Integer
Public Sub ThreadMain()
Socket.AttachThread()
Do While Not Terminated
If Socket.IsReadable Then
End If
If Socket.IsClosed Then
Exit Do
End If
Loop
Socket.Disconnect()
Socket.Dispose()
Socket = Nothing
Quotes.Clear()
QuotesSync.Clear()
Quotes = Nothing
QuotesSync = Nothing
Exit Sub
End Sub ------------->>>>> does it get rid of the SessionClass and
its thread ?
Public Sub Terminate()
Terminated = True
End Sub
End Class
My application has many clients that connect to it using socket.
When a client connect to it, it creates a session class and runs a
thread for that session class.
When a client disconnect from it, I set the socket and all the
variables inside that session to nothing before I EXIT SUB from that
session.
After the client disconnects, the memory usage didn't go back to
before the client connected. There is about additional 200 K of memory
loss. For example: before the client connects memory usage of my
program is 35,544 K, after the client connects it was 36,004 K, and
after the client disconnects it was 35,756 K, which is about 200 K
more than before the client connects.
What would cause this and is there a way to clean up the memory ?
(again, before EXIT SUB out of the session, I clear, dispose and set
all variables to nothing).
When I END SUB in the Sub ThreadMain of the SessionClass, does it get
rid of the SessionClass (like setting it to nothing) and its thread ?
Thank you.
This code is called when a client connect to the program
Dim oSession As SessionClass
Dim oThread As Threading.Thread
Static nSession As Long
nSession = nSession + 1
oSession = New SessionClass
oSession.Socket = Sock
oSession.Handle = 0
oThread = New Threading.Thread(AddressOf oSession.ThreadMain)
oThread.SetApartmentState(ApartmentState.STA)
oThread.Name = CLng(nSession)
oThread.Start()
This is the code in the SessionClass
Public Class SessionClass
Private Quotes As New Queue
Private QuotesSync As Queue = Queue.Synchronized(Quotes)
Public Socket As SocketTools.SocketWrench
Public Handle As Integer
Public Sub ThreadMain()
Socket.AttachThread()
Do While Not Terminated
If Socket.IsReadable Then
End If
If Socket.IsClosed Then
Exit Do
End If
Loop
Socket.Disconnect()
Socket.Dispose()
Socket = Nothing
Quotes.Clear()
QuotesSync.Clear()
Quotes = Nothing
QuotesSync = Nothing
Exit Sub
End Sub ------------->>>>> does it get rid of the SessionClass and
its thread ?
Public Sub Terminate()
Terminated = True
End Sub
End Class