features/pool: clear repeated bytes/string field in ResetVT #152
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Clearing repeated bytes/string field ensure that the memory can be
released by the garbage collector. Previously, the slice was only
resized to 0, but the underlying []byte/string were still referenced
by the slice.
String are immutable in Go and aren't supposed to be modified after they
are created, so reusing the allocated memory is not possible. The memory
allocated for []byte could be reused, but this requires some additional
modification to the generated Unmarshal code and would be incompatible
with the use of UnmarshalVTUnsafe. This could be considered in a
follow-up PR.
When repeating other types, we don't need to clear the slices:
.Reset
or.ResetVT
is being called instead toclear the message.
clear()
was introduced in Go 1.21, so the version has to be bumped.