Uploaded image for project: 'Realm Cocoa SDK'
  1. Realm Cocoa SDK
  2. RCOCOA-588

Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=9 "mmap() failed: Cannot allocate memory size: 1207959552 offset: 0"

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • Q2-22FY
    • Affects Version/s: None
    • Component/s: None

      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=

      {NSLocalizedDescription=mmap() failed: Cannot allocate memory size: 1207959552 offset: 0, Error Code=9}

      :}}

      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

            Assignee:
            lee.maguire@mongodb.com Lee Maguire
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: