4

I have a C#/WPF application that is meant to run on a small panel PC with 512 MB of memory. If it is left to run, an OutOfMemoryException is eventually thrown. This can take 12+ hours up to 2 days to happen.

Using both ProcessExplorer and .NET Memory Profiler, I see no evidence that the memory used by my application is growing over time. There is just a typical pattern of a little growth followed by garbage collection.

I've added code to print out all running processes and their memory information when the exception is thrown. I'm currently just waiting around for it to happen again. I should mention that PCs are flash based and paging is disabled. The 512 is a hard limit.

It has happened on two separate PCs. The exception information was the same in both cases:

Top Level Exception - System.OutOfMemoryException: Insufficient memory to continue the execution of the program.
    at System.Windows.Media.Composition.DUCE+Channel.SendCommand(Byte* pCommandData, Int32 cSize)
    at System.Windows.Media.MediaContext.EnterInterlockedPresentation()
    at System.Windows.Media.MediaContext.ScheduleNextRenderOp(TimeSpan minimumDelay)
    at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
    at System.Windows.Media.MediaContext.AnimatedRenderMessageHandler(Object resizedCompositionTarget)
    at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
    at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

Any insight is appreciated!

BabaBooey
  • 1,552
  • 3
  • 21
  • 38
  • 3
    Why do I get the feeling you have a rogue event subscription. – ChaosPandion Feb 17 '11 at 14:06
  • 4
    This kind of debugging can be very tricky, but you most likely would need to create a dump and analyze it. Tess has a great blog with lots of labs to get you started: http://blogs.msdn.com/b/tess/archive/2008/02/04/net-debugging-demos-information-and-setup-instructions.aspx – CodingInsomnia Feb 17 '11 at 14:07
  • @ChaosPandion - Damn those rogues! Can you elaborate? – BabaBooey Feb 17 '11 at 14:15
  • 1
    @Tim: rogue event subscription. When you create an object that listens to an event (i.e. `thing.event += this.eventHandler`). But when you abandon the object you don't un-subscribe from the event. So what happens is that your objects stay in memory because the event delegate maintains a reference. You have to do `thing.event -= this.eventHandler` to remove the reference. – Jim Mischel Feb 17 '11 at 15:18
  • When the OutOfMemory exception is thrown has the process actually consumed 512MB of memory or is there still memory free? – Tollo Feb 17 '11 at 15:28
  • @Tollo - Not sure since the app basically shuts itself down when the exception occurs. I've added code to intercept the exception and printout task manager-esque data. I'll update you when I get the crash again. – BabaBooey Feb 17 '11 at 15:33
  • I was going to say what Jim Mischel said. That's been the #1 cause of .NET out-of-memory mysteries for me. – Robert Rossney Feb 17 '11 at 19:05
  • 1
    If it was a case of rogue event subscription, wouldn't I see the app gradually bloating over time? I've been running the app on two systems throughout the day and watching them with ProcessExplorer. They have stayed between 32 and 33 MB all day. It's like suddenly, something goes BOOM. Keep in mind that the systems are being left untouched, so it's not as if some interaction with the app triggers the crash. – BabaBooey Feb 17 '11 at 22:23

3 Answers3

1

Since you are a 'small panel PC', maybe you are calling some non-'.Net' code to control some hardware. Is so, maybe that part of the program might be using a fair amout of memory (but still not leaking any). To get the garbage collector to work harder in that case, look into adding a GC.AddMemoryPressure() call.

jyoung
  • 5,071
  • 4
  • 30
  • 47
1

It turns out that a variety of issues were causing my application to crash. I've detailed them in another post here.

Community
  • 1
  • 1
BabaBooey
  • 1,552
  • 3
  • 21
  • 38
0

I came across a very good article that examines the error in depth.

WPF Render Thread Errors

The most telling paragaph: don't bother trying to analyze the call stack you're given:

Due to the design, unfortunately, the exception and callstack you see on the UI thread aren't typically helpful in diagnosing the true cause of the problem. This is because by the time the exception is thrown, it is already after the point of failure on the render thread. By this time, critical state has been lost on the render thread that would help us understand where and why the failure occurred.

Andrew Shepherd
  • 44,254
  • 30
  • 139
  • 205