On Thu, Mar 26, 2020 at 6:41 PM robfig <rob...@gmail.com> wrote: > Reducing a slice's length makes the elements unreachable, but the GC > appears to still treat them as live, based on this snippet: > https://play.golang.org/p/SvsE-nXi-JA > > I would have expected the HeapInUse to go down in the second measurement. > > Why is that? > > I presume that the GC is traversing the slice's capacity rather than > length, but I'm not sure why this is necessary. Is there a way (without > using unsafe) to access slice elements past the length? >
Yes. https://play.golang.org/p/HhZWkGvR37L > -- > 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/c2bea525-0636-4365-b551-59d1fceb5959%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/c2bea525-0636-4365-b551-59d1fceb5959%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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/CAEkBMfF-GzA%2BEOEANFZTpAZ_CXTNJhLTyY%2B4xZs%2BVa505CGYoQ%40mail.gmail.com.