How to make OutOfMemoryError occur on Linux JVM 64bit

前端 未结 7 2028
旧时难觅i
旧时难觅i 2021-01-14 10:36

in my unit test I deliberately trying to raise an OutOfMemoryError exception. I use a simple statement like the following:

byte[] block = new byte[128 * 1024         


        
7条回答
  •  礼貌的吻别
    2021-01-14 10:48

    Linux doesn't always allocate you all the memory you ask for immediately, since many real applications ask for more than they need. This is called overcommit (it also means sometimes it guesses wrong, and the dreaded OOM killer strikes).

    For your unittest, I would just throw OutOfMemoryError manually.

提交回复
热议问题