This repository was archived by the owner on Oct 24, 2025. It is now read-only.
Fix memory leak in removeAt methods.#9
Merged
gconnell merged 1 commit intogoogle:masterfrom Sep 21, 2016
Merged
Conversation
Contributor
Author
|
Ping. |
Contributor
|
Thanks! |
nvb
added a commit
to nvb/cockroach
that referenced
this pull request
Nov 6, 2018
google/btree#9 Release note: None
nvb
added a commit
to nvb/cockroach
that referenced
this pull request
Nov 13, 2018
google/btree#9 Release note: None
nvb
added a commit
to nvb/cockroach
that referenced
this pull request
Nov 13, 2018
google/btree#9 Release note: None
nvb
added a commit
to nvb/cockroach
that referenced
this pull request
Nov 15, 2018
google/btree#9 Release note: None
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This change sets the last item in the slice to nil before the slice length is decreased when removing arbitrary elements. In the writeup below vertical bars denote that beginning and end of the visible part of the slice. Items beyond the last vertical bar denote items that lie beyond the end of the slice yet are still within the slice's capacity and therefore cannot be garbage collected.
Before this change, deleting B from | A B C D E | yielded | A C D E | E
Then deleting E yielded | A C D | nil E. Even though E is deleted, E can't be garbage collected because a copy of it still sits beyond the end of the slice yet within the slice's capacity.
With this change, deleting B from | A B C D E | yields | A C D E | nil so that no extra copies of items or child pointers exist beyond the end of the slice allowing them to be GCed.