3 ms·
There's problems when you're taking a slice and storing it for a potentially long time. If the slice is actually a subslice of a super large array, the backing
by jmgao 9y ago
There's problems when you're taking a slice and storing it for a potentially long time. If the slice is actually a subslice of a super large array, the backing slice will be kept around until the subslice goes away (assuming the implementation doesn't try to be clever about things, but it probably doesn't).
- zaarn 9y agoIf the Go compiler can't tell anything about the length of storage of a slice, it'll end up in heap. The stack is usually only used when escape analysis determines that the value does not survive the function call, atleast IIRC. Slices should be capable of being partially deallocate so long as the backing arrays are not referenced anymore.