Crash on updateValue for Dictionary

At the moment, I have a dictionary written like this, where Model is a generic:

private var cache = [String: Model]()

Sometime when I call the following:

cache.updateValue(model, forKey: uid)

I get the following crash:

Thread 14: "-[NSIndexPath count]: unrecognized selector sent to instance 0x8000000000000000"

Some other info about the state of the cache when the crash occurs:

  • The dictionary is storing 1205 key/value pairs
  • The value being updated does not exist

According to the summary on Apples documentation for updateValue:

Updates the value stored in the dictionary for the given key, or adds a new key-value pair if the key does not exist.

Can someone please explain what is happening and how to fix this issue?

cache[uid] = model

Could you show more code, how is Model defined, what is uid (String ?)

Thread 14: "-[NSIndexPath count]: unrecognized selector sent to instance 0x8000000000000000"

This is a sign of memory management problems. You typically see it when you’ve over-released an object and the memory used by that object gets reused by an object of a different type. Later on, when someone who thinks they have the original object tries to use it, they call it with the wrong selector and you see this crash.

It’s very unlikely that this is caused by a problem in Dictionary. It’s more likely that Dictionary just happens to be generating a lot of memory traffic that just happens to reveal the problem.

A good place to start here is the standard memory debugging tools. They, and specifically zombies, should reveal the source of the original over-release.

If that doesn’t help, please post a full crash report, per the advice in Posting a Crash Report.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Crash on updateValue for Dictionary
 
 
Q