Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

franz1981
Copy link
Contributor

Motivation:

AdaptiveByteBuf::deallocate is not cleaning up both its wrapped ByteBuf and Chunk, extending their lifecycles (if they can be GCed) till AdaptiveByteBuf is reused again

Modifications:

Clean the relevant fields of AdaptiveByteBuf on deallocation

Result:

No more (temporary) memory leak

Copy link
Member

@normanmaurer normanmaurer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

@normanmaurer
Copy link
Member

@franz1981 you need to add a null check and throw IllegalReferenceCountException:

Error:  Failures: 
Error:    AdaptivePooledByteBufTest>AbstractByteBufTest.testEnsureWritableAfterRelease:3023 Unexpected exception type thrown, expected: <io.netty.util.IllegalReferenceCountException> but was: <java.lang.NullPointerException>
Error:  Errors: 
Error:    AdaptivePooledByteBufTest>AbstractByteBufTest.testArrayAfterRelease:4372 � NullPointer
Error:    AdaptivePooledByteBufTest>AbstractByteBufTest.testMemoryAddressAfterRelease:4385 � NullPointer
[INFO] 
Error:  Tests run: 11508, Failures: 1, Errors: 2, Skipped: 1257
[INFO] 

@franz1981
Copy link
Contributor Author

@normanmaurer

you need to add a null check and throw IllegalReferenceCountException:

I've done it but still getting an ex; investigating...

Motivation:

AdaptiveByteBuf::deallocate is not cleaning up both its wrapped ByteBuf and Chunk, extending their lifecycles (if they can be GCed) till AdaptiveByteBuf is reused again

Modifications:

Clean the relevant fields of AdaptiveByteBuf on deallocation

Result:

No more (temporary) memory leak
@franz1981 franz1981 force-pushed the 4.1_adaptive_cleanup_fields branch from 74a787f to 2101055 Compare September 3, 2024 09:25
@franz1981
Copy link
Contributor Author

franz1981 commented Sep 3, 2024

@normanmaurer PTAL

Not the best possible way to solve it, but I've decided to have 2 fields (in theory one was sufficient, but still...using Java Object Layout plugin for IDEA didn't show up any advantage in term of Object size...) which are "sticky" i.e. even if the object is deallocated, to respect the existing contract for hasArray/hasMemoryAddress - they remember their the last value (which should be constant TBH), while initialized.

@normanmaurer normanmaurer added this to the 4.1.113.Final milestone Sep 4, 2024
@normanmaurer normanmaurer merged commit e1d6384 into netty:4.1 Sep 4, 2024
16 of 17 checks passed
normanmaurer pushed a commit that referenced this pull request Sep 4, 2024
Motivation:

AdaptiveByteBuf::deallocate is not cleaning up both its wrapped ByteBuf
and Chunk, extending their lifecycles (if they can be GCed) till
AdaptiveByteBuf is reused again

Modifications:

Clean the relevant fields of AdaptiveByteBuf on deallocation

Result:

No more (temporary) memory leak
@franz1981
Copy link
Contributor Author

@normanmaurer should I open this for 4.2? Wdyt of using the GH stuff we talked about for automatic backporting?

@normanmaurer
Copy link
Member

I already cherry-picked it

@franz1981
Copy link
Contributor Author

u're a star, thanks bud @normanmaurer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants