mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
In filter trick, include code that handles garbage collected elements.
parent
a2ce08d4a1
commit
15b8fbe8bd
@ -120,6 +120,14 @@ for _, x := range a {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
For elements which must be garbage collected, the following code can be included afterwards:
|
||||||
|
|
||||||
|
```go
|
||||||
|
for i := len(b); i < len(a); i++ {
|
||||||
|
a[i] = nil // or the zero value of T
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Reversing
|
### Reversing
|
||||||
|
|
||||||
To replace the contents of a slice with the same elements but in reverse order:
|
To replace the contents of a slice with the same elements but in reverse order:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user