Giter Club home page Giter Club logo

Comments (4)

jpsim avatar jpsim commented on May 17, 2024

By curiosity, how much data are you trying to mmap? i.e. how large is your realm file on disk?

from realm-swift.

syedhali avatar syedhali commented on May 17, 2024

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.
Started: 25KB
Reload same data (update or insert): 122KB
Keep loading page over and over (update or insert): 500KB
More (update or insert): 2MB
More: 12.6MB
More: 25.2MB
After 25.2MB it keeps climbing by itself (the app is not running) until it reached ~300MB (I deleted it at that point). I've attached some screenshots of the realm files I would download from the app bundle and inspect.

screen shot 2014-07-19 at 12 50 03 am
screen shot 2014-07-19 at 1 00 10 am
screen shot 2014-07-19 at 1 00 27 am
screen shot 2014-07-19 at 1 01 12 am

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

from realm-swift.

alazier avatar alazier commented on May 17, 2024

Are you running this code passing int YES or No to wrapTransaction? If you are constantly running through inserts/updates without ever closing a transaction you will end up using a huge amount of temporary disk space which will not get reclaimed until the transaction is closed. This might also explain the mmap issue. If you are using a single outer transaction (NO for wrapTransaction) then try passing in YES for wrapTransaction to see if that changes the behavior. I would also suggest using a single transaction in usersWithAPIUsers:wrapTransaction: around each group of users rather than using a transaction for each user.

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.

from realm-swift.

timanglade avatar timanglade commented on May 17, 2024

This was probably related to #709 which we fixed earlier this morning, per the ML

from realm-swift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.