473,770 Members | 6,158 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Pro cess.GetProcess es

Dim lv As New ListViewItem

Try

lv.Text = oProcess.MainMo dule.ModuleName

lv.SubItems.Add (oProcess.Id.To String)

lv.SubItems.Add (oProcess.Start Time.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 1676
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_erasebackgro und

When I am updating the listbox I set the blnUpdatingCont rol = true from the
form class code; this prevents it from flickering.
Public Class CLS_SC_listview

Inherits ListView

Public blnUpdatingCont rol 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 blnUpdatingCont rol = 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.co mwrote in message
news:ef******** ******@TK2MSFTN GP03.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.Pro cess.GetProcess es

Dim lv As New ListViewItem

Try

lv.Text = oProcess.MainMo dule.ModuleName

lv.SubItems.Add (oProcess.Id.To String)

lv.SubItems.Add (oProcess.Start Time.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
4759
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 that displays items in a ListView control that is running on a Windows 98 SE machine. The machine is well within system specifications for the .Net Framework. It is a 600 MHz with 128 MB of RAM, and also has the Resource Meter application installed....
1
5971
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. I would like to assign each control to a listview object, however I get a type mismatch. Further investigation reveals that the type of the control is "Custom Control" and not a listview. I would like to be able to work with real control object's...
1
1208
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 you focus the form or pass the mouse in/out the ListView, the memory used by the application increases. And, besides that, the start memory used is about 12MB. Isn't that a little big? Word uses about 8MB.
0
2241
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 hogged like crazy. I know this is where the memory problems occur because I've gone through that whole comment/check the ram thing. Here's the source of where the problem occurs: Public Shared Sub FillImageList(ByVal dir As String, ByVal...
7
15004
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 MyList data is resident in a dataset table. I'm stuck and can't choose either because. If I choose ListView as my control I don't understand how to programmatically get the data from the dataset table
3
1909
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 single PC but a pain in the ass at a Terminalserver when 20-25 Users start the program (25*100 = 2500 MB). We made some analysis:
12
3413
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. Very simple. I would like to create listviewitem's for display in a listview control. The listview items need to contain properties from Internet Explorer windows i've managed to collect into an arraylist.
2
5064
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 application monitors all the textboxes and other input & display controls on that application. The data from the textboxes and listboxes are retrived fine. But, when it comes to Listview there I got memory exception. I know that I need to do the in memory...
4
4516
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 is that when clicking on the "Show details" button the ListView for the appropriate row binds in the codebehind and displays the detail data for the selected row. I did something similar with a gridview control previously, but want to be able to...
0
9592
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10231
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10005
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7416
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5452
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3972
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.