Design pattern for a try / catch block for OutOfMemoryException in .NET.

I have an application that works with large amounts of data, and I think that maybe it will sometimes OutOfMemoryException(for six months I have not had a single exception, but I just want to know everything about it). As I researched, after this exception, I cannot continue to execute my program.

Is there a good template for handling such exceptions, especially for working with IDisposable classes?

+5
source share
3 answers

In a genuine OOM script (most likely on x86 than on x64) you are pretty doomed. Almost everything can cause distribution, so your best option is to die as quickly and elegantly as possible, causing minimal harm.

Since this does not happen, do not exert excessive stress, but avoidance is better than here:

  • use streaming data APIs and not buffer everything in memory
  • reuse of buffers, etc.
  • avoid huge arrays / lists, etc. (in truth, the most likely way to call OOM is to request a huge (but single) array) - for example, a jagged array scales better than a 2D array (even on x64 there is a hard limit on the maximum size of one array)
  • think about how you handle sparse data.
  • ? , , 20 000 (, ).
  • , ,
  • , ( ).
+4

, OOM - , . . , , - . , , .

, , 32- . , 90 , 500 . , . , 64- .

+4

,
, , - .
, - , (, , ).

In my previous work I used such a tool ( HP Performance Center ), and it turned out to be invaluable not only to check our mistakes and limitations, but also to identify bottlenecks and costly operations.

+2
source

All Articles