解冻intbuffer时Java崩溃

时间:2017-04-16 10:01:39

标签: java crash buffer lwjgl

每当我运行以下代码时,java在释放IntBuffer时返回EXCEPTION_ACCESS_VIOLATION:

public int[] size(){
    IntBuffer size=BufferUtils.createIntBuffer(2);
    long address=MemoryUtil.memAddress(size);

    GLFW.nglfwGetWindowSize(this.handle, address, address+Integer.BYTES);
    int[] result=new int[]{size.get(0), size.get(1)};

    JEmalloc.nje_free(address);

    return result;
}

Pastebin

1 个答案:

答案 0 :(得分:0)

垃圾收集器将释放由ByteBuffer创建的BufferUtils,而不再提及它。

如果要使用JEmalloc.nje_free()释放缓冲区,则在分配缓冲区时还需要使用JEmalloc

IntBuffer size = JEmalloc.je_malloc(2 * Integer.BYTES).asIntBuffer();
long address = MemoryUtil.memAddress(size);

[...]

JEmalloc.nje_free(address);