Sometimes it's helpful to get an application into a bad situation to see how it responds. Things like unplugging the network cable or removing power will show me how resilient my application is and where I have work to do.
To this end, I'm trying to figure out what the fastest way to force an OutOfMemoryException
in .Net. Doing it in a simple console application will allow me to inject this scenario into a running application. There are obviously other things that need to be considered when dealing with OutOfMemoryExceptions
(e.g. memory fragmentation and how the garbage collector has allocated the different generations) but that's not important for the scope of this experiment.
Update
To clarify the purpose of the question, it's important to note that simply throwing an out of memory exception isn't helpful since I want to see how the program will react when the memory pressure is increased. In essence, I want to stimulate the GC into an aggressive collection mode and monitor how that impacts the performance until the process dies from an out of memory exception.