public static void Main(string[] args) { var t = new Thread(() => { var limit = 64.Mb(); MemoryLimiter.LimitCommittedMemory(limit); var list = new List <byte[]>(); while (MemoryMeter.PrivateBytes() < limit - 128.Kb()) { list.Add(new byte[4096]); } try { F(0); } catch (Exception e) { Console.WriteLine(e.Message); } GC.KeepAlive(list); }); // , 4 * 1024 * 1024); t.Start(); t.Join(); }
public static void Run() { MemoryLimiter.LimitCommittedMemory(64.Mb()); var list = new List <byte[]>(); try { while (true) { list.Add(new byte[100000]); } } catch (Exception e) { Console.WriteLine("in catch block..."); Console.WriteLine(e); } Console.WriteLine("OOM handled"); }