A way to monitor memory usage?

Monkey Targets Forums/Android/A way to monitor memory usage?

Raph(Posted 2013) [#1]
I've been wrestling with this crash for the last day, ever since I added one 512x512 image to each screen in my campaign.



I reduced the frequency by redoing a routine that had a lot of string allocations in it. I also noticed that it happens more often if the images are drawn with alpha, or if I use shadows on the text (using Fontmachine).

I'm discarding the image and loading a new one between pages. Force a GC collect maybe?

Is there a way to monitor memory usage on device while I test and track this down?


Raph(Posted 2013) [#2]
I should mention, I've tried running the Android Debug Monitor. But I an Android noob and not sure what I am seeing :)


Wylaryzel(Posted 2013) [#3]
as far as I know, if the GC is invoked, it is reported in the android debug monitor.

With regards to the memory footprint you can check the task manager or for more details have a look on the VM Heap or the allocation Tracker tab on the debug monitor.

BR
Wyl


AdamRedwoods(Posted 2013) [#4]
E/dalvikvm-heap(20973): Out of memory on a 4194320-byte allocation.

Android Java Machine (aka Dalvik) is frustrating because of heap limitations. it's frustrating.
it depends on type of phone and OS version.

older phones its about 16mb, newer phones its 32mb and up.
so you can only really have 4x4mb images in the heap at once.

i notice you are using bytebuffer access, so you may be keeping these images in memory, which will take up most of the heap but your source program and file loading also uses this same space.

one crude way around this is to add in the manifest.xml:
<application android:largeHeap="true">


the other way is to recycle all available image allocations. after an image bind to opengl, dump the image data or reuse it. this is how mojo works, which is why mojo can use quite a few images.

p.s. Adnroid NDK (c++) avoids the heap limit because it's not using the java vm.


muddy_shoes(Posted 2013) [#5]
If you install Eclipse with the Android dev stuff you'll have access to several methods of looking at memory usage dynamically and statically. http://developer.android.com/tools/sdk/eclipse-adt.html

That allocation looks like a 1024x1024 bitmap, by the way. Simon Read had a similar issue a while back: http://www.monkeycoder.co.nz/Community/posts.php?topic=2589

The code change to mojo discussed in there will only reduce the issue and not solve it if you have a memory leak though.


Raph(Posted 2013) [#6]
You were right, it was a 1024x1024, not a 512x512. I reduced the image to 512 and it seems stable now.

I recently did a graphics pass and redid everything for iOS Retina. I guess it's time to start selectively loading assets. :)

Looks like I now sit at around 85% usage on the 55MB heap according to DDMS. I see optimization in my near future.