System.Drawing Out of Memory Exception

前端 未结 5 1278
深忆病人
深忆病人 2020-11-28 15:43

My application graphics engine throws these exceptions. They are all consumed by an empty catch block. In the early days I found one that was not trapped (associated with

5条回答
  •  醉酒成梦
    2020-11-28 16:13

    It's a pretty bad exception: http://msdn.microsoft.com/en-us/library/system.outofmemoryexception.aspx .. not enough memory to continue execution of the program.

    You'll often find if you have so much allocated that 'simple' operations/allocations throw this message, the app will crash soon after. If it's one massive allocation that's failing, you may be able to continue.

    If the app does anything important, you should try to close things down gracefully.

    To explicitly answer your questions:

    1. They're thrown so the app has a chance to react/recover: some memory allocations (10GB worth of objects) might be expected to fail in many situations, perhaps a one-line app crash (int[] x = new int[5368709120]; equivalent) should really throw an exception rather than crash everything

    2. There should be no hidden effect, but if one allocation fails, then perhaps the next time you want a string or other useful object in some small way allocated for general operation of the app: things might become unstable. That said depending on the environment, you might get this exception at any time..

    Edit: Anyone reading this should also consider that apparently GDI+ throws this exception for other reasons too.

提交回复
热议问题