I need the opposite of good, optimized code. For testing purposes I need a simple program to eat up RAM. Preferably not all memory so that the OS is non-functional, but more like something that would simulate a memory leak, using up a lot of memory and slowing down the OS, gradually, overtime.
Specifically, can anyone provide code spinets or links to tutorials I can use?
I saw this code as a suggestion on another post:
for (object[] o = null;; o = new[] { o });
But it is not quite what I am looking for as per the description above.
Please help.
Use
Marshal.AllocHGlobal(numbytes)
You can attach this to a timer. And just dont release the memory (dont call FreeHGlobal). Thats the most straighforward, controllable and predictable way to consume memory.
Marhsal.AllocHGlobal
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With