Mike,
After changing my program to allocate fewer objects, the probelm seems to
be resolved. However, when I add some functionality that we will need in
the near future and thereby increase the memory usage, I receive
OutOfMemoryException exceptions after reaching about 400 MB of VM Memory
usage by my process. I took a look at the KB article you referred to and I
may be having a similar problem. As a test, I wrote the following console
application:
public static void Main(string [] args)
{
try
{
byte[] bytes = new byte[300000000];
//byte[] bytes = new byte[218099999];
Console.ReadLine();
}
catch(Exception ex)
{
Console.WriteLine(ex);
}
}
If run as written, the application throws an OutOfMemoryException.
However, if the commented out line is commented in and the previous line
is commented out (thereby reducing the memory allocation), I get an
OutOfMemoryException. Adding one (as the article suggests) to the
allocation amount does not fix the problem. If I were simply getting
errors when allocating byte arrays, I could change them until I found a
number that worked, but my OutOfMemoryException errors are coming from
framework code (Dictionary.Add and
SqlConnection.CheckForDroppedConnection, for example). Any idea if the
hotfix mentioned in the article will fix my problems? Thanks!
Regards,
- Ben Blair
{my name} {at} acm.org
----- Michael Giagnocavo [MVP] wrote: -----
Well, are you using more memory than the machine has?
I'm only
asking
because you said typically uses 500MB, leading me to think that there
could
be a bug in the code that makes the memory usage spiral up and boom.
This was just posted in another newsgroup (OutOfMemoryExceptions on
V1.1 of
the framework). Maybe your code is experiencing it?
MORE INFORMATION
The problem is not limited to the RichTextBox control. The problem may
also
occur with certain large memory allocations. For example, the
following code
also results in an "Out of memory" exception error message:
byte[] arr = new byte[16773053];
To work around this problem, add a single byte to this allocation.
http://support.microsoft.com/?kbid=826981
-mike
MVP
Ben Blair said:
I've written a .NET application that typically uses about 500MB of memory.
After running for anywhere from 20 minutes to a few hours, the application
crashes with "Fatal out of memory error" printed on the console. The CLR
does not appear to raise the OutOfMemoryException before the application
crashes. The machines running this application all have 1GB physical
memory. Since the application simply quits (even while being debugged) I
am unsure of how to best debug the problem. A quick search of the
newsgroups has turned up little help. Any suggestions would be
appreciated. Thank you.
{My Name} {at} acm.org