-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: gomobile cause memory issue on android when use with react-native and fresco #20156
Comments
By the way same code on ios does not has this problem. |
Does the problem disappear on arm64 devices (running with arm64 native code)? You can build an arm64-only binary with gomobile bind -target android/arm64 or by specifying GOARCH="arm64" to the gobind gradle plugin. You could also try to disable the ashmem optimization in fresco (if possible. I don't know fresco myself) and see if that helps. |
Got an error when specify GOARCH="arm64"
The gobind gradle plugin
|
Are you running on an Android device and Android version that are both capable of running arm64 code? Your log file shows dalvik-related messages and I think only ART is 64-bit capable. Also, you'll need at least Android 5.0, which I believe is the first release that could handle 64-bit code. Note that this is not a realistic workaround for 4.x devices. It's simply a quick test to see if the problem is related to the limited virtual memory available on 32 bit. |
I test it on android 5.0 and 6.0. The starting fail still happens. The logcat is shown below
But as fresco do not use Ashmem on android 5.0+, so the crash seems not happen so easily. |
React Native and/or fresco is probably using 32-bit libraries, blocking ART from running in 64-bit mode. facebook/react-native#2814 seems to indicate that at least reach native doesn't run in 64-bit mode at all. |
Maybe it's not caused by running out virtual memory. Because my android phone has 3000MB RAM. If I run it with Go, the app crashes when the app only takes about 200Mb memory. But normally the app will be crashed when the memory is taken above 1000MB. |
Go tip (to become Go 1.11) now uses fragmented heap maps. If you're feeling adventurous, please retry with go tip. You'll have to download the Go source and run ./make.bash from the src/ directory and use the go command from the bin/ directory. |
Are you sure this could let the problem go away ? |
I'm not sure, that's why I'm asking you to try it. |
It is worth a try. Thank you for your advice. |
@eliasnaur Just another question: Will the release Go of 1.11 officially uses fragmented heap maps ? |
And I couldn't find go 1.11. Google has said nothing about 1.11 and the fragmented heap maps. Where did you get info ? |
Fragmented heap maps were added to tip in https://golang.org/cl/96779 and https://golang.org/cl/96780. They will be in the future Go 1.11 release. |
@ianlancetaylor You mean if I wanna check this I could just git clone the golang repo and switch to this commit then compile ? |
Yes. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.7.4 darwin/amd64
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/nary/Desktop/gopath
GORACE=""
GOROOT="/usr/local/Cellar/go/1.7.4_1/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.7.4_1/libexec/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/f8/73mv3kjn2rxcv3rv_zvs6tn40000gn/T/go-build352177269=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
What did you do?
use gomobile to create react-native cross platform app
What did you expect to see?
What did you see instead?
It is very easy to crash on android 4.3 when you use gomobile with react-native.
on android 4.4 and 5.0, 6.0 the situation is a little better but it will still lead to memory issue and the pic will never show when you browse a lot.
I create a complete reproducable demo on my github. https://github.com/narychen/ReactNativeListTest
It just print hello call from the gomobile in android/app/src/main/java/com/listtest/MainApplication.java
On android 4.3 it will quickly crash and the android log shows
On android 4.3 and earlier version the facebook fresco module use Ashmem to manage the pic memory. So error shows that 'sharedmem_gpumem_alloc: mmap failed errno 12 Out of memory'.
And if gomobile somewhere conflict with fresco on Ashmem. It may cause this problem.
Nowadays, react-native and fresco is used everywhere. Hope the gomobile team could see this problem and solve it.
When you use the demo, just change the GOPATH in android/gotest/build.gradle and you will compile it. If you are not familiar with react-native, just cd the demo's directory and run command
or use android studio to compile and run it.
Should be test on real devices.
Thanks.
The text was updated successfully, but these errors were encountered: