none
System.OutOfMemoryException: Insufficient memory to continue the execution of the program.

    Question

  • On occasion we get these errors, and, we are showing huge images and do have memory issues in our app which we have talked to MS support and are dealing with, but when these happen, we can't catch it nor and the app freezes up... any ideas?

     

    System.OutOfMemoryException: Insufficient memory to continue the execution of the program.
       at System.Windows.Media.Composition.DUCE.Channel.SyncFlush()
       at System.Windows.Media.MediaContext.CompleteRender()
       at System.Windows.Interop.HwndTarget.OnResize()
       at System.Windows.Interop.HwndTarget.HandleMessage(Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       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)

     

    Thursday, January 27, 2011 5:02 PM

Answers

  • Hi dan,

    Welcome to the MSDN forums. MSDN Forum support and MS support are two channels, so we may provide the different reply for you.

    And regarding to the OutOfMemoryException exception, first, please ensure the data size of the images you use. As we know, a process can use 2GB memory in a 32-bit platfrom. For monitoring the memory useage, I recommend to use VMMap or Windbg to view the memory space, VMMap can show the different kinds of the memory type and we could check which space is fully used. By the way, we could use Windbg to check the objects in the memory heap, please refer to the following tutorial about Windbg:

    For a solution, I think we could design to show the large image by a different way. Please try to separate the large image, and we could display them by DrawingVisual in the different regions. Please refer to this document: http://msdn.microsoft.com/en-us/library/ms742254.aspx such as:

    using (DrawingContext dc = drawingVisual.RenderOpen())
    { 
     bi = new BitmapImage();
     bi.BeginInit();
     bi.UriSource = new Uri(one image part's path); // Or load it by Stream
     bi.EndInit();
     dc.DrawImage(bi, new Rect(the corresponding region));
    }
    

    And then we could load the parts which we can view first, the other parts can be loaded if user requests to view. Such as Dynamic Loading.

    Sincerely,


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, January 28, 2011 3:02 AM

All replies