我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

如果切片的容量已由unsafe.Pointer修改,那么剩余内存可以被垃圾回收重用吗?

Think about this case:

s := make([]byte, 512, 1024)
(*reflect.SliceHeader)((unsafe.Pointer(&s))).Cap = 512

are the last 512 bytes memory can be collected by the GC?

Whether it is or not, Why?

As far as I know, the current garbage collector will not collect partial slices or strings. The same is true for:

s=s[:512:512] // Like your example but idiomatically starting in Go1.3
s=s[128:] // first 128 elements are not collected.

近期文章

  • ssh使用golang中的交互式shell将nsenter作为远程命令执行以调试Docker容器
  • 从末尾开始替换n次字符串
  • 增加最大分配内存Golang 1.4+
  • goquery-将标记与后面的标记连接
  • Golang写入http响应会中断输入阅读?
  • 如何访问软件包外部的模板?
  • 使用Go和OpenCV读取/写入图像中的ICC配置文件
  • Golang干净的项目不在渠道中,不会被读取
  • Mac hive3无论如何都无法启动
  • 如何监控网络接口(go-lang)
  • 如何在Golang Beego中删除重复的ORM实例
  • 我不知道为什么我的案例中JS和Go之间没有太大的性能差异
  • 将Go程序源导入为库
  • Golang-解析嵌套的JSON
  • 让git / go获得使用代理域
  • 基于nanomsg的内部服务器
  • 在实现相同接口的多个结构上定义方法
  • 在Golang中将正常空间/空白转换为不间断空间?
  • 服务器上的HTTP保持活动超时
  • Golang Goroutines共享RPC连接

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华