Skip to content

Use detached byte buffers by default for decoded values #330

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

Closed
mp911de opened this issue Sep 10, 2020 · 0 comments
Closed

Use detached byte buffers by default for decoded values #330

mp911de opened this issue Sep 10, 2020 · 0 comments
Labels
type: task A general task
Milestone

Comments

@mp911de
Copy link
Collaborator

mp911de commented Sep 10, 2020

Right now, the driver uses pooled (attached) buffers when decoding Json. When not consuming the Json content, this may lead to a memory leak as the buffer backing the Json value is reference-counted and not disposed automatically.

This behavior is memory-efficient but it's not obvious. We should default to copy buffers into a data structure that can be garbage-collected. With copying data, we lose a bit of efficiency but provide memory-safety in return.

Original issue: spring-projects/spring-data-r2dbc/#453.

@mp911de mp911de added the type: task A general task label Sep 10, 2020
@mp911de mp911de added this to the 0.8.5.RELEASE milestone Sep 10, 2020
mp911de added a commit that referenced this issue Sep 10, 2020
JsonCodec now copies the decoded value from an attached buffer to a detached one reduce the risk of memory leaks. Detached buffers get garbage collected regardless of whether the decoded value gets consumed.

Attached buffers are reference-counted and don't get automatically garbage-collected which requires decoded values to be consumed. If a value backed by an attached buffer doesn't get consumed, then the memory backing the data structure isn't reclaimed and creates a memory leak. Since this behavior is non-obvious, we default to the less-efficient approach to copy buffers which prevents the risk of memory leaks.

[resolves #330]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: task A general task
Projects
None yet
Development

No branches or pull requests

1 participant