I got the “objc_msgSend()” killer error message in my app and thanks to Hamster Emporium
i can figure out a little bit what was happening.
Now i found the “problem” and the “solution”, but what i can’t understand why my problem was really a problem.
Here is the scenario:
Object_A –> Object_B –> Object_C
The ‘–>’ symbol represent the “create” action.
Class of Object_C looks like this:
@interface Class_C {
NSArray *items;
}
@property (nonatomic, retain) NSArray *tems;
@end
The property ‘items’ is set in Object_B through a ‘setItems’ method:
- (void)setItems:(NSArray *)items_ {
if (object_B) {
[object_B.taskItems release];
object_B.taskItems = items_;
}
[super setItems:items_];
}
Now, if I use this method as is I got the blasphemous ‘objc_msgSend()’ error BUT if I comment the release line everything goes well.
Note: the retainCount in the release line is 0, but the release execute without problems
You are getting that error because the
taskItemsmember variable is being released twice. There is no need to manually releasetaskItemsbecause using the dot syntax takes care of it automatically.This line:
Invokes the property accessor for
taskItems, in which the old value is automatically released before the new one is retained (or copied, depending on the property definition).A very good general rule for Cocoa memory management is that you should only
releasean object if you created it (either by alloc/init or by copy). Releasingobject_B.taskItemswould violate that rule.