LWJGL: Bufferutil.createbytebuffer() vs. ByteBuffer.allocatedirect()

Is there a difference? are there any reasons i should use one over the other?

The difference is described in the javadocs.

Riven is right, BufferUtils.createByteBuffer(int) does the same thing than ByteBuffer.allocateDirect() except that it sets its byte order to the native one of the platform. It probably does :

ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder());

so it doesn’t return a bytebuffer that doesn’t leak?

It does return a bytebuffer that doesn’t leak, simply because bytebuffers never leak. That’d be messy.

What do you mean? An undirected NIO buffer is allocated on the Java heap but a direct NIO buffer is allocated on the native heap. The former doesn’t need any intervention of the programmer to be garbage collected whereas the latter may require some help, for example when you still have a lot of memory available in the Java heap but not in the native heap.

I was wondering if one returned by bufferutils gets helped along. How would I go about making one get rid of it’s memory?

Exactly the same as how you ensure a byte[n] gets eventually cleaned up.

Follow Riven’s suggestion and if the JVM needs a kick in its ass, get the cleaner of your direct NIO buffer and call it but you must be absolutely sure that the VBO using it has been destroyed before.

User beware.