Giter Club home page Giter Club logo

Comments (9)

lyricsboy avatar lyricsboy commented on July 24, 2024

Can you tell us which version of this library you're using?

Because we're using an unowned reference to self in the saveContext method, and that method executes asynchronously, it's possible for the NSManagedObjectContext instance to be deallocated by ARC before the async save block executes. If you're doing background work on another thread/queue that calls saveContext and finishes its work before that block is done, this could result.

While we could use weak and prevent the crash, it may make the code in saveContext a no-op, which is probably not what you would expect.

We'll look at making the memory semantics of this more clear, but the better fix is probably to use saveContextAndWait for background operations in your code instead.

from coredatastack.

jeremy-w avatar jeremy-w commented on July 24, 2024

It might be more in keeping with the intent of a save call to drop both unowned and weak and instead hold a strong reference to the object till the save completes. I think this would take only a two-word change: remove the [unowned self] in saveContext from SaveHelpers.swift:51.

from coredatastack.

rcedwards avatar rcedwards commented on July 24, 2024

@jeremy-w I like this idea. 👍 I'll let @lyricsboy take a look today and see if we can put a unit test together to cover this case before proceeding.

from coredatastack.

bitomule avatar bitomule commented on July 24, 2024

Can I help with it?

from coredatastack.

jeremy-w avatar jeremy-w commented on July 24, 2024

@bitomule: Sure, the unowned -> strong switch outlined above will hopefully fix it. If you could apply that and verify that it stops your app from crashing, that would be awesome. :D

BTW, did the crash happen reliably for you, or was it only sometimes crashing?

I think @rcedwards was hoping to put a test over it, but that will be hard without introducing something like "build test-only project, run the executable from the test, wait for it to exit, fail if it didn't exit cleanly", since a failing test within the test process will kill the test process itself and prevent running other tests. :)

from coredatastack.

bitomule avatar bitomule commented on July 24, 2024

@jeremy-w that could fix it but my issue only happened once after a lot's of saves so not easy way to test it.

from coredatastack.

rcedwards avatar rcedwards commented on July 24, 2024

Addressed in https://github.com/bignerdranch/CoreDataStack/releases/tag/v1.0.2

from coredatastack.

bitomule avatar bitomule commented on July 24, 2024

Thanks, will report if it occurs again. Btw, today we released our iOS app with a powerful core data stack 👍

from coredatastack.

rcedwards avatar rcedwards commented on July 24, 2024

@bitomule fantastic news 🎉 We're happy our stack was able to help with your project.

from coredatastack.

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.