No worries,
I figured it out, and intresting that the application now starts out bieng
quite large in memory then gets smaller and smaller, I guessing that alot of
the objects used at the start of the application are eventually being freed
by the garbage collector thing.
the program now peaks at around 19 MB, then drops to about 9 MB over time
that I think people can live with.
Another thing with the Listview though class erases the background of the
controll before building the new list; this makes the ListView Flicker when
you are updating the information on a regular basis I found some code in C#
that exampled subclassing a textbox and making sure it was only numeric
input by discarding the window's messagess; I adapted it to VB and made it
discard wm_erasebackground
When I am updating the listbox I set the blnUpdatingControl = true from the
form class code; this prevents it from flickering.
Public Class CLS_SC_listview
Inherits ListView
Public blnUpdatingControl As Boolean = False
Private Const WM_ERASEBKGND = &H14
Protected Overrides Sub WndProc(ByRef message As
System.Windows.Forms.Message)
If message.HWnd = MyBase.Handle Then
Select Case message.Msg
Case WM_ERASEBKGND
If blnUpdatingControl = True Then
' Ignore paint message
Else
MyBase.WndProc(message)
End If
Case Else
MyBase.WndProc(message)
End Select
Else
MyBase.WndProc(message)
End If
End Sub
End Class
Regards,
Mike.
PS does anyone have good resources on using the system.runtime interop and
Marshalling.
"Michael M." <no****@mike.comwrote in message
news:ef**************@TK2MSFTNGP03.phx.gbl...
HI all,
When I add items to a Listview control, then clearing the items and adding
more items my program seems to allocate a few KB of data and then not free
the Memory. I noticed this about half way through writing a program and
it's driving me a bit mad. I have posted a sub function below that I
used to test this problem:
The Sub is called every 4 seconds by a timer object, every 4 the seconds
the memory usage of the program is incremented by arround 40K. if I leave
it running for 20 minutes it can get as large as 50 megabytes.
Test setup:
VB.net 2005 Express, with .net framework 2 on XP Pro service pack 2.
P4 CPU arround 3 Ghz
1 GIG of DDR memory.
Sub AddProcessData()
ListView1.items.clear()
For Each oProcess As Process In Diagnostics.Process.GetProcesses
Dim lv As New ListViewItem
Try
lv.Text = oProcess.MainModule.ModuleName
lv.SubItems.Add(oProcess.Id.ToString)
lv.SubItems.Add(oProcess.StartTime.ToString)
ListView1.Items.Add(lv)
Catch ex As Exception
End Try
lv = Nothing
oProcess = Nothing
Next
End Sub
Anyone know what's happening here? calling GC.Collect does not help
either.
I am new to .net programming so there is a good chance I am overlooking
something obvious
Regards,
Mike.