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 6139227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:57:47+00:00 2026-05-23T17:57:47+00:00

This is a bit of a tricky one. I have Document entities that are

  • 0

This is a bit of a tricky one.

I have Document entities that are currently being imported into CoreData from a SQLite database on a background thread. There’s a separate context for the background thread and I am batching the save at every 500 entries.

Saving the background thread context triggers a notification which grabs my main thread’s contexts and performs a merge between the two.

Everything works as expected if I am only importing document entities.

My problem occurs when I try and establish a relationship between the current document being created, an another entity called briefcase.

This is what my import routine currently does:

  • Create Briefcase entity
  • Loops through SQLite database rows and creates Document entities for each row
  • Create the relationship between the document in the loop and the briefcase entity
  • At every 500 rows, I save & reset the context. This triggers a ContextSave notification which grabs the main thread and merges with the main thread’s context.
  • This is where my issue is: after the save & reset above, my Briefcase entity gets merged with the main thread so when my loop continues, the next document entity created tries to associate itself with the briefcase, which is where I get a crash saying I can’t establish relationships between objects on separate threads.

I know that if I remove the call to reset the context after saving it, everything works as expected but my memory footprint goes way up and it is not something I am prepared to accept.

So my question is:

  • Can you think of a way of keeping the Briefcase entity around (and valid) for the entire import process so I can continue to create the relationships?

  • My first thought was to create the briefcase entity without a context and then add it to the context once the whole process is finished. This didn’t work very well (it crashed on creation).

Your thoughts are very much appreciated.
Rog

  • 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-23T17:57:47+00:00Added an answer on May 23, 2026 at 5:57 pm

    Answering my own question:

    • Create Briefcase entity
    • Loop through SQLite database rows and create Document entities for each row
    • Create the relationship between the document in the loop and the briefcase entity
    • At every 500 rows, save context & immediately store the objectID for Briefcase after saving
    • Now it’s ok to reset the context
    • (Re)retrieve the briefcase instance using the objectID saved above and the existingObjectWithID:error: method
    • Loop continues…
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This a bit of strange one.... We have an internal web app that runs
This might be a bit tricky setup but... I have this Silverlight project that
Well, I have this bit of code that is slowing down the program hugely
I'm finding this a bit tricky! Maybe someone can help me on this one
Okay, have a bit of a tricky one (for me anyway, i'm pretty rubbish
this is a little bit tricky. usually when someone clicks on a link that
Bit tricky to communicate but hope this makes sense. I have 8 div containers
I have this bit of javascript written with jQuery 1.2.5. It's contained inside the
I have this bit of script to widen a text box on mouseover and
I have this bit of code I found on the web at the end

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.