In filter trick, include code that handles garbage collected elements.

Anaminus 2019-02-14 17:59:35 +00:00
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
To replace the contents of a slice with the same elements but in reverse order: