It is possible to reduce the capacity of a slice by using the full slice 
expression (https://golang.org/ref/spec#Slice_expressions).

Now consider the following code where a is a 1MB slice. I then create b, a 
slice of a, but with a much smaller capacity. Finally, I change the value 
of a so that only b refers to the slice element storage.  

a := make([]byte, 1000000)
b := b[:3:3]
a = nil

Will the garbage collector be able to recover the inaccessible space in the 
slice element storage ?

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/1c984e3f-eb86-49b8-be00-34a99f9f2551%40googlegroups.com.

Reply via email to