You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm investigating this issue, and during profiling with Instruments, I found no heap allocation leaks. However, there is a significant increase in VM allocations. The chart grows exponentially up to 10 GiB and beyond, without ever decreasing.
Upon further investigation, it appears that every time a new Realm instance is created, it allocates 64 MiB in the following call: realm::util::File::MapBase::try_reserve(realm::util::File const&, realm::util::File::AccessMode, unsigned long, long long, realm::util::WriteObserver*)
I suspect this could be the cause of address space exhaustion.
This is how I instantiate and interact with Realm:
The shouldCompactOnLaunch option doesn't mitigate the issue, nor do calling refresh() before using a new Realm instance or invalidate() after finishing.
One potential workaround I’m considering is restricting Realm usage to the main queue, storing the instance in a property, and reusing it instead of creating a new one each time. However, this seems like bad practice since Realm is supposed to return the same instance per thread, even if Realm() is initialized multiple times. Additionally, this approach would prevent me from using advantages of background queues.
Are these VM allocations behaving as expected? Is there a better way to resolve this issue without restricting Realm usage to the main queue?
How frequently does the bug occur?
Always
Description
Our users are experiencing crashes in random places due to the exhaustion of virtual memory address space:
I'm investigating this issue, and during profiling with Instruments, I found no heap allocation leaks. However, there is a significant increase in VM allocations. The chart grows exponentially up to 10 GiB and beyond, without ever decreasing.
Upon further investigation, it appears that every time a new Realm instance is created, it allocates 64 MiB in the following call:
realm::util::File::MapBase::try_reserve(realm::util::File const&, realm::util::File::AccessMode, unsigned long, long long, realm::util::WriteObserver*)
I suspect this could be the cause of address space exhaustion.
This is how I instantiate and interact with Realm:
The
shouldCompactOnLaunch
option doesn't mitigate the issue, nor do callingrefresh()
before using a new Realm instance orinvalidate()
after finishing.One potential workaround I’m considering is restricting Realm usage to the main queue, storing the instance in a property, and reusing it instead of creating a new one each time. However, this seems like bad practice since Realm is supposed to return the same instance per thread, even if Realm() is initialized multiple times. Additionally, this approach would prevent me from using advantages of background queues.
Are these VM allocations behaving as expected? Is there a better way to resolve this issue without restricting Realm usage to the main queue?
Stacktrace & log output
Error Domain=io.realm Code=9 "mmap() failed: Cannot allocate memory (size: 67108864, offset: 2348810240)" UserInfo={Error Name=AddressSpaceExhausted, NSLocalizedDescription=mmap() failed: Cannot allocate memory (size: 67108864, offset: 2348810240), Error Code=9}
Can you reproduce the bug?
Sometimes
Reproduction Steps
No response
Version
10.54.2
What Atlas Services are you using?
Local Database only
Are you using encryption?
No
Platform OS and version(s)
iOS 17.5.1
Build environment
Xcode version: 16.2
Dependency manager and version: cocoapods (1.16.2)
The text was updated successfully, but these errors were encountered: