Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mmap() failed: Cannot allocate memory size #6431

Closed
LoicK20 opened this issue Feb 24, 2020 · 3 comments
Closed

mmap() failed: Cannot allocate memory size #6431

LoicK20 opened this issue Feb 24, 2020 · 3 comments
Assignees

Comments

@LoicK20
Copy link

LoicK20 commented Feb 24, 2020

Since my two last release, I have several crashes about realm size file (according crash report):
Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=9 "mmap() failed: Cannot allocate memory size: 1879048192 offset: 0" UserInfo={NSLocalizedDescription=mmap() failed: Cannot allocate memory size: 1879048192 offset: 0, Error Code=9}: file
or
crash_info_entry_0 Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=2 "Unable to open a realm at path '/var/mobile/Containers/Data/Application/B30A63B7-0584-4841-860C-9B62844112ED/Documents/default.realm': Invalid top array (ref: 90691440, size: 0) Exception backtrace: 0 Realm 0x0000000106aeeea8 _ZNK5realm9SlabAlloc6verifyEv + 376 1 Realm 0x0000000106b8e778 _ZN5realm5Group18validate__top_arrayERKNS_5ArrayERKNS_9SlabAllocE + 1364 2 Realm 0x0000000106b96f94 _ZN5realm11SharedGroup7do_openERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEbbNS_18SharedGroupOptionsE + 3224 3 Realm 0x0000000106ab5c58 _ZN5realm5_impl11RealmFriend13read_group_toERNS_5RealmENS_9VersionIDE + 4644 4 Realm 0x0000000106ab58ec _ZN5realm5_impl11RealmFriend13read_group_toERNS_5RealmENS_9VersionIDE + 3768 5 Realm 0x0000

At the first init of my realm instance.
I think it’s not possible the file size should be as big. We don’t save enough data to have this file size.
I don’t reproduce the issue, I just see it in the crash reporting.

I have to get the current user from the database in the application delegate. In the didFinishLaunchingWithOptions method.

Goals

Fetch data from DB

Expected Results

Get data from DB

Actual Results

Crash

Steps to Reproduce

I don’t reproduce the issue, I just see it on my crash report. I print my personal realm file size and I’ve 65536bytes.

Code Sample

In Appdelegate / didFinishLaunchingWithOptions

Realm.Configuration.defaultConfiguration = Realm.Configuration(schemaVersion: dbVersion, migrationBlock: { _, _ in })
realm = try! Realm()
let predicate = NSPredicate(format: "identifier == %@", argumentArray: [userId])
let currentUser = realm.objects(User.self).filter(predicate).first

The application crash at the initialization of the realm instance.

Version of Realm and Tooling

Xcode: 11.3.1
Realm Object Server version: N/A
RealmSwift: 4.3.1

Thanks for advances.

@leemaguire
Copy link
Contributor

One of Realm's current limitations is that a Realm file cannot be larger than the amount of memory your application would be allowed to map in iOS. The exception you're seeing occurs when iOS denies Realm's attempt to map further memory, indicating that you've reached the maximum file size we support for that device. There are a few ways you can attempt to work around this limitation:

  • Split your data across multiple Realms, being sure to close those you're not actively using to minimize memory usage.

  • Compact your Realm file on launch, as described here

Be sure that all write actions are in autoreleasepool { ... }

If you can share further information about the types of data you're storing, or even a sample dataset, we can provide more specific advice. If you're not comfortable sharing this information publicly feel free to do so privately by emailing lee.maguire@mongodb.com and referencing this GitHub issue.

@chenhaigang888
Copy link

我也遇到同样的问题了。不过我们的文件达到了6442450944 。以下是错误日志:
*** Terminating app due to uncaught exception 'RLMException', reason: 'mmap() failed: Cannot allocate memory size: 6442450944 offset: 0' *** First throw call stack: (0x1b99b896c 0x1b96d1028 0x10582d684 0x1057fdcbc 0x1057fef28 0x1057fec4c 0x1057fd618 0x104decde4 0x104c593b8 0x1bdaafc18 0x1bdab1a14 0x1bdab7340 0x1bd24fbec 0x1bd701518 0x1bd250724 0x1bd250154 0x1bd250540 0x1bd24fdc4 0x1bd254544 0x1bd71b39c 0x1bd62d7bc 0x1bd71b354 0x1bd25425c 0x1bd71b23c 0x1bd2540b8 0x1bd0bc434 0x1bd0baef8 0x1bd0bc164 0x1bdab5730 0x1bd64f6bc 0x1bebade10 0x1bebd4aa0 0x1bebb8ef4 0x1bebd4734 0x1b965dfd8 0x1b9660d1c 0x1bebfb254 0x1bebfaf00 0x1bebfb46c 0x1b9934108 0x1b993405c 0x1b99337c8 0x1b992e694 0x1b992df40 0x1c3bbe534 0x1bdab9580 0x1050ad9b8 0x1b97ace18)

@KimiChiu
Copy link

Be sure that all write actions are in autoreleasepool { ... }

Really? That doesn't in the document.
I thought we only need it if we are using realm on worker thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants