Jacksonkr
Jacksonkr

Reputation: 32247

Android program crash on random error (caused by java.lang.OutOfMemoryError)

My program runs just fine and then I always encounter a random crash error (eg. Error inflating class ) which is almost always started by a OutOfMemoryError.

I watched my VM Heap in DDMS and it looks like gc is doing it's job as I'll watch the %used go up and down along with the #Objects

I've noticed that I get the crash when I have close to these stats:

Heap Size    11.820 MB
Allocated    7.020 MB
Free         4.801 MB
% Used       59.39%
# Objects    148,927

This is about the peak of usage on the device. Sometimes it crashes here, but other times it allows me to move around to another category which allows GC to do it's work getting the %used down to 32%. However, I usually crash shortly after even though usage is down.

I typically crash out with a chain of errors. The top-most Caused by: error is usually something like Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget

I'm not sure where to go next as the device seems fine on resources when it crashes, but complains about not having enough memory. I've tried running the program without images and I still get an app that crashes. Regardless, where should I start looking to find the culprit?

** EDIT **

Kindle Fire on Android 2.3.4 via Eclipse

Upvotes: 0

Views: 529

Answers (1)

HighFlyer
HighFlyer

Reputation: 1655

In pre-honeycomb android versions bitmap data stores outsize VM heap, so its impossible to track bitmap data via DDMS :) There are two possible reasons: 1. Your interface use giant count of images 2. You create bitmaps manually and memory leak occurs. In one Google IO presentation was said that several garbage collections necessary to completely free bitmap memory


Sorry, missed that app crashed without images. Try dump memory usage periodically and see it later via Eclipse Memory Analyzer

Upvotes: 2

Related Questions