public void release() { synchronized (this) { if (refCount <= 0) { refCount = 0; throw new IllegalStateException( "Already released buffer. You released the buffer too many times."); } refCount--; if (refCount > 0) { return; } } // No need to return buffers to the pool if it is disposed already. if (disposed) { return; } buf.release(); }
protected void capacity0(int requestedCapacity) { if (buf.isDerived()) { throw new IllegalStateException( "Derived buffers cannot be expanded."); } int newCapacity = MINIMUM_CAPACITY; while (newCapacity < requestedCapacity) { newCapacity <<= 1; } UnexpandableByteBuffer oldBuf = this.buf; boolean direct = isDirect(); UnexpandableByteBuffer newBuf; try { newBuf = allocate0(newCapacity, direct); } catch (OutOfMemoryError e) { if (direct) { newBuf = allocate0(newCapacity, false); } else { throw e; } } newBuf.buf().clear(); oldBuf.buf().clear(); newBuf.buf().put(oldBuf.buf()); this.buf = newBuf; oldBuf.release(); } }
public void release() { if (isDerived()) { parentBuf.release(); return; } synchronized (this) { if (refCount <= 0) { refCount = 0; throw new IllegalStateException( "Already released buffer. You released the buffer too many times."); } refCount--; if (refCount > 0) { return; } } // No need to return buffers to the pool if it is disposed already. if (disposed) { return; } if (pooled) { if (parentBuf != null) { release0(parentBuf); } else { release0(this); } } }