-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
'RLMException', reason: 'mmap() failed #620
Comments
By curiosity, how much data are you trying to mmap? i.e. how large is your realm file on disk? |
Hey @jpsim, thanks for the quick response! It looks like the realm file gets into some kind of locked state and keeps growing larger and larger while I'm inspecting it. A little more context:I'm importing the JSON into models (using an APIObject wrapped via CottonObject) in a background thread, each model has its own write transaction, and when the import is done I execute a completion block with the data on the main thread like this: + (User*) userWithAPIUser:(APIUser*)apiUser wrapTransaction:(BOOL)wrapTransaction
{
// get the default realm and try to find a user to update (else import new)
RLMRealm* realm = [RLMRealm defaultRealm];
User* user = nil;
RLMArray* matchingUsers = [User objectsWhere:@"id == %@",apiUser.id];
// write the user to the database
wrapTransaction ? [realm beginWriteTransaction] : 0;
user = matchingUsers.count ? matchingUsers.firstObject : [[User alloc] init];
user.id = apiUser.id.integerValue;
user.email = apiUser.email;
user.first_name = apiUser.first_name;
user.last_name = apiUser.last_name;
user.token = apiUser.token;
[realm addObject:user];
wrapTransaction ? [realm commitWriteTransaction] : 0;
// return the cached user
return user;
}
+ (NSArray*) usersWithAPIUsers:(NSArray*)apiUsers wrapTransaction:(BOOL)wrapTransaction
{
NSMutableArray* users = [NSMutableArray array];
for (APIUser* apiUser in apiUsers)
{
User* user = [User userWithAPIUser:apiUser wrapTransaction:wrapTransaction];
[users addObject:user];
}
return users;
}
+ (void) usersWithAPIUsers:(NSArray*)apiUsers
wrapTransaction:(BOOL)wrapTransaction
completion:(void(^)(NSArray* users))complete
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^
{
NSArray* users = [User usersWithAPIUsers:apiUsers wrapTransaction:wrapTransaction];
if (complete)
{
dispatch_async(dispatch_get_main_queue(), ^
{
complete(users);
});
}
});
} I've browsed the schema via the Realm Browser and there aren't any duplicate entities either (the ones that exist just get updated). I apologize if I'm doing anything horribly wrong here, I'm more of an audio guy :P |
Are you running this code passing int YES or No to Also, when you dispatch back to the main queue, you are passing an array of RLMObjects which are associated with the RLMRealm instance on the background queue. There isn't currently a way to share objects across RLMRealm instances/threads so for now you need fetch the objects on the main thread after a change. Instead of dispatching back to the main thread you can instead register for a notification and respond in kind to any changes. |
This is such a wonderful framework! Thank you guys so much for open sourcing this.
I've been using running into this exception quite frequently.
Any ideas why the mmap operation can't allocate enough memory?
The text was updated successfully, but these errors were encountered: