Android Question Out of memory - Downsampling image

zetadan

Member
Licensed User
Longtime User
I have an app with 120 views and over 200 png images in the layout. When I load the layout, I get the message "downsampling image due to lack of memory" one time. Then every time I load a bitmap in code from DirAssets, I continually get this same error over and over. Even after I reduced the file sizes of the images, I still get the same amount of errors. This just started happening as my app has grown to its present size.

Could this be related to the number of views that are bitmap drawable, the sheer number of images or something else? I have my doubts that it is related solely to the number of images because I have reduced the number and sizes. The one thing I haven't reduced is the number of views.

Would it be better to use a smaller number of views and make them dual purpose? This is somewhat difficult since I use many buttons and use a separate click event for each.

Should I remove the images from the layout and load them into files?

Can anyone help? This is so frustrating as I have hundreds of hours invested in this app.
 
Last edited:

zetadan

Member
Licensed User
Longtime User
Thanks Erel,

If it is not related to the number of views, why when I reduce the number of images in the layout by a large number I get no change? Each view in the layout is set with the default values for width and height. I then change them in code to the necessary size (frequently larger). Should I keep the size of the view very small until I need it? The down sampling first occurs immediately after loading the layout. Most images are not connected to the views in the layout but in the code instead.

This does not seem to be a recycling issue. For some reason the layout is using up the memory and then things get worse. However, once the app is on the phone and not in debug, the problem is limited to the initial condition as does not seem to worsen. Images remain at their current resolution. (down sampled or not but they no longer get worse).
 
Upvote 0

zetadan

Member
Licensed User
Longtime User
I will make sure that the image sizes are only as big as necessary.

I am concerned that this will not fix my problem because I have removed a number of the images such that I have gone back to a number that did not cause massive down sampling previously.

Do you think this problem is compounded by code size, other files taking up resources (audio) or number of variables?

The problem has only increased in magnitude even though I have reduced the number of files. Do you have an idea of approximately how much total image memory may be too much?

Thanks so much for your help.
 
Upvote 0

zetadan

Member
Licensed User
Longtime User
From what I have read, I do not think that Bitmapsample will help. The are over 200 images ranging in size from 50 x 100 to 1000 X 600. I do not need them all in memory at the same time. At say 150 images, I had no problems. And I have reduced the number to 150 again but the probably is just as bad as when I had 200. The images are loaded in the layout and when I load the layout in code the problem begins. How might I go about loading them when I need them and then allowing memory to reuse the space?

Thanks for the answer.
 
Upvote 0
Top