Out Of Memory - App Stops

Bill Norris

Active Member
Licensed User
Longtime User
Am experiencing outofmemory crashes of my app. These log files contain alot of stuff I know nothing about. I've attached a text file of the latest crash -- hopefully somebody out there can assist.
 

Attachments

  • crash_log_file.txt
    9 KB · Views: 202

Inman

Well-Known Member
Licensed User
Longtime User
These errors are common if you have many bitmaps in an activity. Apparently these bitmaps don't get unloaded from the memory, even if the activity is closed. One solution is to use LoadBitmapSample to load a scaled down version of the bitmap. If that is not enought, you need to recycle bitmaps, which can be done with agraham's Reflection library.

http://www.b4x.com/forum/basic4android-updates-questions/10760-out-memory-2.html#post62144

Now this doesn't guarantee that you won't get Out of Memory errors again. But it will certainly reduce the chances.
 
Upvote 0

Bill Norris

Active Member
Licensed User
Longtime User
RE:

Bitmap does seem to be the issue. Have one activity with 13 images in a scrollview, each image is 600x700, but only at 72 dpi. (Am developing on a 10" tablet). I put some code in to remove those imageviews when the activity pauses and it appears to have resolved the problem.
 
Upvote 0

Bill Norris

Active Member
Licensed User
Longtime User
I use "Back" buttons on my activities to control which activities are displayed when user is going "backwards". (I capture the device's back button click and it gets ignored). In the click event of my back button, I put this code to remove the imageviews:

B4X:
For i=0 To cursor1.RowCount-1
   myimageview(i).RemoveView
Next
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It depends on whether there is still a live reference to the views. For example if do not clear myimageview array then the views will not be released.

With that said, when the activity is destroyed all the activity global variables are destroyed as well. This means that you usually do not need to do anything special.

The most important tip related to bitmaps is to use LoadBitmapSample instead of LoadBitmap.
 
Upvote 0

Bill Norris

Active Member
Licensed User
Longtime User
RE:

Regarding Bitmap Sample ... in the offending activity, the imageview size for each bitmap is 600 x 700. I sized each of the bitmaps that will load to 600x700 in photoshop, so I am assuming there would be no benefit in this case to use load bitmapsample vs loadbitmap? Also, am I to understand that in order to free up max memory, I need to clear the imageview array, rather than just removing the imageviews? If so, how does one clear an array, perhaps simply re-dim?
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
You need to set each imageview in the array, as null, and if that is not enough, you will have to recycle bitmaps used in those imageviews as well.
 
Upvote 0
Top