Memory usage in VB.NET program

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
 
A

Armin Zingler

Am 03.03.2011 22:10, schrieb 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).

"Automatic Memory Management":
http://msdn.microsoft.com/en-us/library/f144e03t(VS.90).aspx

Does this answer the question?
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 ?

Yes, if there are no other references to the object.
 
F

fniles

Thanks.

I have 1 more question: what will be the reason that the memory usage
say is 124,560K, but the Virtual memory is 704,168 K ?
 

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