Hi,
After some research it looks like I may not be closing all the realm I am opening.
Going through the code I see that I am correctly closing the realms in finally.
Any idea what the problem could be?
Realm 3.5.0
Crashlytics
Fatal Exception: java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by io.realm.exceptions.RealmError: Unrecoverable error. mmap() failed: Out of memory size: 1476395008 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(SharedRealm.java)
at io.realm.internal.SharedRealm.(SharedRealm.java)
at io.realm.internal.SharedRealm.getInstance(SharedRealm.java:239)
at io.realm.internal.SharedRealm.getInstance(SharedRealm.java:202)
at io.realm.RealmCache.doCreateRealmOrGetFromCache(RealmCache.java:298)
at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:284)
at io.realm.Realm.getDefaultInstance(Realm.java:281)
at app.devUtilities.Cache.Cache.retreive(Cache.java:87)
at app.devUtilities.Cache.CacheObject.load(CacheObject.java:65)
at app.Models.Meta.ProfileMeta.isProfileMetavalid(ProfileMeta.java:27)
at app.controllers.Profile.ProfileController$1.doInBackground(ProfileController.java:128)
at app.controllers.Profile.ProfileController$1.doInBackground(ProfileController.java:116)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Hello @trr-amsiq Is there something you can reproduce?
@dalinaum I am trying as we speak!
You should check with getGlobalInstanceCount() if you truly do close the Realms everywhere, or if there is something somewhere on the AsyncTask's thread pool that remains unclosed; or if there is an IntentService for example that never closes it, and so on.
Hi @Zhuinden I unable to reproduce the issue. I have been stress testing the application my loading multiple objects, lists at once and getGlobalInstanceCount() returns 1 90% of the time and does not exceed 2.
@trr-amsiq I added Reproduction Required here. If you can reproduce this problem, please update this issue or share your code.
In that case, a possibility is that you have a for loop where you insert each item in a new transaction, instead of adding multiple items in one transaction. Or you just have too many Realms on too many threads at the same time and don't compact it on launch or on exit.
@Zhuinden I have no loops wrapping begintransaction().
Just added Compact on after Realm.init(this). I will report back with any updates
@trr-amsiq I think you can compactOnLaunch if you want to add Compact after Realm.init.
https://realm.io/docs/java/3.5.0/api/io/realm/RealmConfiguration.Builder.html#compactOnLaunch--
@Zhuinden
It seems to have helped! Thank you so much for the hint.
@dalinaum
I will update the code to use the config builder!
Thank you very much both of you.
@trr-amsiq
It looks like you have, at least, a workaround. I am going to close this issue. If you can reproduce the problem, please open a new issue right away.
Thanks!
-blake
up
"up" what exactly? This means the file is too big so it cannot be memory mapped.
Depending on file size, this can be either expected, or a result of not closing Realm properly.
Most helpful comment
@trr-amsiq I added
Reproduction Requiredhere. If you can reproduce this problem, please update this issue or share your code.