Yes you could the code down to one line of code. You could catch the exception somewhere else, so I suppose the question could then become what do you do in a mission critical system when outofmemory exception or an allocation fails, therefore allowing you to gracefully shutdown. First thing that comes to mind is if the current thread is not mission critical you can kill that can free up some memory. Second, you could have a fail-safe that would allow you to kill all non-mission critical threads thus freeing memory. With the right permissions you could also kill the other applications. I've never implemented one but you could also have a "memory para-shoot" that at the start of the program allocates a chunk of memory and frees it when needed. I suppose allot of it depend on the system and requirements.
M
Michael Losinski
@Michael Losinski
Posts
-
What this 'null' check doing here... -
What this 'null' check doing here...The only thing that I can think of is technically new doesn't guarantee that the variable initialization will take place. In programming languages like c++ it could return null. This could happen if the memory was so fragmented that the allocation failed. However, instead of returning null in C# I believe it throws a out of memory exception. I have only seen this done in system critical embedded systems.