netty bytebuff 释放原则和防止内存泄露
博客专区 > greki 的博客 > 博客详情
netty bytebuff 释放原则和防止内存泄露
greki 发表于3年前
netty bytebuff 释放原则和防止内存泄露
  • 发表于 3年前
  • 阅读 68
  • 收藏 0
  • 点赞 0
  • 评论 0

腾讯云 技术升级10大核心产品年终让利>>>   

摘要: netty bytebuff 释放原则和防止内存泄露


Action Who should release? Who released?
1. main() creates buf buf→main()
2. main() calls a() with buf buf→a()
3. a() returns buf merely. buf→main()
4. main() calls b() with buf buf→b()
5. b() returns the copy of buf buf→b(), copy→main() b() releases buf
6. main() calls c() with copy copy→c()
7. c() swallows copy copy→c() c() releases copy


  • If a [sending] component is supposed to pass a reference-counted object to another [receiving] component, the sending component usually does not need to destroy it but defers that decision to the receiving component.
  • If a component consumes a reference-counted object and knows nothing else will access it anymore (i.e., does not pass along a reference to yet another component), the component should destroy it.


1.A(byteBuff)接受了byteBuff, 然后又传给了另外一个方法B(bytebuff),A方法内不用释放;

2.如果B(bytebuff)接受了byteBuff,没有再传递给其他方法,B负责release;


http://netty.io/wiki/reference-counted-objects.html

http://stackoverflow.com/questions/15781276/buffer-ownership-in-netty-4-how-is-buffer-life-cycle-managed



标签: netty bytebuff refCnt
共有 人打赏支持
粉丝 92
博文 106
码字总数 39835
×
greki
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: