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 modifies the contents of the slice s; it does not create a new slice."
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:
@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.