Does go garbage collect parts of slices?

前端 未结 4 1310
名媛妹妹
名媛妹妹 2020-12-03 03:17

If I implement a queue like this...

package main

import(
    \"fmt\"
)

func PopFront(q *[]string) string {
    r := (*q)[0]
    *q = (*q)[1:len(*q)]
    re         


        
4条回答
  •  Happy的楠姐
    2020-12-03 04:01

    Simple question, simple answer: No. (But if you keep pushing the slice will at some point overflow its underlying array then the unused elements become available to be freed.)

提交回复
热议问题