golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.06k stars 17.68k forks source link

x/mobile: memory ios #21489

Closed gowinder closed 7 years ago

gowinder commented 7 years ago

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.8 darwin/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64" GOBIN="/usr/local/Cellar/go/1.8/libexec" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOOS="darwin" GOPATH="/Users/Mac/Code/golang" GORACE="" GOROOT="/usr/local/Cellar/go/1.8/libexec" GOTOOLDIR="/usr/local/Cellar/go/1.8/libexec/pkg/tool/darwin_amd64" GCCGO="gccgo" CC="clang" GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/gb/k1qql3113734cl6kpzgfzl2m0000gn/T/go-build278014438=/tmp/go-build -gno-record-gcc-switches -fno-common" CXX="clang++" CGO_ENABLED="1" PKG_CONFIG="pkg-config" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2"

What did you do?

i build a shadowsocks local proxy, at windows platform, it just use 5,6, top 8m memory, but when i use
gomobile bind -target=ios proxyproject/my/net invoke the function in IOS network extension, the memory of PacketTunnel start at 6m, and glow to 15 after use safari, 15m is the limit of network extension, when memory use 15m, ios will kill the PacketTunnel why gomobile export function not release memory to system? I do call runtime.GC(), but in windows platform it's ok, but IOS, memory keep growing.

What did you expect to see?

Is there any way to reduce memory on IOS, or return memory to system

What did you see instead?

yamada95 commented 7 years ago
why gomobile export function not release memory to system?

Go will release memory and return them to the OS, but not immediately.

Is there any way to reduce memory on IOS, or return memory to system

You can call debug.FreeOSMemory() to tell GC to return memory, but it may not help much. I found debug.SetGCPercent(10) is more helpful.

I think you should make your code more memory efficient, you may also want to limit goroutine concurrency to make sure they will not eat up all your available memory.

crawshaw commented 7 years ago

As @serika00 says, the two tools available are debug.FreeOSMemory and debug.SetGCPercent.

Note that as this is a question, not a bug report, it shouldn't be on the issue tracker. Please see http://golang.org/wiki/Questions.

gowinder commented 7 years ago

debug.SetGCPercent(10) is usefull, thanks