realm / realm-java

Realm is a mobile database: a replacement for SQLite & ORMs
http://realm.io
Apache License 2.0
11.45k stars 1.74k forks source link

Unrecoverable error. mmap() failed: Out of memory size #5225

Closed alessandrojp closed 7 years ago

alessandrojp commented 7 years ago

Goal

Don't let the realm file crashed

Expected Results

Realm file not crashed

Actual Results

Realm file crashed

Unrecoverable error. mmap() failed: Out of memory size: 738197504 offset: 0 in /home/cc/repo/realm/release/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 252 io.realm.exceptions.RealmError: Unrecoverable error. mmap() failed: Out of memory size: 738197504 offset: 0 in /home/cc/repo/realm/release/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 252 at io.realm.internal.SharedRealm.nativeGetSharedRealm(Native Method) at io.realm.internal.SharedRealm.<init>(SharedRealm.java:186) at io.realm.internal.SharedRealm.a(SharedRealm.java:239) at io.realm.internal.SharedRealm.q(SharedRealm.java:202) at io.realm.aw.b(RealmCache.java:298) at io.realm.aw.a(RealmCache.java:284) at io.realm.av.aSM(Realm.java:281)

Steps & Code to Reproduce

I'm having several issues on Crashlytics and it seems it only happens on Android 4.x.x It happens when I call Realm.getDefaultInstance() I also checked the free space and in most cases it had at least 40%. Moreover, in most cases it was reported with the same memory size 738197504.

Version of Realm and tooling

Realm version(s): 3.5.0

Realm sync feature enabled: no

Android Studio version: 2.3.3

Which Android version and device: SH-02G 4.4.4 AQUOS CRYSTAL X 4.4.4 404KC 4.4.4 SoftBank 305SH 4.4.4 Xperia Z1 4.4.2 ZenFone 5 LTE (A500KL) 4.4.2

beeender commented 7 years ago

It seems your realm file size getting very big ... See https://realm.io/docs/java/latest/#faq-large-realm-file-size

Do you have any Realm instances are not closed in the background thread?

alessandrojp commented 7 years ago

Thanks for reply. I'll take a look.

Do you have any Realm instances are not closed in the background thread?

No Yes, I just checked here and there is a possibility that it was not closed.

beeender commented 7 years ago

Is it possible that your Realm file getting to that big for some other reasons?

alessandrojp commented 7 years ago

I don't think so. It only happens on devices 4.x.x, it's tough when you can't reproduce it :/

beeender commented 7 years ago

Do you have any Realm instances are not closed in the background thread? Yes, I just checked here and there is a possibility that it was not closed.

That may lead to unexpected Realm file growth. Try to close it properly so the file size won't get to that big which caused the mmap failure.

cmelchior commented 7 years ago

@alessandrojp I assume the above answered your question. If you are still seeing this problem after closing your Realms, feel free to reopen.