@Override
    public long size() {
        lock.lock();
        try {
            return numAllocatedBatches * (long) batchSize;
        } finally {
            lock.unlock();
        }
    }
Release the retained buffers in the free pool.
raft/src/main/java/org/apache/kafka/raft/internals/BatchMemoryPool.java