3

I have created a UI that is rich with PNG images for a Xamarin Android application, mostly images are assigned declaratively in the AXML layouts and range from 5 KB to 100 KB in size, unfortunately after running the application and navigating between Activities for sometime the application crashes with messages in the LogCat mentioning memory issues as follow

02-14 21:01:34.856: E/dalvikvm-heap(18277): Out of memory on a 4320016-byte allocation.

02-14 21:01:34.876: D/skia(18277): --- allocation failed for scaled bitmap

Also when I monitored the application using Xamarin Profiler, I found that the memory allocation chart goes up on launching an activity but doesn't go down on closing the activity (although I am using Finish method to close it), which means that the memory consumed by the activity does not get deallocated!

Any idea what could be the problem?

Sisyphus
  • 900
  • 12
  • 32
  • The file size is irrelevant. I can make a 10K file which needs more RAM than a 1MB file. What size are the bitmaps? Are you recycling the bitmaps in onStop()? – Simon Feb 14 '15 at 19:32
  • I assume by the size of the Bitmap you mean size of the ImageView or the View using the images, I am using many images as backgrounds, so that's all the screen size, some backgrounds directly uses PNG files and others use xml files to tile a PNG image. The images are assigned to Views declaratively so I am not sure how to recycle them. – Sisyphus Feb 14 '15 at 20:46
  • Displaying efficiently http://developer.android.com/training/displaying-bitmaps/index.html make sure your bitmaps are eligible for collection. You could take it a step further with weak references. http://stackoverflow.com/questions/28519203/xamarin-out-of-memory-issue – ClintL Feb 16 '15 at 18:41

3 Answers3

1

We had exact same issue, and we had to remove background image to resolve it. I am not sure why Xamarin hasn't received bug report for this.

Wei Ma
  • 3,125
  • 6
  • 44
  • 72
0

I had the same issue recently and I solved it by calling GC.Collect() whenever the problematic activity gets closed

Community
  • 1
  • 1
xleon
  • 6,201
  • 3
  • 36
  • 52
-1

Add below line in your manifest file,

android:largeHeap="true"
prasun
  • 7,073
  • 9
  • 41
  • 59