Hello , i would like to share my experience with this error since i was struggeling with it too much without finding a best solution for it.
Im developing a heavy project (Music Player) with a graphical ui , more than 7 activities , 3 services and more, each activity has a background image , has more than 1 layout added to panels , each layout is designed with the designer and has also bitmaps loaded to buttons and panels , so when loading the app with default heap size (64mb) the app crashes due to outofmemory since the activities are loaded more than once and each time a activity is loaded its layout is also loaded wish has bitmaps and those bitmaps are also loaded more than once and still exist in the memory , also in my code im loading bitmaps added to views as background using
Now i ve noticed that this call will load the bitmap into memory but dont release it even if the activity was finished and when i load the activity once again the memory grows and calling
is not efficient for me since i have lots of them.
Notice that im monitoring my app with MAT.
Now what i did is this :
Dimming all bitmaps that i have to use in the proccess global.
In the activity create i load them when the Firsttime is true.
And then share those bitmaps with all activities.
Now the bitmaps are loaded once and remain in the memory even if the Main activity was paused , so with that stratigy my app became healthy since my last memory check was over 160mb (heap = true). Now my app is using around 40mb with all activities loaded.
I think Mr Erel has mentioned this stratigy but no one has consider it.
So if u have views and u want to load a bitmap on it dont use Loadbitmap , just use the already loaded bitmap , btw i noticed also that lets say
Did not grows the memory and that was a advantage , i thing thats how android works.
Now i have something to say to Mr @Erel : as im loyal to B4A and as i noticed some changes in the designer , i would suggest to make a better solution in the designer in the next update when loading bitmaps for the activity or views like panel background , buttons drawables , if could find a way when loading thoses bitmap to recycle them for the next load.
I hope my experience will help u and u could now revise ur code and remain the memory happy , thank u , Joe.
Im developing a heavy project (Music Player) with a graphical ui , more than 7 activities , 3 services and more, each activity has a background image , has more than 1 layout added to panels , each layout is designed with the designer and has also bitmaps loaded to buttons and panels , so when loading the app with default heap size (64mb) the app crashes due to outofmemory since the activities are loaded more than once and each time a activity is loaded its layout is also loaded wish has bitmaps and those bitmaps are also loaded more than once and still exist in the memory , also in my code im loading bitmaps added to views as background using
B4X:
Loadbitmap(file.dirassets,....)
B4X:
Bmp = null
Notice that im monitoring my app with MAT.
Now what i did is this :
Dimming all bitmaps that i have to use in the proccess global.
In the activity create i load them when the Firsttime is true.
And then share those bitmaps with all activities.
Now the bitmaps are loaded once and remain in the memory even if the Main activity was paused , so with that stratigy my app became healthy since my last memory check was over 160mb (heap = true). Now my app is using around 40mb with all activities loaded.
I think Mr Erel has mentioned this stratigy but no one has consider it.
So if u have views and u want to load a bitmap on it dont use Loadbitmap , just use the already loaded bitmap , btw i noticed also that lets say
B4X:
Activity.setbackgroung(bmp)
Now i have something to say to Mr @Erel : as im loyal to B4A and as i noticed some changes in the designer , i would suggest to make a better solution in the designer in the next update when loading bitmaps for the activity or views like panel background , buttons drawables , if could find a way when loading thoses bitmap to recycle them for the next load.
I hope my experience will help u and u could now revise ur code and remain the memory happy , thank u , Joe.