0

This is happening on an embedded system that is using a custom build of Android 4.0.2 platform. I see one of our android activity apps growing to around 400MB (rss size when "ps" is invoked) and getting killed by Linux OOM killer. The android platform was configured with max heap size set to 62M. I am clueless how Dalvik VM let the activity grow to 400MB.

Shouldn't the app get Java out of memory exceptions when heap reaches around 60MB? We don't see those Java exceptions in the logcat logs or in anr traces.

We implemented a sample activity that allocates byte arrays in sequence and set each byte to a dummy value. We do see Outofmemory exceptions when the activity allocated around 60MB.

Are there allocation paths in android that don't get counted towards heap budget? The activity renders bitmap pngs downloaded from a web site.

Below are "getprop" results on our platform.

$ adb shell getprop | grep -i heap

I appreciate any pointers.

Thanks

Edited: Note: Below is ps output. The Pss and Uss are around 316M which is way above.

                             PID      Vss      Rss      Pss    Uss    cmdline
logcat: hd[0]: pexecd(65):   982  351512K  351316K  326300K  316632K  mytest.home^M
logcat: hd[0]: pexecd(65):   660  679916K   61044K   57200K   56952K  ./videngine^M

RAM: 741764K total, 20320K free, 2148K buffers, 80104K cached, 24964K shmem, 10368K slab
Kara
  • 6,115
  • 16
  • 50
  • 57
videoguy
  • 1,732
  • 2
  • 24
  • 49

3 Answers3

2

Direct allocations in native code don't count against that Java heap total. There may be other possibilities as well (perhaps pages mapped and populated from files?).

If you have a custom android build, you may be able to set OOM killer values to preserve your own application.

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
  • It is plain android app without any custom JNI stuff going on. I want JVM throw OOM exceptions instead of letting the process grow to 400MB. – videoguy Apr 16 '13 at 22:03
  • It may not be custom (actually I had thought - perhaps mistakenly - it wasn't even your app), but what does it do? There's lot of JNI in platform code. – Chris Stratton Apr 16 '13 at 22:16
  • This app loads a web page using android web browser control. Looks like Webkit engine does lot of allocations in native code outside of Android Java heap based on page being downloaded. That explains why the app grew to 300MB+. – videoguy Apr 19 '13 at 22:14
2

I see one of our android activity apps growing to around 400MB (rss size when "ps" is invoked)

To quote Dianne Hackborn, regarding the output of ps on Android: "the Vss and Rss columns are basically noise (these are the straight-forward address space and RAM usage of a process, where if you add up the RAM usage across processes you get an ridiculously large number)"

I would heartily encourage you to read her epic SO answer on measuring an app's memory footprint. Notably, Rss plays no role in her analysis, beyond the quote I cited above. Hence, I would suggest not worrying about Rss and focus on other metrics.

Community
  • 1
  • 1
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I am going to take a look at the thread. Thanks for sharing. This is what I am seeing when "ps" invoked. logcat: hd[0]: pexecd(65): 982 351512K 351316K 326300K 316632K mytest.home^M logcat: hd[0]: pexecd(65): 660 679916K 61044K 57200K 56952K ./native_engine^M ... – videoguy Apr 16 '13 at 23:34
1

Here is what you can do to get an idea of what memory your app is using.

Go to DDMS, and create a heap dump by clicking the icon that looks like this: HPROF

Next convert the HPROF in android format to regular HPROF format using the hprof-conv tool in the androir-sdk/tools folder.

Next, open the heap dump with Eclipse Memory Analyser (MAT), and look at the dominator tree, there you will see a list of variables that your app is forcing the Dalvik Garbage Collector (GC) to keep. Right click on them and go to "Path the GC root", and "Exclude Weak References", will show you the references thats keeping those objects alive. Look and see if you have any expired references that's been kept as a memory leak.

You can watch this video for much detailed way of find memory leak in Android application.

wangyif2
  • 2,843
  • 2
  • 24
  • 29
  • Thanks for the info and the link. We are going to fix the memory leak. The thing that bothers me is why Dalvik runtime didn't throw any OutOfMemory exceptions. – videoguy Apr 18 '13 at 14:17
  • 1
    Not everything is allocated on the Dalvik Heap, various things are going to get larger, and they might reflect in the application memory (eg. the running application tab under settings), such as JIT, or something else. I would really recommend watching the video from I/O, it explains in detail what goes on the Heap, and how an outOfMem Exp is thrown. – wangyif2 Apr 18 '13 at 15:44