Skip to content
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
keep94:leak
Sep 21, 2016
Merged

Fix memory leak in removeAt methods.#9
gconnell merged 1 commit intogoogle:masterfrom
keep94:leak

Conversation

@keep94
Copy link
Copy Markdown
Contributor

@keep94 keep94 commented Aug 12, 2016

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.

@keep94
Copy link
Copy Markdown
Contributor Author

keep94 commented Sep 21, 2016

Ping.

@gconnell gconnell merged commit 7b8aed7 into google:master Sep 21, 2016
@gconnell
Copy link
Copy Markdown
Contributor

Thanks!

nvb added a commit to nvb/cockroach that referenced this pull request Nov 6, 2018
nvb added a commit to nvb/cockroach that referenced this pull request Nov 13, 2018
nvb added a commit to nvb/cockroach that referenced this pull request Nov 13, 2018
nvb added a commit to nvb/cockroach that referenced this pull request Nov 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants