Simon Phoenix Simon Phoenix -4 years ago 164
Android Question

java.lang.OutOfMemoryError:[] of length 1279544898 would overflow

These crashes occur intermittently while backing into my main activity, which consists of two fragments (one being a Google Maps support fragment). If it wasn't for our crash-tracking system, I'd have no idea users were experiencing this, as it is not reproducible on any of my physical or emulated devices. It spans various APIs between my min of 15 and my target of 22.

In the crash system, the crash is occurring in one of two forms:

java.lang.OutOfMemoryError:[] of length 1279544898 would overflow


java.lang.OutOfMemoryError: Failed to allocate a 5118179604 byte allocation with 16777216 free bytes and 472MB until OOM near/at g.newArray:174

The crashing occurs in the onViewCreated method of the fragment containing my map:


My first thought is memory leak, looks like it's looping when creating the backstack -- as if the index of backstacks has overflowed the long. Leak Canary didn't find any memory leaks (except for our MainApplication, which I know retains a static reference to context). And if it WAS a typical memory leak, it seems odd this crash would always occur on the same line and nowhere else. There are other memory-intensive areas of this app (which is enterprise, so I can't divulge too much), but none of those other activities have thrown OOM errors.

I should also note that this is a mature app, with many users and releases. The OOM issue occurs ONLY in the beta of our current release (again, based solely on the records of our crash-tracking system, since we can't repro anywhere). I've done thorough code comparisons between our production release and our beta, and most of the changes are relatively standard/trivial. (I haven't started adding new bitmaps or anything.)

The specs:

  • Play Services 8.4.0

  • Gradle 2.1

  • Target API 22

  • Min API 15

  • ProGuard enabled

Anyone else seeing this? I can see the crash is happening, but it's awfully hard to track down when I can't reproduce it...

Answer Source

Answering my own question...

I was able to repro the error by enabled Don't Keep Activities in developer options.

After three days of testing, I eventually discovered that our build server was compiling support 24 instead of the support 22 I have specified in Gradle. Evidently there's some incompatibility between support 24 and android maps. By changing:

compile ''


compile('') {
    force = true

thus forcing Gradle to take 22 instead of the later 24 available to it, the looping backstack went away. Now I'm no longer seeing the OOM with our beta users.

I speculate it has something to do with the permissions model change of API, but who knows.

Anyway...hopefully this helps someone.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download