I’m doing some archiving to a property list and when I unarchive my data using NSKeyedUnarchiver I find that my app crashes if I release the object afterward. I was wondering if the finishDecoding message also autoreleases the object. Seems weird that it crashes when I release it.
Share
What do you release? NSKeyedUnarchiver or unarchived object?
Should you release NSKeyedUnarchiver or not depends on how you created it. It follows usual rules. If you use
alloc+initForReadingWithDatayou should release, if you useunarchiveObjectWithDataorunarchiveObjectWithFile– you shouldn’t.Regarding result of
decodeObjectForKey, it also follows usual rule that method returns autoreleased object and you shouldn’t release it unless you explicitly retained it.Regarding
finishDecoding: you are expected to explicitly call it before NSKeyedUnarchiver object is released. You shouldn’t use unarchiver after that point, but object is still alive.