1

I'm having some issues with a Results object on Realm. I have a collection of type 'Offer', and in three different view controllers I have three different queries to Offer Realm collection depending on an Offer property. 'Offer' objects are different for each user so, when the user logs out I clean all session data, including this collection.
When the user signs in again (closing the app or not), all collections are reloaded and I receive this exception:

malloc: *** error for object 0x208a7614: incorrect checksum for freed object - object was probably modified after being freed.

The way I reload each collection is:

  • First If there are offers available on local Database, I load them.

  • After that, I request Offers from remote and when I received them I remove all from local and add all new ones.

  • Finally I save them on Realm, I receive the changeset from Realm (with RxRealm) and I make all changes on a CollectionView (with performBatchUpdates).

The way I do the 'swap' on Realm after reloading is:

do{
     try realm.write(){
         realm.delete(andRemove)
         realm.add(offers, update: true)
     }
}

And the ChangeSet is applied like this:

func applyChangeset(deleted:[Int], inserted:[Int], updated:[Int], animationStyle:UITableViewRowAnimation = .automatic) {
    self.performBatchUpdates({
        self.deleteItemsAtIndexPaths(deleted.map { IndexPath(row: $0, section: 0) }, animationStyle: animationStyle)
        self.insertItemsAtIndexPaths(inserted.map { IndexPath(row: $0, section: 0) }, animationStyle: animationStyle)
        self.reloadItemsAtIndexPaths(updated.map { IndexPath(row: $0, section: 0) }, animationStyle: animationStyle)
    }, nil)
}

The exception below rises on applyChangeset method last line.

I know the problem happens when I try to reload the collection, because if I don't request offers from remote, It works perfectly.

What could it be happening?

Regards

Edit: Backtrace

https://i.stack.imgur.com/zsKpg.png

http://pastebin.com/eY7VUmvE

kikettas
  • 1,682
  • 1
  • 24
  • 31
  • Can you please share the complete backtrace of the crash? – bdash Mar 03 '17 at 17:11
  • @bdash I edited with a backtrace screenshot – kikettas Mar 03 '17 at 19:02
  • The backtrace is missing frames 1 thru 7. Can you disable the "Show only stack frames and frames between libraries" button at the bottom of the backtrace window, or preferably just run `bt` in Xcode's LLDB console to get a textual backtrace. – bdash Mar 03 '17 at 19:10
  • I'd also suggest looking at http://stackoverflow.com/a/22417528/1991710 for some tips about how to debug crashes of this nature. – bdash Mar 03 '17 at 19:13
  • I edited again with a new screenshot and all backtrace from 'bt'. Thank you for your help. – kikettas Mar 06 '17 at 09:05
  • 1
    Based on that backtrace, the link I shared above should definitely help you in tracking down the cause of the problem. – bdash Mar 06 '17 at 17:37
  • 1
    The link didn't give me a solution but It gave me a hint of the problem (collectionView tried to refresh numberOfItems but it wasn't initialized yet). Thank you @bdash for your help and your time, I appreciate it. – kikettas Mar 09 '17 at 11:30

0 Answers0