Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/mobile: potential gomobile memory leak #59511

Open
NightBlaze opened this issue Apr 9, 2023 · 4 comments
Open

x/mobile: potential gomobile memory leak #59511

NightBlaze opened this issue Apr 9, 2023 · 4 comments
Labels
mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@NightBlaze
Copy link

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

$ go version go1.20.3 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/nightblaze/Library/Caches/go-build"
GOENV="/Users/nightblaze/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/nightblaze/go/pkg/mod"
GONOPROXY="bitbucket.org//*"
GONOSUMDB="bitbucket.org//*"
GOOS="darwin"
GOPATH="/Users/nightblaze/go"
GOPRIVATE="bitbucket.org//*"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.20.3"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/37/jv5g6pm104l9ty_8gtnrd54h0000gn/T/go-build4126383988=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I use gomobile bind to build shared logic for iOS and Android and it seems that sometimes gomobile doesn't break retain cycles that leads to memory leaks. Probably I use wrong architecture but in any case the behaviour is strange: in one case all created objects was dealloced and in another there was a memory leak.
To reproduce you can check demo project https://github.com/NightBlaze/GomobileDemo

What did you expect to see?

Memory doesn't leak

What did you see instead?

Memory leak

@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Apr 9, 2023
@gopherbot gopherbot added this to the Unreleased milestone Apr 9, 2023
@dr2chase
Copy link
Contributor

Does the amount of leaked memory become large enough to matter, or did you just notice this as an anomaly and the leak is a manageable size? The Go garbage collector doesn't have problems with cycles, but it can be thwarted by stray pointers, especially in the youngest call frame (which should not be a problem here because your example calls debug.FreeOSMemory).

@NightBlaze
Copy link
Author

The amount of leaked memory can vary. In the example project, it is very small, but if we need to hold some images or other big data, then the amount of leaked memory can become unmanageable.

@prattmic prattmic added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 21, 2023
@prattmic
Copy link
Member

cc @hyangah

@NightBlaze
Copy link
Author

If I add

go func() {
	ticker := time.NewTicker(1 * time.Minute)
	for range ticker.C {
		debug.FreeOSMemory()
	}
}()

then "leaked" objects will become dealloced on the ticker tick.

I think it's ok to close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants