How to make OutOfMemoryError occur on Linux JVM 64bit

前端 未结 7 2022
旧时难觅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:47

    The reason for no OutofMemoryError is that the memory is being allocated in a uncommitted state, with no page.

    If you write a non-zero byte into each 4K of the array, that will then cause the memory to be allocated.

提交回复
热议问题