none
OutOfMemoryException when resizing Window

    General discussion

  • We are developing a WPF application and it shows a strange behaviour. The Application works quite fine but when the window is enlarged or maximized, a OutOfMemoryException is thrown:

    System.OutOfMemoryException: There was not enough 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)
    


    In the case when the window is maximized, i can see the code line in the debugger that triggers the exception:

    		void PrismaFrame_Loaded(object sender, RoutedEventArgs eventArgs) {
    
    			var window = this.ParentWindow;
    			if (window != null) {
    				this.btnWindowClose.Click += (s, e) => window.Close();
    				this.btnWindowMaximize.Click += (s, e) => {
    					window.WindowState = WindowState.Maximized; // <<--- This line fires the exception
    					this.btnWindowMaximize.Visibility = Visibility.Collapsed;
    					this.btnWindowResize.Visibility = Visibility.Visible;
    				};
    
    				this.btnWindowResize.Click += (s, e) => {
    					window.WindowState = WindowState.Normal;
    					this.btnWindowResize.Visibility = Visibility.Collapsed;
    					this.btnWindowMaximize.Visibility = Visibility.Visible;
    				};
    
    				this.btnWindowMinimize.Click += (s, e) => {
    					window.WindowState = WindowState.Minimized;
    				};
    
    				this.PART_TitleBar.MouseDown += (s, e) => { if (((MouseEventArgs)(e)).LeftButton == MouseButtonState.Pressed) window.DragMove(); };
    			}
    		}
    



    I have no idea what i can do. Can you help?

    Regards,
    Jerma
    • Changed type Linda Liu Friday, October 23, 2009 3:34 AM No follow up from OP
    Friday, October 16, 2009 7:35 PM

All replies

  • It looks like you're using Windows Interop to host a native control in your Window.

    I'm guessing that it's having a problem during the resize.  It's difficult to diagnose without more info, but try temporarily removing that control, and seeing if the problem goes away...

    Reed Copsey, Jr. - http://reedcopsey.com
    Friday, October 16, 2009 8:47 PM
  • Hi Jerma,

    What's the PrismaFrame?

    If you write a method explicitly to handle the btnWindowMaximize.Click event rather than use a lambda expression, can be problem be fixed?

    If this doesn't help, could you please tell me how to reproduce the problem?

    Thanks,
    Linda Liu
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, October 21, 2009 8:15 AM
  • We are changing the issue type to “General Discussion” because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question” by opening the Options list at the top of the post window, and changing the type. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.
    Friday, October 23, 2009 3:34 AM
  • I have the same issue, the thing is it works fine on some workstation but it blow up on one computer. it's a window inherit from window. it's not using lamda to handle the max event.

     

     

    void OnMaximizeClick(object sender, RoutedEventArgs e)

    {

    WindowState = WindowState ==

     

    WindowState.Maximized ? WindowState.Normal : WindowState.Maximized; //exception here

    }

     


    Kevin
    Monday, November 29, 2010 8:17 PM
  • hi Jerma,

    did you ever find the solution to this issue?

    Thanks

    Kevin

     


    Kevin
    Monday, November 29, 2010 8:32 PM