mirror of
https://github.com/golang/go.git
synced 2024-11-21 21:11:11 +00:00
woops. revert last edit.
parent
fdf5588096
commit
3ddd17034b
@ -29,6 +29,12 @@ 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
|
||||
|
Loading…
Reference in New Issue
Block a user