No stack trace for System.OutOfMemory

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike Schilling

    #1

    No stack trace for System.OutOfMemory

    Instances of SystemOutOfMemo ryException 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(Exceptio n ex) {
    Console.WriteLi ne("Exception occurred");
    Console.WriteLi ne(ex);
    String s = ex.StackTrace;
    if (s == null)
    Console.WriteLi ne("Stack trace is null");
    else
    Console.WriteLi ne("StackTrace length is " + s.Length);
    }
    }

    Output:

    Exception occurred
    System.OutOfMem oryException: Exception of type System.OutOfMem oryException
    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?


  • Chris LaJoie

    #2
    Re: No stack trace for System.OutOfMem ory

    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" <mscottschillin g@hotmail.com> wrote in message
    news:ObXYhuvgDH A.2400@TK2MSFTN GP11.phx.gbl...[color=blue]
    > Instances of SystemOutOfMemo ryException do not contain a stack trace.[/color]
    Easy[color=blue]
    > 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(Exceptio n ex) {
    > Console.WriteLi ne("Exception occurred");
    > Console.WriteLi ne(ex);
    > String s = ex.StackTrace;
    > if (s == null)
    > Console.WriteLi ne("Stack trace is null");
    > else
    > Console.WriteLi ne("StackTrace length is " + s.Length);
    > }
    > }
    >
    > Output:
    >
    > Exception occurred
    > System.OutOfMem oryException: Exception of type System.OutOfMem oryException
    > was thrown.
    > Stack trace is null
    >
    > This makes debugging these exceptions tricky, to say the least. I wound[/color]
    up[color=blue]
    > 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[/color]
    the[color=blue]
    > performance degradation from running an ASP.NET program inside Visual[/color]
    Studio[color=blue]
    > 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?
    >
    >[/color]


    Comment

    • Chris LaJoie

      #3
      Re: No stack trace for System.OutOfMem ory

      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" <mscottschillin g@hotmail.com> wrote in message
      news:ObXYhuvgDH A.2400@TK2MSFTN GP11.phx.gbl...[color=blue]
      > Instances of SystemOutOfMemo ryException do not contain a stack trace.[/color]
      Easy[color=blue]
      > 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(Exceptio n ex) {
      > Console.WriteLi ne("Exception occurred");
      > Console.WriteLi ne(ex);
      > String s = ex.StackTrace;
      > if (s == null)
      > Console.WriteLi ne("Stack trace is null");
      > else
      > Console.WriteLi ne("StackTrace length is " + s.Length);
      > }
      > }
      >
      > Output:
      >
      > Exception occurred
      > System.OutOfMem oryException: Exception of type System.OutOfMem oryException
      > was thrown.
      > Stack trace is null
      >
      > This makes debugging these exceptions tricky, to say the least. I wound[/color]
      up[color=blue]
      > 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[/color]
      the[color=blue]
      > performance degradation from running an ASP.NET program inside Visual[/color]
      Studio[color=blue]
      > 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?
      >
      >[/color]


      Comment

      • Mike Schilling

        #4
        Re: No stack trace for System.OutOfMem ory


        "Chris LaJoie" <chris@etriptra der.com> wrote in message
        news:OwgJmVxgDH A.1832@TK2MSFTN GP09.phx.gbl...[color=blue]
        > OutOfMemory exceptions sometimes occur because there's too much in the[/color]
        call[color=blue]
        > stack (i.e. if a function unconditionally recursively calls itself). In
        > that situation, the call stack IS the reason for the OutOfMemory[/color]
        exception,[color=blue]
        > and it wouldn't really make sense to have it available for examination.[/color]

        Sure, and it's also possible that the heap is exhausted so there isn't room
        to construct a stack trace.
        [color=blue]
        > Knowing which function caused the error is generally enough (I would[/color]
        think).[color=blue]
        > However, don't see any reason why a stack trace can't be supplied for the
        > error you're generating in the example.[/color]

        Nor do I.


        Comment

        Working...