strange "Out of memory" exception on Close
Hi all, I am experiencing a strange "out of memory" exception when I close my app. All it does, is load a really large text (1 million characters) via stream reader from a .txt file into a rich textbox. The app takes ~80MB of RAM according to Task Manager.
The loading itself does not cause any problems / exceptions but when I close the app, the following exception occurs:
http://img490.imageshack.us/img490/7...sposing5wr.jpg
I tried myStreamReader.Close and RichTextBox1.Text = Nothing and still get the same exception.
When I run the app outside the IDE and then close it, it flickers for a second and closes normally without crashing. My guess is, this flickering is the exception.
The output from the debugger:
"
An unhandled exception of type 'System.OutOfMemoryException' occurred in mscorlib.dll
Unhandled Exception: OutOfMemoryException.
The program '[984] Chain' has exited with code 0 (0x0).
"
Any ideas how to prevent that thing, it can have some unknown strange effects later if I simply decide to ignore it.
Regards
Re: strange "Out of memory" exception on Close
Can you tie the exception to any particular line or section of code that YOU wrote? This error is often the result of a recursive call, usually an unintentional recursive call. This might happen if some action triggered an event which re-triggered the action, etc. However, if that was the case, you should be able to look at the stack trace when the exception occurs and find a massive set of repeat calls to a few functions.
1 Attachment(s)
Re: strange "Out of memory" exception on Close
Nope, the stack looks clear (screenshot attached). I have no idea even where to begin searching. What is this "+0x10 bytes"?
Re: strange "Out of memory" exception on Close
I have never really dealt with that portion of the stack, but I would assume that the line means: 16 bytes into line 28. I would think that would have to do with the intermediate language rather than what you wrote, but either way I don't think it is all that valuable in this case.
Do you have anything in the....uhhh....whatever event fires when the form closes? I have the feeling that what is happening is that some resource is not being freed up, though I'm not sure what.
One ugly possibility would be to wrap the Form1.Show in a Try....Catch block that does nothing when an exception is caught. You should be able to hide the message this way, but catching an exception is slow, so you will incur a cost. Therefore, this is a cosmetic fix at best.
Re: strange "Out of memory" exception on Close
Are you referencing any external dll's by chance?
Re: strange "Out of memory" exception on Close
Nope, a single app with a single form. 2 similar richtextboxes, both get populated with the same number of characters(they are different though) and in similar way (with same code). When I populate the first one I get the error, when I populate the second one - no error. When I fill both I get the error again.
Since I can't isolate the cause, the only successful workaround so far is pretty lame:
VB Code:
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
[COLOR=Red]RichTextBox1.Text = Nothing[/COLOR]
MyBase.Dispose(disposing)
End Sub
I'd like to treat the cause, not just the symptom :confused: