On Thursday, March 9, 2017 at 2:48:05 AM UTC-8, Jan Mercl wrote:
>
> On Thu, Mar 9, 2017 at 11:45 AM 代君 <sydn...@gmail.com <javascript:>> 
> wrote:
>
> > I have a []*Struct, at some times it length grow to 1000, after that, 
> the slice be shortcut to length of 10, and never grow to 1000 again.
> > dose the memory of *Struct at slice's tail will never be gc? 
>
> It will not be garbage collected because it's possible to do slice = 
> slice[:1000] any time later.
>
> -- 
>
> -j
>

There's also the seldom used 3 parm form of slicing, e.g. slice[0:10:10] 
(last one is the capacity) but it won't help in this case, the GC just 
doesn't collect parts of the backing array. The only way seems to be to 
copy what you need from the old slice into a new one of smaller size, using 
the built-in copy() function for example. 

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to