Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6207869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:42:31+00:00 2026-05-24T05:42:31+00:00

Why is it that everytime I call save on my NSManagedObjectContext: -(NSManagedObjectContext*)managedObjectContext { NSMutableDictionary*

  • 0

Why is it that everytime I call save on my NSManagedObjectContext:

-(NSManagedObjectContext*)managedObjectContext {
    NSMutableDictionary* threadDictionary = [[NSThread currentThread] threadDictionary];
    NSManagedObjectContext* backgroundThreadContext = [threadDictionary objectForKey:RKManagedObjectStoreThreadDictionaryContextKey];
    if (!backgroundThreadContext) {
        backgroundThreadContext = [self newManagedObjectContext];
        [threadDictionary setObject:backgroundThreadContext forKey:RKManagedObjectStoreThreadDictionaryContextKey];
        [backgroundThreadContext release];

        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(mergeChanges:)
                                                     name:NSManagedObjectContextDidSaveNotification
                                                   object:backgroundThreadContext];
    }
    return backgroundThreadContext;
}

- (NSError*)save {
    NSManagedObjectContext* moc = [self managedObjectContext];
    NSError *error = nil;

    @try {
        if (![moc save:&error]) { //breakpoint in here

    //some code
}

the app seems to be waiting forever and never got back to resume it’s execution? Here’s what I mean in a video. Can this be possibly caused because something is wrong with the entity/relationship model?

Here’s a screenshot of the leaks instruments, I don’t see any leaks, but it seems that the app is allocating something that builds up:

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:42:33+00:00Added an answer on May 24, 2026 at 5:42 am

    Have you tried ditching your multi-threading code to see if it works? My guess would be that you’re mixing up threads here and accessing/saving the MOC from different threads. Managing threads manually is a PITA, you should try switching to Grand Central Dispatch.

    I would also give your main MOC its own accessor so you can make sure it isn’t called from background threads, and have some: - (NSManagedObjectContext*)newBackgroundMOC; and - (void)saveBackgroundMOC:(NSManagedObjectContext*)context; methods to quickly create and save MOCs from background queues/threads:

    dispatch_async(my_queue, ^{
        NSManagedObjectContext *context = [self newBackgroundMOC]; // create context, setup didSave notification to merge with main MOC, etc
    
        // modify context
    
        [self saveBackgroundMOC:context]; // main MOC gets updated
    });
    

    Migrating to GCD is a bit of work, but in the long run you’ll see it’s much more pleasant to work with. It goes without saying that it’s also the most modern and recommended by Apple way to deal with threads.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Coming from C++ it is hard grained into my mind that everytime I call
I'm loading an assembly at runtime and the question that arises everytime I call
It seems that everytime I call a function that returns a PyObject*, I have
I want that everytime someone wants to checkout the project from SVN he/she will
I'm relatively new to Threading in Java and I've noticed that everytime I use
I have a old website that generate its own RSS everytime a new post
I have an asp page that loads a response user=exists everytime I try to
On Windows Vista, with UAC enabled, everytime a program that requires administrative priviledges starts,
Everytime call this stored procedure i get this error: #1064 - You have an
I have this iPhone application that let users take a picture and save it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.