question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Optimize realm database when Out of memory caused

See original GitHub issue

I’m facing with out of memory error. Here is stack trace: Exception io.realm.exceptions.RealmError: Unrecoverable error. mmap() failed: Out of memory size: 738197504 offset: 0 in /tmp/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 238 I found a solution is using compactRealm and I put Realm.compactRealm(getRealmConfig()); at line 116 in OnCreate() of Application class. It is ok if database become not too large enough to get Out of memory size or I get this exception. Exception io.realm.exceptions.RealmError: Unrecoverable error. mmap() failed: Out of memory size: 939524096 offset: 0 in /tmp/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 238 io.realm.internal.SharedRealm.nativeGetSharedRealm (SharedRealm.java) io.realm.internal.SharedRealm.<init> (SharedRealm.java:185) io.realm.internal.SharedRealm.getInstance (SharedRealm.java:237) io.realm.internal.SharedRealm.getInstance (SharedRealm.java:201) io.realm.BaseRealm.compactRealm (BaseRealm.java:601) io.realm.Realm.compactRealm (Realm.java:1772) x.y.z.App.onCreate (App.java:116)

Version of Realm and tooling

Realm version(s): 3.4 Snapshot

Android Studio version: 3.0.0

Which Android version and device: 5.0.2

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
cmelchiorcommented, Sep 18, 2018

Also keep an eye out for warnings like this: “Remember to call close() on all Realm instances. Realm %s is being finalized without being closed, this can lead to running out of native memory.”

This Realm object finalizer will log this as warnings if close is not correctly called. If you don’t see these and still run out of memory because of large file sizes, it means that you are actively holding on to resources somehow.

1reaction
kainjinezcommented, Nov 15, 2017

Hi @Zhuinden
I forgot using realm.close() when developing small app. By time, i received some Firebase crashes from user that they reached Out of Memory with Realm. Now i close realm in java code and trying to compact database for who reached Out of Memory error. That’s it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Realm API is Optimized for Performance & Low Memory ...
Learn about the Realm API classes that allow for performant and robust apps.
Read more >
Out of memory error when reading Realm database after ...
I am currently using Realm database on my Android application to retrieve data according to user defined filters and to synchronize with a ......
Read more >
Realm: Create reactive mobile apps in a fraction of the time
When the storage engine cannot allocate native memory or the file system is full, Realm will throw an java.lang.OutOfMemoryError exception. It is important...
Read more >
Resolve Out Of Memory Issues - SQL Server - Microsoft Learn
Increase the value of MAX_MEMORY_PERCENT. If the database is bound to a resource pool, which is best practice, the memory available to restore ......
Read more >
Realm - Revision #10
The Realm Database supports the features that optimize the memory usages for some data structures. For example, the database will convert a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found