private static void writeToCOS(Message result, Message header, int totalSize, ByteBuffer pbBuf)
    throws IOException {
    ByteBufferUtils.putInt(pbBuf, totalSize);
    // create COS that works on BB
    CodedOutputStream cos = CodedOutputStream.newInstance(pbBuf);
    if (header != null) {
      cos.writeMessageNoTag(header);
    }
    if (result != null) {
      cos.writeMessageNoTag(result);
    }
    cos.flush();
    cos.checkNoSpaceLeft();
  }
Call is done. Execution happened and we returned results to client. It is now safe to cleanup.
hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/ServerCall.java