Skip to content
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

Crash likely due to Photographer and PhotoClub zombies #100

Closed
vdhamer opened this issue Dec 30, 2022 · 0 comments · Fixed by #102
Closed

Crash likely due to Photographer and PhotoClub zombies #100

vdhamer opened this issue Dec 30, 2022 · 0 comments · Fixed by #102
Assignees
Labels
Bug Something isn't working

Comments

@vdhamer
Copy link
Owner

vdhamer commented Dec 30, 2022

This crash looks like an Automatic Reference Counting issue. ARC is removing PhotoClub or Photographer objects (NSManagedObject in Core Data) that are still being referenced. This is known as "zombie objects".

Observed error messages (listed below)

  • isTemporaryID seems to be CoreData internal, but is work on behalf of the PhotoClub object.
  • name is probably PhotoClub.name
  • givenName_ is Photographer.givenName_

Analysis

This shouldn't with structure (as there are no references with value semantics). And shouldn't happen with normal strong references to objects, but could happen with weak references that may be used internally within Core Data. In particular, this is used to break a cycle between MemberPortfolio which "points to" both a PhotoClub and to a Photographer. While PhotoClub has a computed CoreData attribute called 'members_'; and Photographer has a similar property called memberships_. To avoid this "classical" ARC risk of memory leaks, one of the references is probably weak.

But what to do about it?

  • pinpoint exactly what is going on using the Zombie detection Instrument in XCode. Doesn't seem to detect this? Which is suspicious.
  • remove memberships_ and members_ from the data model, hoping that the weak reference no longer exists. This means generating this info ourselves, when needed, using a query to the database. In fact, it may be possible to implement Photographer.memberships and PhotoClub.members as custom computed properties. Core Data however doesn't seem to like relationships without inverse relationships.
  • carefully add a temporary copy of PhotoClub and Membership to some scope, thus leaving the objects longer. There is actually a keyword for that.
  • put more permanent references to PhotoClub and Membership objects somewhere (at top level). Essentially trying to deliberately create a memory leak. This isn't too bad if you have say 20 PhotoClub objects with 20 members each: 20 + 400 objects.

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[PhotoClub isTemporaryID]: unrecognized selector sent to instance 0x2819cdea0'
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCoreDataTaggedObjectID name]: unrecognized selector sent to instance 0x93b50e9d26960d3b'
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCoreDataTaggedObjectID givenName]: unrecognized selector sent to instance 0xb37907d875249736'

https://developer.apple.com/documentation/xcode/investigating-crashes-for-zombie-objects
https://docs.swift.org/swift-book/LanguageGuide/AutomaticReferenceCounting.html

@vdhamer vdhamer added the Bug Something isn't working label Dec 30, 2022
@vdhamer vdhamer self-assigned this Dec 30, 2022
@vdhamer vdhamer pinned this issue Dec 30, 2022
@vdhamer vdhamer changed the title Investigate NSZombies using Zombie Instrument Crash likely due to Photographer and PhotoClub zombies Jan 1, 2023
@vdhamer vdhamer added the Help wanted Extra attention is needed label Jan 1, 2023
vdhamer pushed a commit that referenced this issue Jan 1, 2023
Fix #100 Zombies prevention by avoiding ref count going to zero
@vdhamer vdhamer unpinned this issue Jan 1, 2023
@vdhamer vdhamer removed the Help wanted Extra attention is needed label Jan 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant