这完全取决于您对“透明”的定义。有效的方法之一当然是:
slice = slice[:0]
但是有一个陷阱。如果切片元素的类型为T:
var slice []T
然后强制
len(slice)为零,由上述“特技”, 不 使任何元件
slice[:cap(slice)]
eligible for garbage collection. This might be the optimal approach in some
scenarios. But it might also be a cause of “memory leaks” - memory not used,
but potentially reachable (after re-slicing of ‘slice’) and thus not garbage
“collectable”.



