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 (, ).
- , ,
- , ( ).