|
The following statement throws an Out of Memory exception when count is large (I saw this for count = 44 million) (Note that I am using virtual mode to populate only the visible cells) dataGrid.RowCount = count; I want to modify this as follows : try { dataGrid.RowCount = count; } catch (OutOfMemoryException){ // set count to reasonable value count = reasonable_value; ShowMessage ("Showing only {0} rows", count); dataGrid.RowCount = count; } My question is : What is a reasonable row count here. The documentation for datagridview doesnt put any max value on the row count a datagrid can have, but in practice there is a memory limitation. What is the best way to work around this problem |
| pqr Wednesday, June 17, 2009 12:19 AM |
Hi pqr, 44 million? How much physical memory do you have? .NET won't limit the number of the rowcount, I think it is the memory and the operating system will limit that. Sincerely, Kira Qian Please mark the replies as answers if they help and unmark if they don't. |
| Kira Qian Thursday, June 18, 2009 9:05 AM |
I am on a 32-bit system with 2 GB memory. I do understand that .Net doesn't limit the rowcount. As I said (and you agree) that there is a memory limitation because DataGridView uses up too much memory even in virtual mode. I'm looking for a workaround to this problem. Do you have any suggestions? By the way, this is the stack trace when the OutOfMemoryException occurs : Are there any other DataGridView members that I should set to particular values to reduce memory consumption ? mscorlib.dll!System.Collections.ArrayList.Capacity.set(int value) + 0x23 bytes mscorlib.dll!System.Collections.ArrayList.EnsureCapacity(int min) + 0x26 bytes mscorlib.dll!System.Collections.ArrayList.Add(object value = {DataGridViewRow { Index=-1 }}) + 0x1e bytes System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRowCollection.AddCopiesPrivate(System.Windows.Forms.DataGridViewRow rowTemplate = {DataGridViewRow { Index=-1 }}, System.Windows.Forms.DataGridViewElementStates rowTemplateState = Visible, int count = 44175677) + 0x54 bytes System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRowCollection.Add(int count) + 0x272 bytes System.Windows.Forms.dll!System.Windows.Forms.DataGridView.RowCount.set(int value) + 0x315 bytes
|
| pqr Thursday, June 18, 2009 4:39 PM |
I guess my question would be what a user would ever do with 44 million rows of data. That is *WAY* too much to comprehend from a user perspective. Why not provide some filtering features so that the user gets a more reasonable amount of data. That would be a work around for this problem. www.insteptech.com
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS! |
| DeborahK Thursday, June 18, 2009 4:55 PM |
Thanks for your suggestion. If you look at my original post, I wanted to understand what would be a good value for "a more reasonable amount of data". I need a way to ensure I do not run into OutOfMemory exception. Any ideas? |
| pqr Thursday, June 18, 2009 5:04 PM |
My first thought is what *I* would want to see if I was a user. When I google, I look at my first 20 or so options. I would not want to begin to look at all 45,435 entries that it may have returned.
So I would think about it this way ... based on the goals of your application, what would be a reasonable amount of data a user would want to look at. I would guess that it would be under 1000 rows, which should never have any memory issues on any type of usable computer these days.
Don't know if this helps at all. www.insteptech.com
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS! |
| DeborahK Thursday, June 18, 2009 5:15 PM |
The analogy doesn't hold for my application because the relevance of the google search results diminishes dramatically past a certain point (first few pages like you said). I need to be able to scroll to a particular row and inspect the data there. The virtual mode in DataGridView promises that you only need to hold the currently visible rows in memory and I spent a lot of effort to ensure that I page the relevant part of my data from disk to memory when needed. Now I'm running into an issue where the datagridview memory consumption is a function of the total row count and not the visible row count, which, I think, is a design flaw in the datagridview control. I'm now trying to figure out a way to ensure that I still can display a subset of the information I need to, but I'm having a difficult time figuring out the size of the subset - 90%? 50%?? |
| pqr Thursday, June 18, 2009 5:37 PM |
I think the thread in web page "http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/243a81e7-909b-4c8e-9d28-6114248cf66e" can help you ----------------------------------------------------------------- Sabrina Gage http://www.comm100.com/livechat/Microsoft Certified Partner |
| Sabrina Gage Thursday, September 24, 2009 1:09 AM |
You just referred to this page's URL.
|
| pqr Thursday, September 24, 2009 2:17 AM |