Repository: go
Issue: x/mobile: gomobile cause memory issue on android when use with react-native and fresco
Labels: mobile

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
```
  public void onCreate() {
    super.onCreate();
    Log.i("gotest", Gotest.greetings("gotest"));  //delete it will make the app work without crash
    SoLoader.init(this, /* native exopackage */ false);
  }
```
On android 4.3 it will quickly crash and the android log shows
```
04-28 11:40:42.691 23953-24922/com.listtest D/skia: ---------- mmap failed for imageref_ashmem size=8294400
04-28 11:40:42.901 23953-24890/com.listtest D/dalvikvm: GC_FOR_ALLOC freed 12460K, 30% free 18487K/26372K, paused 18ms, total 19ms
04-28 11:40:42.901 23953-24890/com.listtest I/dalvikvm-heap: Grow heap (frag case) to 23.802MB for 4194320-byte allocation
04-28 11:40:42.931 23953-24922/com.listtest D/dalvikvm: GC_FOR_ALLOC freed 45K, 27% free 22544K/30472K, paused 16ms, total 16ms
04-28 11:40:42.941 23953-24922/com.listtest I/dalvikvm-heap: Grow heap (frag case) to 27.764MB for 4194320-byte allocation
04-28 11:40:42.971 23953-24899/com.listtest D/dalvikvm: GC_FOR_ALLOC freed 135K, 23% free 26645K/34572K, paused 14ms, total 15ms
04-28 11:40:42.981 23953-24899/com.listtest I/dalvikvm-heap: Grow heap (frag case) to 31.770MB for 4194320-byte allocation
04-28 11:40:42.981 23953-24922/com.listtest D/skia: ---------- mmap failed for imageref_ashmem size=8294400
04-28 11:40:42.991 23953-24899/com.listtest D/skia: ---------- mmap failed for imageref_ashmem size=8294400
04-28 11:40:43.021 23953-24917/com.listtest D/dalvikvm: GC_FOR_ALLOC freed 8207K, 26% free 22547K/30468K, paused 16ms, total 16ms
04-28 11:40:43.021 23953-24917/com.listtest I/dalvikvm-heap: Grow heap (frag case) to 27.767MB for 4194320-byte allocation
04-28 11:40:43.031 23953-24917/com.listtest D/skia: ---------- mmap failed for imageref_ashmem size=8294400
04-28 11:40:43.111 23953-24917/com.listtest D/dalvikvm: GC_FOR_ALLOC freed 4380K, 26% free 22556K/30468K, paused 16ms, total 16ms
04-28 11:40:43.121 23953-24917/com.listtest I/dalvikvm-heap: Grow heap (frag case) to 27.776MB for 4194320-byte allocation
04-28 11:40:45.731 23953-24899/com.listtest D/dalvikvm: GC_FOR_ALLOC freed 8307K, 30% free 18594K/26372K, paused 17ms, total 17ms
04-28 11:40:45.741 23953-24899/com.listtest I/dalvikvm-heap: Grow heap (frag case) to 21.907MB for 2097168-byte allocation
04-28 11:40:45.831 23953-24890/com.listtest D/dalvikvm: GC_FOR_ALLOC freed 198K, 28% free 20524K/28424K, paused 15ms, total 15ms
04-28 11:40:45.841 23953-24890/com.listtest I/dalvikvm-heap: Grow heap (frag case) to 23.791MB for 2097168-byte allocation
04-28 11:40:45.941 23953-24922/com.listtest D/dalvikvm: GC_FOR_ALLOC freed 316K, 26% free 22563K/30476K, paused 27ms, total 27ms
04-28 11:40:46.101 23953-23953/com.listtest W/Adreno-GSL: <sharedmem_gpumem_alloc_id:1427>: sharedmem_gpumem_alloc: mmap failed errno 12 Out of memory
04-28 11:40:46.101 23953-23953/com.listtest E/Adreno-GSL: <ioctl_kgsl_sharedmem_alloc:1528>: ioctl_kgsl_sharedmem_alloc: FATAL ERROR : (null)
```
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
```
react-native run-android
```
or use android studio to compile and run it.
Should be test on real devices.
Thanks.