117 Star 1.1K Fork 361

Yeauty/netty-websocket-spring-boot-starter

 / 详情

关于Session的ByteBuf分配问题

待办的
创建于  
2021-09-11 19:53
public ChannelFuture sendText(ByteBuffer byteBuffer) {
    ByteBuf buffer = channel.alloc().buffer(byteBuffer.remaining());
    buffer.writeBytes(byteBuffer);
    return channel.writeAndFlush(new TextWebSocketFrame(buffer));
}

请问下作者大大,channel.alloc()默认实现是PooledByteBufAllocator,是ThreadLocal。如果在自己的业务线程调用这个方法,不会引起内存泄露么?这里为什么不是使用Unpooled而使用channel.alloc()呢?

评论 (2)

超肥大胖狸猫 创建了任务
展开全部操作日志

1.使用pool会复用内存,性能更高
2.在最后发出去的时候会release,不会内存泄漏

自己写了个测试验证了下,确实还是会还到原线程的池子里去。谢谢作者耐心解答~

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(2)
1420829 yeauty 1578951071
Java
1
https://gitee.com/Yeauty/netty-websocket-spring-boot-starter.git
git@gitee.com:Yeauty/netty-websocket-spring-boot-starter.git
Yeauty
netty-websocket-spring-boot-starter
netty-websocket-spring-boot-starter

搜索帮助

344bd9b3 5694891 D2dac590 5694891