Open NightBlaze opened 1 year ago
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).
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.
cc @hyangah
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.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat 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