473,386 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

memory issuse with listview control?

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.
Dec 29 '06 #1
1 1656
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.


Dec 29 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: David Miller | last post by:
Hello, I posted this to DotNet.Framework.Controls a week ago or so and got no response, so now I will repost it here to see if anyone here knows anything about it... I have an application...
1
by: Welie | last post by:
Hi all- I am using a listview (MSComctlLib.ListViewCtrl.2)on an Access form. Actually there are six listviews on the form. I need to do the same thing to all six forms so I have the loop below....
1
by: Bruno Rodrigues | last post by:
Hi, I'm having several memory leaks in my Windows Form (C#). Testing, I found a curious thing: Put a ListView control in a Windows Form, run the project and start the TaskManager. Each time...
0
by: Chris Putnam | last post by:
I am working on an application that includes a feature where a directory is spidered and thumbnails are displayed. I have it pretty much down, but when the bitmaps are loaded from file, memory is...
7
by: BobAchgill | last post by:
I am trying to decide which of these controls to use to implement letting my user select a full row from MyList. The MyList has several columns which would be nice to sort by at run time. The...
3
by: Alexander Overmann | last post by:
Hello, currently we encounter several huge memoryproblems running .NET C# Applications under Windows Terminal Servers/Citrix. Sometimes the program claims 100 MB which is not very much at a...
12
by: garyusenet | last post by:
I have had no replies to my previous post so perhaps I didn't write it good enough. Please excuse new thread but i wanted to break from the last thread hopefully this thread will be better. ...
2
by: =?Utf-8?B?SXJmYW4=?= | last post by:
Hello, It may be a repeated question but I don't find the solution to the situation that I encounter in it. My application is monitoring another application that is built in VB6. The...
4
by: Brian Gaze | last post by:
I have created a ListView control and have bound this to a datasource. Within the ItemTemplate of the ListView I have added another ListViewControl which is databound in the code behind. The idea...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.