3

I'm using RealmSwift in a project and from time to time I get a

Terminating app due to uncaught exception 'RLMException', reason: 'Object has been deleted or invalidated.'

I don't delete any objects from my realm database so issue isn't that the object was deleted some place else.

What are the other options?

  • Can you share more info regarding this, like some code samples of what you think may be causing this? Any areas around where you are storing objects (in a property) and deleting them would be good. – yoshyosh May 11 '15 at 17:20
  • If you're explicitly calling `Realm.invalidate()`, that would also cause that exception. – segiddins May 11 '15 at 21:22
  • Thanks for your help. It turned out I was calling invalidate previously on another realm instance. I was under the impression invalidate only invalidates the objects linked to the respective realm instance, but instead all objects are invalidated that are fetched from the same realm file. Perhaps the guys at realm should update the docs to make that clearer :) – Alex Alexiev May 12 '15 at 19:22

1 Answers1

1

Old thread I know but I just came across this issue too. You will also see that error when the object is on the wrong thread:

// throw an exception if the object is invalidated or on the wrong thread
static inline void RLMVerifyAttached(__unsafe_unretained RLMObjectBase *const obj) 
{        
    if (!obj->_row.is_attached()) {
        @throw RLMException(@"Object has been deleted or invalidated.");
    }
    [obj->_realm verifyThread];
}
Jaroslav Kadlec
  • 2,505
  • 4
  • 32
  • 43
darkbreed
  • 151
  • 9