feat(新增): 🚀 netty的 ByteBuf 释放
This commit is contained in:
parent
c22915a471
commit
756476e1e1
|
@ -0,0 +1,31 @@
|
|||
package cn.bunny.service.netty.demo3;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
|
||||
import static cn.bunny.service.NettyLogUtil.log;
|
||||
|
||||
public class ByteByteBufAllocator {
|
||||
public static void main(String[] args) {
|
||||
ByteBuf buf = ByteBufAllocator.DEFAULT.buffer(10);
|
||||
buf.writeBytes(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
|
||||
|
||||
log(buf);
|
||||
|
||||
ByteBuf buf1 = buf.slice(0, 5);
|
||||
buf1.retain();
|
||||
log(buf1);
|
||||
|
||||
ByteBuf buf2 = buf.slice(5, 5);
|
||||
buf2.retain();
|
||||
log(buf2);
|
||||
|
||||
// 释放原有的buf 内容
|
||||
buf.release();
|
||||
log(buf);
|
||||
|
||||
// 释放 buf1和buf2内容
|
||||
buf1.release();
|
||||
buf2.release();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue