Skip to content

Commit 334a238

Browse files
Deleplacerandall77
authored andcommitted
slices: mention possible memory leak in Delete doc
Mitigates golang/go#54650 Change-Id: I899094ec6af8d3b1985e737a5318e9776b4cb1a9 Reviewed-on: https://go-review.googlesource.com/c/exp/+/425895 Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent bd9bcdd commit 334a238

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

slices/slices.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ func Insert[S ~[]E, E any](s S, i int, v ...E) S {
153153
// Delete modifies the contents of the slice s; it does not create a new slice.
154154
// Delete is O(len(s)-j), so if many items must be deleted, it is better to
155155
// make a single call deleting them all together than to delete one at a time.
156+
// Delete might not modify the elements s[len(s)-(j-i):len(s)]. If those
157+
// elements contain pointers you might consider zeroing those elements so that
158+
// objects they reference can be garbage collected.
156159
func Delete[S ~[]E, E any](s S, i, j int) S {
157160
_ = s[i:j] // bounds check
158161

0 commit comments

Comments
 (0)