/** * This method allocates one large Buffer and then repeatedly creates a java.nio.ByteBuffer to * access them * * <p>If the system is not leaking, the garbage collector will ensure we don't run out of heap * space. If we're leaking, bad things will occur. */ @Test public void testNoLeakingMemoryOnDirectAccess() { Buffer buf = Buffer.make(null, 1024 * 1024); // 1 MB assertNotNull(buf); for (int i = 0; i < 100000; i++) { java.nio.ByteBuffer nativeBytes = buf.getByteBuffer(0, buf.getBufferSize()); // and we do nothing with the outBytes assertEquals(nativeBytes.limit(), buf.getBufferSize()); nativeBytes = null; } }