Couchbase Lite Android Fatal Exception: java.lang.OutOfMemoryError

I am using Couchbase Lite 1.4 version.

Sometimes I got following in my crash logs:

Fatal Exception: java.lang.OutOfMemoryError
Failed to allocate a 128 byte allocation with 4194304 free bytes and 6MB until OOM; failed due to fragmentation (required continguous free 4096 bytes for a new buffer where largest contiguous free 0 bytes)
java.util.concurrent.FutureTask.get (FutureTask.java:177)
com.couchbase.lite.replicator.RemoteRequestRetry.get (RemoteRequestRetry.java:221)
com.couchbase.lite.replicator.ReplicationInternal.waitPendingFuturesCompleted (ReplicationInternal.java:1994)
com.couchbase.lite.replicator.ReplicationInternal.waitForAllTasksCompleted (ReplicationInternal.java:1969)
com.couchbase.lite.replicator.ReplicationInternal.waitForPendingFutures (ReplicationInternal.java:1940)
com.couchbase.lite.replicator.ReplicationInternal$25.run (ReplicationInternal.java:1901)
java.lang.Thread.run (Thread.java:761)

What is the reason for such errors? How can I fix these?

This is a very old version of couchbase lite that is officially unsupported and is not actively maintained by Couchbase. Probably not the response you were looking for but would suggest upgrading to the 2.x version.

1 Like

Priya’s reply is the most important. You should upgrade to something much more recent.

I’d like to add, though, that I haven’t seen that error in a very long time. What version of Android are you running? It might be time to upgrade that as well.

As you can see, you have plenty of free memory ( 4194304 free bytes, 6MB until OOM), but the memory is so badly fragmented that you cannot get a contiguous 4K for a buffer.

I’d be surprised it that were even possible on a version of Android >=19

1 Like

Got this error on Android 7,8,9, 10 evenly distributed.

Upgradation is in our plans, but it will take time do so.

Do have mirgation instructions for such cases?

This SO answer may be useful to you.

In order to reduce jank, ART on Androids 5-7 only run compaction when some thread other than the main thread holds the processor…

1 Like

Do have mirgation instructions for such cases?

We don’t have official migration guides. But this blog should be a good start.

1 Like

Useful information, but unfotunately it seems like not my case at all, since I am running replication in the background thread (android background service).

An Android Service runs on an application’s Main/UI thread.