Bug? Bitmap memory bug

francoisg

Active Member
Licensed User
Hi Erel,

When an imageView is declared in an Activity and a Bitmap image is assigned to it (either in code or within Layouts), now when an activity is closed and re-opened X number of times, the app will sooner or later "Downsample" the images due to a lack of memory, and then crash. (In my case, I only had to reopen the activity 7 times, before it starts "Downsampling")

It seems like, every time an Activity is created (and Bitmaps are loaded) it creates new instances in memory, and previous instances of the closed activity is still retained and not freed.

A workaround for this, is to declare a Bitmap in the Process_Globals, rather than in the Globals, and then in the Activity_Create, one should check if the the bitmap is already initialized and then reuse that for a View.
But this is not preferable, since with each Activity_Create, a clean slate should be given to the Globals.
 

francoisg

Active Member
Licensed User
Yes, it happens in release mode.
I'm using B4A version 4.30

Attached is a very simple test app:
It starts a new activity, loads a layout with an image, closes the activity, and repeats the cycle automatically (with 1 second interval)
On my phone, the image gets pixelated on count 23 and crashes on count 28
 

Attachments

francoisg

Active Member
Licensed User
I did some more debugging...
The problem seems to occur when the Layout's "Animation Duration" is > 0
otherwise it seems to be stable.
 

Erel

Administrator
Staff member
Licensed User
Note that you should use File - Export as zip when uploading projects.

I wasn't able to reproduce it. Tested it in both release mode and rapid debug mode.

With that said, you are loading a very large image (1900 * 1200). It will consume more than 9 mb of memory. If your device doesn't manage the memory quick enough it may fail to allocate the required memory.

Use LoadBitmapSample instead or decrease the image size.
 

francoisg

Active Member
Licensed User
Yes, I've used the 1900 * 1200 image to get to the result faster.
I've reduced the image size to 480 * 300 (113KB) and double the time interval just to be sure. With patience, the "Downsampling" message eventually start appearing in the Log console, and went the same route.

I'm pretty positive that this happens when the Layout Designer's Animation Duration Property is anything greater than 0, but if the Property is equal to 0, then all is fine.
 

jorgesegura

Member
Licensed User
Hi

I have the same problem .
I did what you mentioned about the animation put it to zero.
and is now stable. Thanks
 

Reviewnow

Active Member
Licensed User
I had this same issue I was not loading any image only using a blank canvas to draw on after 5th or 6th time of showing the same layout with a blank canvas I received the
Downsampling image due to lack of memory error and the application would force close
setting Animation Duration Property to 0 resolved it
 
Top