Linux下GO语言编译出来的程序VSZ占用很大

XiaoYanShen · 2018-09-06 16:45:28 · 1797 次点击 · 大约8小时之前 开始浏览    置顶
这是一个创建于 2018-09-06 16:45:28 的主题,其中的信息可能已经有所发展或是发生改变。

在Linux下运行编译好的go语言程序,程序占用VSZ达到了661M,本身设备的内存一共也才512M,现在程序运行达不到在X86下面运行的效果,这个是由于VSZ大小超过了物理大小所致吗 深度截图_选择区域_20180906164432.png


有疑问加站长微信联系(非本文作者)

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

1797 次点击  
加入收藏 微博
5 回复  |  直到 2018-09-07 11:49:47
mlzhou
mlzhou · #1 · 7年之前

是不是创建的对象太多了

moryaden
moryaden · #2 · 7年之前

http://docs.studygolang.com/doc/faq#Why_does_my_Go_process_use_so_much_virtual_memory

The Go memory allocator reserves a large region of virtual memory as an arena for allocations. This virtual memory is local to the specific Go process; the reservation does not deprive other processes of memory.

To find the amount of actual memory allocated to a Go process, use the Unix top command and consult the RES (Linux) or RSIZE (macOS) columns.

XiaoYanShen
XiaoYanShen · #3 · 7年之前
mlzhoumlzhou #1 回复

是不是创建的对象太多了

里面确实很多

XiaoYanShen
XiaoYanShen · #4 · 7年之前
moryadenmoryaden #2 回复

http://docs.studygolang.com/doc/faq#Why_does_my_Go_process_use_so_much_virtual_memory The Go memory allocator reserves a large region of virtual memory as an arena for allocations. This virtual memory is local to the specific Go process; the reservation does not deprive other processes of memory. To find the amount of actual memory allocated to a Go process, use the Unix top command and consult the RES (Linux) or RSIZE (macOS) columns.

这个只是说出的原因,没有本质解决问题呐.现在程序运行和PC运行不一样

mlzhou
mlzhou · #5 · 7年之前
XiaoYanShenXiaoYanShen #3 回复

#1楼 @mlzhou 里面确实很多

这是根本原因,你创建的对象太多,gc来不及回收,所以一直导致内存暴涨。解决方法是创建全局对象,复用

添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传