-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
SDK FY21-Q3.
-
6469
FYI, Found same kind of issues reported earlier, but non of the solutions worked for me.
Issue
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=
:}}
Thinks to be know,
- I'm using custom realm configuration
- My realm file is in shared container (To access from Notification service extension)
- Messages will be written to realm from Notification service extension.
- Using realm in background thread, realm will be configured every time when realm is required in BG thread. Since realm used in a thread should be created from same thread.
Solutions tried
- 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.
Expected Results
Should avoid crash while config realm.
Actual Results
Getting crash with above mentioned exception.
Steps to Reproduce
When continuously accessing realm, In my case continuously sending and receiving messages (around 300 message or 2 to 3 hours)
Version of Realm and Tooling
Realm framework version: 4.3.1
Xcode version: 11.3 (11C29)
iOS/OSX version: In all iOS version, especially iOS 13