driuwt9557 2014-12-16 04:26
浏览 517

为什么golang中的内存不减少?

When the server started , the memory it took was about 83MB, which I checked by top. And When some connections were accepted and did something , the memory it took was about 500MB, Then, I closed all the connections and server cleard all the structs, after sometime, the memory decreased a little , about 30MB.The memory didn't return to the level when the server started.

when server started , I looked up heap info

# runtime.MemStats
# Alloc = 7251528
# TotalAlloc = 52713992
# Sys = 15010040
# Lookups = 49
# Mallocs = 2072338
# Frees = 2038576
# HeapAlloc = 7251528
# HeapSys = 12025856
# HeapIdle = 2121728
# HeapInuse = 9904128
# HeapReleased = 0
# HeapObjects = 33762
# Stack = 425984 / 425984
# MSpan = 75504 / 81920
# MCache = 4800 / 16384
# BuckHashSys = 1457768
# NextGC = 11496656

And when all connections closed, after sometime and gc, I looked up again

# runtime.MemStats
# Alloc = 5845912
# TotalAlloc = 13053679584
# Sys = 73128248
# Lookups = 794
# Mallocs = 22728491
# Frees = 22699056
# HeapAlloc = 5845912
# HeapSys = 60112896
# HeapIdle = 52166656
# HeapInuse = 7946240
# HeapReleased = 0
# HeapObjects = 29435
# Stack = 3719168 / 3719168
# MSpan = 88608 / 180224
# MCache = 4800 / 16384
# BuckHashSys = 1597264
# NextGC = 9428528

And I didn't know why it decrease so little. Because I have already clear the variables saved in server. Would anyone give some advice on how I find the problom?

PS. It is not concerned about goroutine, I checked it, and the numbers of goroutine didn't increase. And I already use pprof and open gcdebug.

  • 写回答

1条回答 默认 最新

  • drema2014 2014-12-17 06:05
    关注

    Because it's not entirely up to Go to shrink it's own memory. The Go garbage collector occasionally makes requests to the OS to release unused memory. The OS may decide to not release the memory because the system has plenty to spare, other some other reason.

    If you are really concerned about you app taking too much memory or leaking memory then pay attention to the HeapAlloc value over time. Make sure that this value stays in your expected range.

    Also, don't expect debug.FreeOSMemory() or runtime.GC() to do what you expect.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog