Marco24690
Marco24690

Reputation: 355

Xamarin Forms Out Of Memory Android

I'm working with a Xamarin Forms app that uses a lot of button with images. So after some time of navigation my android app crash, beacuse of out of memory problem. How can I handle this problem?

Upvotes: 0

Views: 702

Answers (1)

Zein Makki
Zein Makki

Reputation: 30022

You need to be very careful when dealing with images:

Before an image is displayed on the screen, it has to be loaded into the memory.

Let’s assume you have a brand new device with full HD screen and 12 MP camera. The picture you just took is 4000x3000 pixels large and the total memory needed to display it is: 4 bytes * 4000 * 3000 = 48 MB for a single image!

What you need to do is:

  • Measure the view you’re showing your images in.
  • Scale / crop the large image accordingly.
  • Show only what can be displayed.

Above info from the below resources:

  1. Read More : Here - Point #8.
  2. Read More: Android (Walk-through on how to resize and crop images)

You can follow the same approaches using C# to resize the large images and display them efficiently.

Upvotes: 2

Related Questions