kruben
kruben

Reputation: 169

High Memory usage in Android Application (50MB)

I am developing a small tamagotchi for a school project and I have huge problems with the amount of memory the app is using. At first I had 200MB allocated to the app and after a bit of researching I got a easy fix to reduce it to 50MB by renaming the drawable folder into drawable-nodpi. But this is still way to much. While investigating the problem I'm sure that it has something to do with my Layout and UI-Elements because i deleted all my Code and launched my app only with the Layout and the memory usage didn't drop at all.

Here you can see my Layout: App-Layout and Memory-Usage

The image-sizes are in average about 30kb and if I calculate the maximum size of possible images in the memory I have around 1.5MB.

So where does all the memory come from? How is that even possible?

If you want to see the app by yourself you can get the project from github: https://github.com/kruben95/TamaStudent

I would be happy if someone can help me or give me some tips.

Upvotes: 1

Views: 2858

Answers (1)

Stepan Maksymov
Stepan Maksymov

Reputation: 2606

I downloaded your project, and here is some suggestions:

1) images are big resolution even if on disk they take 30-40 kb - in memory they are bitmap and bitmap takes a lot of memory, for example body part - 1200x1980 pixels with 4 bytes per pixel this is 9,5 megabytes in memory!!?? now after this bitmap got it must also scale it - this is additional memory, and as you see you have more then 10 megabytes per only one image!! this is extremely HIGH.

2) make images lower resolution. no need to display them so high res.

3) remove from images invisible parts - as i see very big parts are clear but it takes memory!

4) try to make some images programmatically, like circles etc.

5) in code - don't use alpha for view if you only need to do background, set this alpha directly in color: #00FFFFFF - here is white color with alpha 0. If u use alpha on view it will take additional memory for redrawing (lower performance).

6) google internet for your related topics with tag Best practices and you will find a lot of useful information )

Upvotes: 5

Related Questions