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

Bugs: Crashes on launch for some users.

fatal error: ‘try!’ expression unexpectedly raised an error: Error Domain=io.realm Code=9 “mmap() failed: Cannot allocate memory size: 1744830464 offset: 0” UserInfo={NSLocalizedDescription=mmap() failed: Cannot allocate memory size: 1744830464 offset: 0, Error Code=9}: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-802.0.48/src/swift/stdlib/public/core/ErrorType.swift, line 182

Goals

Not crashing

Expected Results

Not crashing

Actual Results

Some user crash on app launch

Steps to Reproduce

Cannot reproduce on my test device

Code Sample

results = try! Realm()
            .objects(NoteR.self)
            .sorted(byKeyPath: "date", ascending: dateAscending)

Version of Realm and Tooling

  • Realm framework version: 2.5.1
  • Realm Object Server version: NA
  • Xcode version: 8.3
  • iOS/OSX version: 10.3
  • Dependency manager + version: CocoaPod 1.2.0

Further information

As asked in https://github.com/realm/realm-cocoa/issues/4820, the answers are: Can you reproduce this problem yourself at all, or has it only been reported by users? Only by users

Can you reproduce it on demand, or does it only appear to happen at random? For the affected users it happen constantly

Can you describe how your application uses Realm with respect to multiple threads. For instance: a. Do you only use Realm on the main thread? Yes b. Do you use Realm on dispatch queues? No c. Do you use Realm on NSOperationQueues? No d. Do you use Realm on background threads that you’ve created? No e. On which threads / queues do you write to the Realm? Main f. On which threads / queues do you read from the Realm? Main

Is your Realm file only accessed by a single process at a time? Multiple process may be involved if you have multiple apps in an app group that share a Realm, or if you have application extensions that share a Realm with your main app. Only one app

How frequently do you write to the Realm? Not frequent

Do you have multiple threads attempting to write to the Realm simultaneously? No

Have you tested with the most recent version of Realm? v2.5.0 includes a fix for a problem that could lead to unexpected file size growth when you have write contention (i.e., multiple threads attempting to write to the Realm concurrently for an extended period of time). Using 2.5.1

cc @bdash

Stacktrace - Pendo is my app’s name, and RootVC._reloadData calls fetch(), which looks like:

func fetch() {
    results = try! Realm()
            .objects(NoteR.self)
            .sorted(byKeyPath: "date", ascending: dateAscending)
}
0	libswiftCore.dylib	
__hidden#17347_ line 134
specialized _assertionFailure(StaticString, String, file : StaticString, line : UInt, flags : UInt32) -> Never
1	libswiftCore.dylib	
__hidden#18979_ line 221
Error<A where ...>._code.getter
2	libswiftCore.dylib	
swift_errorInMain + 26
3	Pendo	
(Missing)
4	Pendo	
RootVC.swift line 0
specialized RootVC._reloadData(Bool, src : String) -> ()
5	Pendo	
RootVC.swift line 0
specialized RootVC.refetchData(String) -> ()
6	Pendo	
RootVC.swift line 0
RootVC.init(collectionViewLayout : UICollectionViewLayout, moc : NSManagedObjectContext?) -> RootVC
7	Pendo	
PendoAppDelegate.swift line 98
specialized PendoAppDelegate.application(UIApplication, didFinishLaunchingWithOptions : [UIApplicationLaunchOptionsKey : Any]?) -> Bool
8	Pendo	
PendoAppDelegate.swift line 0
@objc PendoAppDelegate.application(UIApplication, didFinishLaunchingWithOptions : [UIApplicationLaunchOptionsKey : Any]?) -> Bool
9
UIKit	
-[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 380
22
UIKit	
UIApplicationMain + 208
23	Pendo	
DetailVC+Cmd.swift line 17
main
24	libdyld.dylib	
start + 4

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

Hi @hyouuu. Thanks for filing this separate issue. We’ll review what you’ve shared and someone will follow-up with you where necessary.