Csabi
Csabi

Reputation: 3043

Memory issue with my Android app

Hi my Android application is working fine on my Lenovo a319 device , in this device it consuming 40 MB of RAM meanwhile on the Galaxy s5 Device , it consuming 300 Mb for the same build(apk). And I am getting lot of errors such as memory issue on Galaxy s5 device.

For Instance

Out of memory

exception and

android.view.InflateException: Binary XML file line

errors. I have found this Question where it is answered that high pixel resolution will cause memory exception , I am not able to get any clue from that answers provided in that Question , kindly provide the support on the same?

EDIT: Thanks for the answers but they are inacurate i reuse recycle bitmaps and i make them null, even call system.gc(); and my memory is constant, i just do not understand that why it takes 300 MB of ram at sumasung galxy s5 and just 40 on my lenovo. My lenovo is hdpi s5 is xxhdpi if i am sure.

Upvotes: 1

Views: 212

Answers (3)

cnnagpal
cnnagpal

Reputation: 397

This thing can be an easy fix for this

just add this line in your application tag in manifest file

android:largeHeap="true"

like this

<application android:largeHeap="true" android:allowBackup="true" ......

and if you want to more optimize your code then use Memory Analyser in eclipse

Upvotes: 1

Stan
Stan

Reputation: 6551

Looks like your app was built using layouts defined in xml files. These layouts uses images like images for background or source images for ImageButton or ImageView etc. All your drawables are usually stored in drawable-DENSITY folders. So you need to lower resolution of all of your drawables to save some RAM. Like if you have some drawable for ImageView lets call it new_image.jpg and its in drawable-hdpi and its resolution is 800x600 px try to resize it to 400x300 px (you could use a Farstone Image Viewer for this). Do that with every drawable in project and see what happens.
Also it could be that you are displaying images in ListViews using some ImageLoader like Glide (recommended) or UIL or Picasso or whatever use use. Such loaders are usually consuming a lot of RAM (which is configurable however) for caching needs and due to that at one point AOS fails to load, build and represent some your layout which uses images by itself.
Also I recommend you to lern how to display Bitmaps efficiently you MUST know such things.

Upvotes: 2

Ajit Pratap Singh
Ajit Pratap Singh

Reputation: 1289

Apart from bitmaps and drawables the most common problem is leaking memory through the Activity context. Make sure that you are not passing around the activity to callback listeners. A good tool to analyze memory is MAT(Memory Analyzer Tool). It helps you find out memory leaks in your app

Upvotes: 0

Related Questions