Skip to main content

DirectBuffer reallocation

2 replies [Last post]
Joined: 2004-07-12

It would be a nice feature to free or reallocate an instance of DirectBuffer.


APIs like jogl and lwjgl are using DirectBuffers to hold 3D graphic data. You waste a lot of unused memory because the DirectBuffer is only freed at the end of a VM run. When you need a smaller or bigger one you can't free or reallocate the old DirectBuffer. You have no possibility to scale the memory usage of the application if you use DirectBuffers.


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-06-19

I don't claim to be an expert but: IIRC, direct buffers should be collected during GC. If there's not enough memory for a direct buffer allocation, then System.gc is called. There was a discussion somewhere about whether System.gc should block the calling thread until the GC thread(s) have done their work.

However, it does seem reasonable that direct buffer should be considered resources, not just memory, and therefore have a dispose operation.

Joined: 2004-11-26

I believe that depends on who allocated the direct buffer. If java code does it, it will get collected, but if jni does it, then no garbage collection.