By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,422 Members | 1,275 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,422 IT Pros & Developers. It's quick & easy.

No stack trace for System.OutOfMemory

P: n/a
Instances of SystemOutOfMemoryException do not contain a stack trace. Easy
test to verify this:

class OOM
{
public static void Main() {
try {
Object[, ] arr = new Object[100000000, 10000000];
} catch (Exception ex) {
dumpEx(ex);
}
}

private static void dumpEx(Exception ex) {
Console.WriteLine("Exception occurred");
Console.WriteLine(ex);
String s = ex.StackTrace;
if (s == null)
Console.WriteLine("Stack trace is null");
else
Console.WriteLine("StackTrace length is " + s.Length);
}
}

Output:

Exception occurred
System.OutOfMemoryException: Exception of type System.OutOfMemoryException
was thrown.
Stack trace is null

This makes debugging these exceptions tricky, to say the least. I wound up
having to track down where the exception was being generated with
WriteLines. I know that you can trap these is Visual Studio as well, but
this one was touchy (it turned out to be a synchronization problem) and the
performance degradation from running an ASP.NET program inside Visual Studio
made it stop happening. Two questions:

1. Are there any tricks that I'm missing for debugging these more
effectively?

2. Can we expect to see stack traces in some future release?
Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
OutOfMemory exceptions sometimes occur because there's too much in the call
stack (i.e. if a function unconditionally recursively calls itself). In
that situation, the call stack IS the reason for the OutOfMemory exception,
and it wouldn't really make sense to have it available for examination.
Knowing which function caused the error is generally enough (I would think).
However, don't see any reason why a stack trace can't be supplied for the
error you're generating in the example. Sorry I don't have an answer for
you, just though I'd offer my insight.

Chris LaJoie
"Mike Schilling" <ms*************@hotmail.com> wrote in message
news:Ob**************@TK2MSFTNGP11.phx.gbl...
Instances of SystemOutOfMemoryException do not contain a stack trace. Easy test to verify this:

class OOM
{
public static void Main() {
try {
Object[, ] arr = new Object[100000000, 10000000];
} catch (Exception ex) {
dumpEx(ex);
}
}

private static void dumpEx(Exception ex) {
Console.WriteLine("Exception occurred");
Console.WriteLine(ex);
String s = ex.StackTrace;
if (s == null)
Console.WriteLine("Stack trace is null");
else
Console.WriteLine("StackTrace length is " + s.Length);
}
}

Output:

Exception occurred
System.OutOfMemoryException: Exception of type System.OutOfMemoryException
was thrown.
Stack trace is null

This makes debugging these exceptions tricky, to say the least. I wound up having to track down where the exception was being generated with
WriteLines. I know that you can trap these is Visual Studio as well, but
this one was touchy (it turned out to be a synchronization problem) and the performance degradation from running an ASP.NET program inside Visual Studio made it stop happening. Two questions:

1. Are there any tricks that I'm missing for debugging these more
effectively?

2. Can we expect to see stack traces in some future release?

Nov 15 '05 #2

P: n/a
OutOfMemory exceptions sometimes occur because there's too much in the call
stack (i.e. if a function unconditionally recursively calls itself). In
that situation, the call stack IS the reason for the OutOfMemory exception,
and it wouldn't really make sense to have it available for examination.
Knowing which function caused the error is generally enough (I would think).
However, don't see any reason why a stack trace can't be supplied for the
error you're generating in the example. Sorry I don't have an answer for
you, just though I'd offer my insight.

Chris LaJoie
"Mike Schilling" <ms*************@hotmail.com> wrote in message
news:Ob**************@TK2MSFTNGP11.phx.gbl...
Instances of SystemOutOfMemoryException do not contain a stack trace. Easy test to verify this:

class OOM
{
public static void Main() {
try {
Object[, ] arr = new Object[100000000, 10000000];
} catch (Exception ex) {
dumpEx(ex);
}
}

private static void dumpEx(Exception ex) {
Console.WriteLine("Exception occurred");
Console.WriteLine(ex);
String s = ex.StackTrace;
if (s == null)
Console.WriteLine("Stack trace is null");
else
Console.WriteLine("StackTrace length is " + s.Length);
}
}

Output:

Exception occurred
System.OutOfMemoryException: Exception of type System.OutOfMemoryException
was thrown.
Stack trace is null

This makes debugging these exceptions tricky, to say the least. I wound up having to track down where the exception was being generated with
WriteLines. I know that you can trap these is Visual Studio as well, but
this one was touchy (it turned out to be a synchronization problem) and the performance degradation from running an ASP.NET program inside Visual Studio made it stop happening. Two questions:

1. Are there any tricks that I'm missing for debugging these more
effectively?

2. Can we expect to see stack traces in some future release?

Nov 15 '05 #3

P: n/a

"Chris LaJoie" <ch***@etriptrader.com> wrote in message
news:Ow**************@TK2MSFTNGP09.phx.gbl...
OutOfMemory exceptions sometimes occur because there's too much in the call stack (i.e. if a function unconditionally recursively calls itself). In
that situation, the call stack IS the reason for the OutOfMemory exception, and it wouldn't really make sense to have it available for examination.
Sure, and it's also possible that the heap is exhausted so there isn't room
to construct a stack trace.
Knowing which function caused the error is generally enough (I would think). However, don't see any reason why a stack trace can't be supplied for the
error you're generating in the example.


Nor do I.
Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.