Android Question Memory Issue

aaronk

Well-Known Member
Licensed User
Longtime User
Hello,

I am having a issue in trying to load a whole heap of images on the page..

When I run my app it will load 20 images in a scrollview and then when the user presses the Next button it will load another 20 images to the end like a list..

Problem I am having is when there is approx 120 images added (and each of the images are the same) I get the following error in the Log:

Downsampling image due to lack of memory.
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
Downsampling image due to lack of memory: 2
Downsampling image due to lack of memory.
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 4
Downsampling image due to lack of memory: 4
Downsampling image due to lack of memory.
Downsampling image due to lack of memory.

Then my App crashes and says it's not responding and closes.
(The above happens on both my Samsung Galaxy S2 (Running Android 4.1.2) and Samsung Galaxy S2 4G (Running Android 2.3)

However, when testing my app on a Sony Xperia Z (Running Android 4.2.2) it works fine and doesn't crash.

My guess is that my Samsung phones don't have as powerful processer and don't have as much RAM as my Sony phone or could there be some type of error I have?

I have a panel I designed in the designer and that panel has a 2 labels, 3 images.

I am adding this panel using the following:
B4X:
MyScrollView.Panel.AddView(new_pnl, 10dip, 100dip, 100%x -20dip, 50dip)
new_pnl.LoadLayout("my_layout")

Like I said it crashes after adding approx. 120 panels with the above in each.
 

eps

Expert
Licensed User
Longtime User
Have you set the image memory to be recycled?

Is your Canvas/Panel defined in Globals? I seem to remember Erel recommending this set up, then effectively you just reuse the memory already set out and don't grab a whole chunk of new memory each time you place 20 images in the App. This may well solve all your problems and mean that you don't need to set the memory to be recycled as you just reuse what you've already set aside.

What have you got the heapsize set to in your manifest file? This might help delay the inevitable if you set it large or something similar.
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
I am not to sure what you mean by recycling the memory.. Are you able to give me a small example on what you mean by this?
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Hello,

I am having a issue in trying to load a whole heap of images on the page..

When I run my app it will load 20 images in a scrollview and then when the user presses the Next button it will load another 20 images to the end like a list..

Problem I am having is when there is approx 120 images added (and each of the images are the same) I get the following error in the Log:

Downsampling image due to lack of memory.
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
Downsampling image due to lack of memory: 2
Downsampling image due to lack of memory.
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 4
Downsampling image due to lack of memory: 4
Downsampling image due to lack of memory.
Downsampling image due to lack of memory.

Then my App crashes and says it's not responding and closes.
(The above happens on both my Samsung Galaxy S2 (Running Android 4.1.2) and Samsung Galaxy S2 4G (Running Android 2.3)

However, when testing my app on a Sony Xperia Z (Running Android 4.2.2) it works fine and doesn't crash.

My guess is that my Samsung phones don't have as powerful processer and don't have as much RAM as my Sony phone or could there be some type of error I have?

I have a panel I designed in the designer and that panel has a 2 labels, 3 images.

I am adding this panel using the following:
B4X:
MyScrollView.Panel.AddView(new_pnl, 10dip, 100dip, 100%x -20dip, 50dip)
new_pnl.LoadLayout("my_layout")

Like I said it crashes after adding approx. 120 panels with the above in each.

Nothing strange here. Your application has a very limited amount of memory available. This amount varies from a device to another. It ranges from 16MB on old devices to a lot more on recent models. If each image occupies 100KB in memory (this amount can be computed with the formula: width*height*4), 120 panels with 3 images = 120*3*100 = 36MB. Add to this the space needed by the code and your other datas, and that will be too much on many devices.

So the solution is simple: use smaller images, or use less. And if some images are always the same, don't create a new bitmap for each one in your ScrollView. Create only one bitmap and set the Bitmap property of your ImageViews to this bitmap.

As you are a licensed user of UltimateListView, I don't know why you don't use ULV in this case. You wouldn't have this problem of memory.
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
As you are a licensed user of UltimateListView, I don't know why you don't use ULV in this case. You wouldn't have this problem of memory

Good point.. I forgot all about using the UltimateListView. Let me try that and see if that fixes my problem.
 
Upvote 0
Top