下面查看ByteBuffer类的源码来验证直接内存分配、释放的的过程。 allocateDirect()中返回一个DirectByteBuffer对象。 public static ByteBuffer allocateDirect(int capacity) { return new DirectByteBuffer(capacity); }调用Unsafe中allocateMemory()来实现申请内存,新建Cleaner对象来释放内存。 DirectByteBuffer(int cap) { // package-private super(-1, 0, cap, cap); bool...