Here you can find the source of releaseTemporaryDirectBuffer(ByteBuffer buf)
static void releaseTemporaryDirectBuffer(ByteBuffer buf)
//package com.java2s; //License from project: Open Source License import java.lang.ref.SoftReference; import java.nio.ByteBuffer; public class Main { private static final int TEMP_BUF_POOL_SIZE = 3; private static ThreadLocal<SoftReference<ByteBuffer>>[] bufferPool; static void releaseTemporaryDirectBuffer(ByteBuffer buf) { if (buf == null) return; // Put it in an empty slot if such exists for (int i = 0; i < TEMP_BUF_POOL_SIZE; i++) { SoftReference<ByteBuffer> ref = (bufferPool[i].get()); if ((ref == null) || (ref.get() == null)) { bufferPool[i].set(new SoftReference<>(buf)); return; }// w w w . j a va 2s .co m } // Otherwise replace a smaller one in the cache if such exists for (int i = 0; i < TEMP_BUF_POOL_SIZE; i++) { SoftReference ref = (bufferPool[i].get()); ByteBuffer inCacheBuf = (ByteBuffer) ref.get(); if ((inCacheBuf == null) || (buf.capacity() > inCacheBuf.capacity())) { bufferPool[i].set(new SoftReference<>(buf)); return; } } } }