We are using WinListView to show list of messages. Its using too much RAM, and if there are more than 15,000 items, the application will crash. Each item in the list has 7 subItems
from my test - 2800 items will cause application footprint to take 370Mb of ram. and if I try to load 17000, application takes 1.8gb of ram, and crashes with OutOfMemory exception.
We used version 2010.3, I updated to version 2012.1 but Listview seems to behave the same.
What should I do?
This is a snippet:
lvMessage.SuspendLayout()lvMessage.Items.Clear()lvMessage.BeginUpdate()For Each M In Messages item = New Infragistics.Win.UltraWinListView.UltraListViewItem lvMessage.Items.Add(item) PopulateMessage(item, M) 'populate subitems here If selectedMessage IsNot Nothing AndAlso selectedMessage.ID = M.ID Then selectedItem = item End IfNextlvMessage.EndUpdate()
yes .. that worked .. created predifned apperances and RAM usage went down to 100mb
Hello ,
Thank you for the provided code snippet . As far as I can see from your PopulateMessage function you are adding a lot of images to your SubItems and I think that this is the reason for a large amount of ram, because when you add an image, font and etc. to the default appearance object, the component should create a new instance of appearance object. When you have 2800 items, it is about 2800*7 (because you are setting an image on almost each sub item) appearance objects, loaded in the ram, and each of them contains an image (which is ram consuming resource). So my suggestion is to create several appearance object, which you could reuse them. Please implement this suggestion and let me know for the results.
I am waiting for your feedback.
Also, if I clear items and try to repopulate, ram usage almost doubles. when theoretically garbage collection should release memory from cleared items, and reuse for new items.
This the PopulateMessage function that is being called in the loop. I also tried not to reference any images, or not to populate Tag property, but result was only different by few hunder kB.
Private Sub PopulateMessage(ByVal item As Infragistics.Win.UltraWinListView.UltraListViewItem, ByVal Message As SCE.SCEInterfaces.IMessage) item.Tag = Message If folderBar.ActiveItem IsNot Nothing Then Select folderBar.ActiveItem.Key Case "Sent", "Draft", "Ready To Send", "Send Errors" item.SubItems("From").Value = Message.SendTo Case Else item.SubItems("From").Value = Message.SenderEmail End Select End If item.SubItems("Subject").Value = Message.Subject item.SubItems("Received").Value = Message.CreateDate If Message.Folder IsNot Nothing Then item.SubItems("Folder").Value = Message.Folder.Name Else item.SubItems("Folder").Value = "" End If If Message.Attachments.Count > 0 Then item.SubItems("Attachment").Appearance.Image = My.Resources.attach Else item.SubItems("Attachment").Appearance.Image = Nothing End If Select Case Message.HighlightColor Case SCE.eMailMessageColor.None item.SubItems("Important").Appearance.Image = My.Resources.bullet_white Case SCE.eMailMessageColor.Blue item.SubItems("Important").Appearance.Image = My.Resources.outlook_flag_blue Case SCE.eMailMessageColor.Green item.SubItems("Important").Appearance.Image = My.Resources.outlook_flag_green Case SCE.eMailMessageColor.Orange item.SubItems("Important").Appearance.Image = My.Resources.outlook_flag_orange Case SCE.eMailMessageColor.Red item.SubItems("Important").Appearance.Image = My.Resources.outlook_flag_red End Select If Message.SendDate > #1/1/2000# Then item.SubItems("Sent").Value = Message.SendDate Else item.SubItems("Sent").Value = "" End If If Message.LastReadDate > #1/1/2000# Then item.SubItems("Last Read").Value = CDate(Message.LastReadDate.ToShortDateString) Else item.SubItems("Last Read").Value = Nothing End If
If Message.Type = SCE.eMailMessageType.Incoming And Message.LastReadDate < #1/1/2000# Then item.Appearance.FontData.Bold = Infragistics.Win.DefaultableBoolean.True item.Appearance.Image = My.Resources.mail_new Else item.Appearance.FontData.Bold = Infragistics.Win.DefaultableBoolean.False Select Case True Case Message.IsDraft item.Appearance.Image = My.Resources.mail_draft Case Message.ForwardedMessage IsNot Nothing item.Appearance.Image = My.Resources.mail_forward Case Message.RepliedMessage IsNot Nothing item.Appearance.Image = My.Resources.mail_reply Case Else item.Appearance.Image = My.Resources.mail End Select End If End Sub
I have tried to replicate your issue on my end, based on your code snipped (please see attached sample), but it seems that this issue is not so simple and it couldn't be replicated only based on the code snipped. Please modify my sample or provide a small sample, in order to be able to reproduce this issue on my end and to investigate this further for you.
I am waiting for your feedback