摘要: 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.