|
-
Mar 2nd, 2011, 07:33 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Preventing OutOfMemoryExceptions
Hello all,
I'm loading a particulary large database (access 2003, oledb) into a few seperate DataGridViews in my program (64,000 records in one table, 120,000 records in another, each record with >40 255-character strings), and am starting to get System.OutOfMemory exceptions, usually during mundane tasks (for instance, the code below, simply determining the minimum value in one of the the columns).
Code:
int minimumID = -10000;
foreach (DataGridViewRow row in dEditMain.Rows)
{
if (row.Cells[1].Value != null)
{
if ((int)row.Cells[1].Value < minimumID)
minimumID = (int)row.Cells[1].Value;
}
}
I've tried replacing the foreach with a for loop and even breaking it into several loops, under the (apparently mistaken) apprehension that the foreach was loading the entire list of DataGridViewRows into memory. It didn't help.
Some of the other loops also use int.Parse(row.Cells[1].Value.ToString()) instead of casting (a holdover from a previous version, in which the numbers were stored as strings). Would replacing these with (int)casts aid the memory situation?
Watching the "Memory (Private Working Set)" column in task manager, the process seems to be allocating 20MB just running, 490MB after the first table is loaded into memory (via a Fill() command), 850MB after the the second is loaded, and shooting up to 1350MB and then failing when a few loops similar to the one above are run.
What are the best-practices for dealing with something like this? Would compiling for x64, or for .Net 3.0, help?
Any help or suggestions would be appreciated. Thanks,
Qu.
Last edited by Quasar6; Mar 2nd, 2011 at 07:34 PM.
Reason: typos
"Why do all my attempts at science end with me getting punched by batman?" xkcd.
| Pong| |
Sorry for not posting more often.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|