realm-swift: {ERROR} [PERSISTENCE] mmap() failed:Cannot allocate memory size: 25346048 offset: 67108864

Goals

I am trying to update a fairly big object graph (33 RLMObject subclasses). I have 200 instances retrieved from the RLMRealm of one of the parent objects. I am trying to update some of the attributes of the parent along with its children, children of children, children of children of children, etc…

Expected Results

I would expect to be able to update all the fields for any of the parent and children objects that I previously retrieved from the store.

Actual Results

When updating a deep nested object I get an exception: {ERROR} [PERSISTENCE] mmap() failed: Cannot allocate memory size: 25346048 offset: 67108864

#0	0x000000010d5b51e8 in realm::util::EncryptedFileMapping::read_barrier(void const*, unsigned long, unsigned long (*)(char const*)) ()
#1	0x000000010d2a784c in realm::util::do_encryption_read_barrier(void const*, unsigned long, unsigned long (*)(char const*), realm::util::EncryptedFileMapping*) ()
#2	0x000000010d4eac80 in realm::BPlusTreeBase::create_root_from_ref(unsigned long) ()
#3	0x000000010d2a79e4 in realm::BPlusTreeBase::init_from_parent() ()
#4	0x000000010d525f8c in realm::Lst<realm::ObjKey>::Lst(realm::Obj const&, realm::ColKey) ()
#5	0x000000010d527230 in realm::LnkLst::LnkLst(realm::Obj const&, realm::ColKey) ()
#6	0x000000010d520124 in realm::Obj::get_listbase_ptr(realm::ColKey) const ()
#7	0x000000010d2b29f4 in realm::List::List(std::__1::shared_ptr<realm::Realm>, realm::Obj const&, realm::ColKey) ()
#8	0x000000010d3026f4 in -[RLMManagedArray initWithParent:property:] ()
#9	0x000000010d2f01e8 in ___ZN12_GLOBAL__N_113managedGetterEP11RLMPropertyPKc_block_invoke ()
#10 MyLocalObject.status = [MyServerObject retrieveStatus]

Steps to Reproduce

Instantiate an Encrypted Realm and store 200 difference instances of the same RLMObject subclass. Ensure the RLMObject has a big object graph with lots of nested children. Allocate in memory another 200 instances of the same RLMObject and try to update the 200 instances retrieved from the store with the attributes from the 200 instances allocated in memory.

Version of Realm and Tooling

Realm framework version: ? 5.0.3

Realm Object Server version: ? N/A

Xcode version: ? 11.3.1

iOS/OSX version: ? 13.5

Dependency manager + version: ? N/A

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 5
  • Comments: 28 (8 by maintainers)

Most upvoted comments

Some acknowledgement of this one would be great. Would have been super dangerous to have released this to my users, without a way for them to downgrade back to a working Realm version!

Same with me. The issue started to appear after update from 4.4.1 -> 5.0.2 and on 5.0.3 too. Autorelease pool doesn’t seem to fix the situation. On non-encrypted too.

v5.3.3 did improve my app from immediately crashing re: the Realm notification listener. Thank you.

I confirmed that setting up a listener to .observe objects while the DB is in the process of writing objects is what causes my crash.

Of course now it’s just a limit case.

Setting config.maximumNumberOfActiveVersions = 3, is too low and crashes as before. Setting config.maximumNumberOfActiveVersions = 64 though seems to hold up much better without the exception crash. 👍

I’ll run some more longer tests on my iPad that syncs down all 40k+ objects to confirm its stability. 🤞

[Update: Aug. 11, 2020] This seems resolved…

I’ve successfully reproduced a bug where we weren’t releasing old versions in a place where we should, which would cause this problem.

The problematic case that I’ve found is when you’re holding onto a Results which you don’t read from after every write transaction.