LoadLayout - Memory Issue

Silentsea

Member
Licensed User
Longtime User
Hi community,

I've created some layouts for different activities. In this layouts I've large Background Panels (for example 1280x800) wich are defined with Background Images (in the layout).

If I start my activities there seems no problem, but when I switch between this activities there ist a oom error after some switching. (I only load the layout in the create sub)

I tried to load the images over bitmap in code, but same problem here. And yes I tried loading samples and also SetBackgroundImage(NULL) or using reflection for RunMethod("recycle").

Some other options, which I haven't seen yet?

regards Silentsea
 
Last edited:

Silentsea

Member
Licensed User
Longtime User
Hi Erel,

it is a little complicate to extract and seperate all the files. I can upload our current project state and send you a link per pm. It is difficult because we generate some views etc.
 
Upvote 0

Silentsea

Member
Licensed User
Longtime User
I've mailed our current project, maybe you can have a look.
 
Last edited:
Upvote 0

Silentsea

Member
Licensed User
Longtime User
Hi,

I tried to write a code module which initializes all bitmaps that are in use in different activities, so they will be loaded only once in memory. In the activities the panels will bet set by setbackgroundimage(bitmap).

But then we noticed some (for us) strange behaviors.

InitializeSample:
If I try to initialize 30 big pictures (normaly 1920x1054) with InitializeSample, by parameters maxwidth 960 and maxheight 527. But there comes an oom message at picture 15. If I load a picture that is in size bigger then the max parameters, for example 1280x703 then there is no oom message and the code runs fine. It feals like there is no difference between InitializeSample and only Initialize. Maybe there is a problem in the framework?

Different ram usage on different devices by same code:
The same code running (15 initialized pictures) would allocate 25 Mb Ram at my Galaxy Tab 7.7, at my Galaxy Note round 50. Is there a realtion to the pixel density or why is this double sized?

Another question for my calculations?
Is each pixel in a bitmap object represented as 32 bit integer?

Because of the unreliability of the garbage collector I tried this way, because I've no idea how to free up memory in the activities.

My only thoughts at the moment are to reduce the full hd pictures to smaller ones, load this at main init. And stretch this by gravity in panel?

Thanks in advance.
 
Last edited:
Upvote 0

Silentsea

Member
Licensed User
Longtime User
Hi Erel,

thanks for looking at my code. How I mentioned it is comlicate to devide functionality from layout in our current state but I will try. What do you would like to see, layout files with big images loading ;)?

First back to my open question:
If each layout has a reference to a large background image and keeps this for time, it's no wonder that I go oom eventually, i think. Most Layout will hold sind large picture reference in full hd. Is this right?

InitializeSample loads a sample of the image. The loaded image size will be equal or larger than these value.

Equal or Larger? In which relation? I couldn't get why it should be larger, I noticed the note in the explanation shown, but I didn't got it yet sorry.

Can you explain the different ram usage on different devices?

Regards Silentsea
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Image sampling works by converting x pixels to a single pixel. The value of x depends on the the bitmap size compared to the desired size. x is an integer. So the result is that the loaded image is equal or larger than the desired size.

I tried your second program and it does crash. Note that you should not load the layout in Activity_Resume as the layout will be loaded multiple times.

You are trying to load huge background images. You will need to resize the images.

Can you explain the different ram usage on different devices?
I'm not sure. It may be related to the different densities.
 
Upvote 0

Silentsea

Member
Licensed User
Longtime User
Erel as I comment, I load these in resume to simulate the behaviour because I've some activities with large layouts. I will of course load the layouts in the activity create. Just a sample.

But then, how can I support full hd pictures? I near future the first full hd display launches, it is annouced for june (Acer Iconia 700A).

Regards Silentsea
 
Upvote 0
Top