New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there a need to free memory of Unpooled.unreleasableBuffer #8139
Comments
(JVM only) It appears that the Direct Buffer will be cleaned up if no references are to it by default in the JVM during the heap GC but not effected by heap pressure so manual cleaning may be required as per previous stack overflow questions. Stack Overflow 1, Stack Overflow 2 (For Netty) Since Netty references the Direct Buffer I would think that it does not clean it until the PoolThreadCache runs the method free() which manually uses the Netty Internal/Cleaners which happens in finalize block of the @trustin or @normanmaurer just to verify this is correct. (Hope so, spent 1 or 2 hours navigating the code) Working notes from browsing the class files below. Reading through the
leading us to ...
and inside
which looks like ultimately it depends on the thread
when it frees it destroys the chunk
|
@felixunivers to release such a buffer you would need to unwrap it first. And yes you definitely want to do this as otherwise you will leak it. So something like:
|
Say, we declare in MyClass:
ByteBuf fixedBuf = Unpooled.unreleasableBuffer(PooledByteBufAllocator.DEFAULT.directBuffer(64, 64));
This should reserve a 64 bytes chunk of off-heap memory. As documented, Netty ignores here the 'release()' and 'retain()' functionality, therefore, the chunk remains allocated throughout the life of MyClass. What will happen to the allocated off-heap memory chunk once the instance of MyClass gets out of scope? Will JVM/GC release it? If not, or if I want to discard the 'fixedBuf ' programatically, how can I best deallocate the claimed memory blocks for such ByteBuf objects?
Would you please also point to explanation(s) / example(s) / best practice for avoiding any memory leaks and issues on ByteBuf objects?
The text was updated successfully, but these errors were encountered: