question

khakindrad1 avatar image
0 Votes"
khakindrad1 asked DanielZhang-MSFT commented

Winform Application crash with System.OutOfMemoryException:"Out of memory." while click on menubar

64-Bit winform application targeting Framework version 4.5.2 crashing while clicking on menu bar.

Event Details appended below :-


Application: APPName.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.OutOfMemoryException
Stack:
at System.Windows.Forms.Control.CreateGraphicsInternal()
at System.Windows.Forms.Control.GetHRgn(System.Drawing.Region)
at System.Windows.Forms.Control.Invalidate(System.Drawing.Region, Boolean)
at System.Windows.Forms.ToolStrip.ClearAllSelectionsExcept(System.Windows.Forms.ToolStripItem)
at System.Windows.Forms.ToolStrip.SetVisibleCore(Boolean)
at System.Windows.Forms.ToolStripDropDown.SetVisibleCore(Boolean)
at System.Windows.Forms.ToolStripManager+ModalMenuFilter.CloseActiveDropDown(System.Windows.Forms.ToolStripDropDown, System.Windows.Forms.ToolStripDropDownCloseReason)
at System.Windows.Forms.ToolStripManager+ModalMenuFilter.ProcessMouseButtonPressed(IntPtr, Int32, Int32)
at System.Windows.Forms.ToolStripManager+ModalMenuFilter.PreFilterMessage(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Application+ThreadContext.ProcessFilters(MSG ByRef, Boolean ByRef)
at System.Windows.Forms.Application+ThreadContext.PreTranslateMessage(MSG ByRef)
at System.Windows.Forms.Application+ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr, Int32, Int32)
at System.Windows.Forms.Application+ThreadContext.RunMessageLoopInner(Int32, System.Windows.Forms.ApplicationContext)
at System.Windows.Forms.Application+ThreadContext.RunMessageLoop(Int32, System.Windows.Forms.ApplicationContext)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.ThreadHelper.ThreadStart(System.Object)

windows-forms
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


In case of graphics, this exception does not necessarily mean “out of memory”. How to reproduce the problem? Do you have a sample project (on OneDrive, GitHub, etc.)?


0 Votes 0 ·

Issue is not simulating Development/UAT environment, Even in Production not simulate every time.
I only have Crash Dump file, does this help to identify the cause?

0 Votes 0 ·

Maybe it is a problem of graphics card or driver. Check if there are updates to drivers or Windows, or if the card has some custom settings, which can be adjusted to solve the problem.

Are you using third-party controls?

0 Votes 0 ·
Show more comments

1 Answer

DanielZhang-MSFT avatar image
0 Votes"
DanielZhang-MSFT answered DanielZhang-MSFT commented

Hi khakindrad1,
By default, the common language runtime in .NET Framework does not allow single objects whose size exceeds 2GB. To override this default, you can use the <gcAllowVeryLargeObjects> configuration file setting to enable arrays whose total size exceeds 2 GB.
You can do it by adding the following code to you app.config file:

 <configuration>
   <runtime>
     <gcAllowVeryLargeObjects enabled="true" />
   </runtime>
 </configuration>

More suggestions you can refer to this document.
Best Regards,
Daniel Zhang


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Daniel,
Thanks for your response.
I'm having Application Crash Dump file, How can I identify which type of object is source of issue?

0 Votes 0 ·

You marked "answer accepted" :
this means that your problem is solved

0 Votes 0 ·

Issue occurs on Production Environment and not simulate every time.
Want to find cause object.

0 Votes 0 ·
Show more comments