mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
Revert 9ade7aa9a7572213f24774347587a453ea88c3e9...3ddd17034b922e41c0d0b8ec85f71dfc813a1992 on SliceTricks
parent
3ddd17034b
commit
3941028dc4
@ -29,12 +29,12 @@ a = append(a[:i], a[i+1:]...)
|
||||
a = a[:i+copy(a[i:], a[i+1:])]
|
||||
```
|
||||
|
||||
> **Delete without preserving order**
|
||||
#### Delete without preserving order
|
||||
```go
|
||||
a[i] = a[len(a)-1]
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user