From fdf5588096eaa09c14978d1f7939d554cfcbbe81 Mon Sep 17 00:00:00 2001 From: Maxim Litvinov <230431+metalim@users.noreply.github.com> Date: Mon, 31 Dec 2018 09:08:09 +0200 Subject: [PATCH] remove garbage. --- SliceTricks.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/SliceTricks.md b/SliceTricks.md index 86451af1..1189033c 100644 --- a/SliceTricks.md +++ b/SliceTricks.md @@ -29,12 +29,6 @@ a = append(a[:i], a[i+1:]...) a = a[:i+copy(a[i:], a[i+1:])] ``` -#### Delete without preserving order -```go -a[i] = a[len(a)-1] -a = a[:len(a)-1] - -``` **NOTE** If the type of the element is a _pointer_ or a struct with pointer fields, which need to be garbage collected, the above implementations of ` Cut ` and ` Delete ` have a potential _memory leak_ problem: some elements with values are still referenced by slice ` a ` and thus can not be collected. The following code can fix this problem: > **Cut** ```go