If a Slice has pointers, It will result in the memeory leak, if we didn't nil the pointers. This snippet is used to do it.
// Snippet: truncates the given slice
// a, array to be sliced
// i, starting index of the array
// j, ending index of the array
copy(a[i:], a[j:])
for k, n := len(a)-j+i, len(a); k < n; k++ {
a[k] = nil // or the zero value of T
}
a = a[:len(a)-j+i]