FYI, Found same kind of issues reported earlier, but non of the solutions worked for me.
I'm using Realm as DB for my chat application, over time i'm getting crash as below,
Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=9 "mmap() failed: Cannot allocate memory size: 1207959552 offset: 0" UserInfo={NSLocalizedDescription=mmap() failed: Cannot allocate memory size: 1207959552 offset: 0, Error Code=9}:
Added _shouldCompactOnLaunch_, When free space is more than 60% i'm returning _true_
Realm.Configuration(shouldCompactOnLaunch: { totalBytes, usedBytes in
let occupiedPercentage = (Double(usedBytes) / Double(totalBytes)) * 100
let junkFilePercentage = 100 - occupiedPercentage
return junkFilePercentage >= 60
})
I could see _shouldCompactOnLaunch_ works fine, usedBytes before: 102435 after returning true reduced to 4566. Even though i'm getting crash at some point
Deleting realm files default.realm, default.realm.lock, default.realm.management when getting exception in config realm. And re-configuring realm.
Should avoid crash while config realm.
Getting crash with above mentioned exception.
When continuously accessing realm, In my case continuously sending and receiving messages (around 300 message or 2 to 3 hours)
Realm framework version: 4.3.1
Xcode version: 11.3 (11C29)
iOS/OSX version: In all iOS version, especially iOS 13
@gokulgovind Did you fix this issue ?
Same issue here
@gokulgovind , are you using Realm Sync at all, or are these local realms? If you're using Realm Sync then there could be some other lurking variables.
If you're using local realms only, make sure to follow the recommendations tgoyne makes in this thread.
It goes into depth on background threads impact on file size growth.
I'm also experiencing this crash since upgrading from Realm 3.x. When I open the container from my device, the Realm file is quite small (20-30MB, or even 1MB in one case). Is there a way to determine whether it's file size that's causing the trouble? (Maybe the file size bloats momentarily before I'm able to view the file?) I'm stuck, not sure how to diagnose this further.
Thread 17: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=9 "mmap() failed: Cannot allocate memory size: 37748736 offset: 134217728" UserInfo={NSLocalizedDescription=mmap() failed: Cannot allocate memory size: 37748736 offset: 134217728, Error Code=9}
If you are encountering issues due to mmap use Realm.Configuration.maxNumberOfActiveVersions to limit the amount of active versions a Realm contains. This may help you figure out areas in your code which may be holding onto a Realm version too long and cannot be cleaned up, hence causing memory issues.
Setting an arbitrary maxNumberOfActiveVersions to, lets say 5 may help narrow down the issue, but play around with this number.
Please see our release note regarding Realm.Configuration.maxNumberOfActiveVersions here: https://github.com/realm/realm-cocoa/releases/tag/v5.0.0
I've successfully reproduced a bug where we weren't releasing old versions in a place where we should, which would cause this problem.
Most helpful comment
Same issue here