a = append(a[:i], a[j:])
What do I have to consider, to do, to prevent memory leak?
Thanks for your help
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
a, a[len(a)-1] = append(a[:i], a[i+1:]...), nil
a -> backingarray[last element] -> value
To clarify: the length of the slice has been reduced, not the length of the array.
The backing array for a is still in use, it's length has just been reduced by one, masking off the final element. The reason you nil the final elegant is otherwise it will still be reachable from a.
a -> backingarray[last element] -> value
A slice is just a pointer to an array element with some extra attributes. Creating a slice on the same array is cheap.
Append always creates a new slice, but most of the time it reuses the array, so usually it is cheap.
See http://golang.org/blog/go-slices-usage-and-internals
So it is possible, that sometimes a memory leak happens?