-
Notifications
You must be signed in to change notification settings - Fork 17.5k
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
x/exp/slices: mention possible memory leak in Compact doc #54728
Comments
The same concern applies to |
Change https://go.dev/cl/426374 mentions this issue: |
@Deleplace I would think that in stead of documenting the memory leak, it should be fixed. Otherwise people will have to implement their own safer Compact. |
@beoran I see it the same as slicing. If you have
Then there remain "invisible" references to |
@randall77 Actually, I never thought about this, I will have to be more careful with slicing like this from now. Still, as long as I have the original array, I can zero the unnecessary elements. It would be useful if there was a generic operation that did this, and Compact seems like the ideal candidate. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What did you do?
I read the documentation comment of Compact
What did you expect to see?
A warning about the "right tail" values in the original slice, which are obsolete but may still contain pointers to large objects. The same problem applied to Delete (issue #54650, CL 425895 ) and was mitigated by updating the func doc.
What did you see instead?
Compact does not zero the "discarded" elements beyond the length of the returned slice, as can be read in the current implementation, which may have adverse memory consequences, as show by this sample code.
I will make a CL with an extra sentence in the func doc.
The text was updated successfully, but these errors were encountered: