c# - When is it OK to catch an OutOfMemoryException and how to handle it? -


Yesterday I was dedicated to OO Outauri Expression and participated in discussions on professionals and opposition to handle this ().

  • The fact is that OutOfMemoryException was thrown; it generally does not mean that the status of a program was corrupted; According to the documentation, "throw outofformary expansion to the following Microsoft Intermediate (MSIL) instructions: Box, Newery, Nubeb" which only (usually) means that CLR has given a given size block of memory Tried to find and unable to do so; No This means that no bytes were left in our nature;

But not all people agreed with this and after the exception the unknown program predicted the state and

so my question is: OutOfMemoryException What are the serious reasons to handle and leave it immediately when this happens?

Edited: Do you think OOME performance engineer is fatal as an exception?

We all write different applications in the WinForms or ASP.Net app, I probably log exception, I suggest to the user, try to save the state, and shutdown / restart. But as Igor described in the comments, this image can be very well constructed by some form of editing application and the process of loading the 100th 20MB raw image can push the app on the edge. Do you really want to use all your work to lose something as easy to say? "Sorry, unable to load more images at this time".

Another common example is that memory can be useful for capturing exceptions. Back and Batch Processing You may have a standard model of loading multi-megabyte files into memory for processing. , But then blue one multi-giga-byte file is loaded one day. When there is out-of-memory, you can log the message in a user notification queue and then go to the next file.

Yes, it is possible that something else can fly at the same time, but those people will probably be logged and notified. If GC is finally unable to process any more memory, then the application is going down hard. (GC runs in an unsafe thread.)

Do not forget that we all develop various types of applications. And as long as you are not on the old, bound machines, you will usually not get an OutOfMommy exception for specific business apps ... but then we're all not just business tool developers.

For your editing ..

Out-of-memory unmanaged memory may be due to fragmentation and pinching. This can also be due to large allocation requests if we wanted to put a white flag and would like to draw a line in the sand on such simple issues, then in large data processing projects, nothing will be done at all. Now by comparing a fatal engine exception, ok, there is nothing at that time that the runtime gets dead under your code. Hopefully you are able to log in (but probably not) why your code has fallen on your face so that you can stop it in the future. But, more importantly, hopefully your code has been written in this manner, allowing you to get as much secure data as you can get. It may also be possible to retrieve the last known good position in your application and possibly leave the offensive corrupt data and allow it to manually process and recover.

Still, data corruption is possible due to SQL injection, out-of-sync version of software, pointers manipulation, run buffer and many other problems at the same time. Avoid any issues just because looks like you can not recover from probably is a great way for users to make error messages creative please check your system Contact the administrator .


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -