Creating a dangling pointer using Java

前端 未结 5 979
既然无缘
既然无缘 2021-01-06 05:57

How can i create a dangling pointer using Java?

5条回答
  •  無奈伤痛
    2021-01-06 06:38

    Not available on all JVMs, but Sun's JVM does give you sun.misc.unsafe#allocateMemory(long bytes). That call returns a pointer.

    sun.misc.unsafe#freeMemory(long address) frees that memory. Your initial pointer is now "dangling".

提交回复
热议问题