Note: This other question seems relevant but it’s not: When does an associated object get released?
I’m adding a second description to a UIView instance as follows:
- (void) setSecondDescription:(UIView*)view description2:(NSString*)description2 {
objc_setAssociatedObject (view,&key,description2,OBJC_ASSOCIATION_RETAIN);
}
- (NSString*) secondDescription:(UIView*)view {
return (id)objc_getAssociatedObject(view, &key);
}
If the UIView deallocs, will the associated description 2 get dealloced? Is there any way to get this to happen automatically?
If you want to actually see the description of the entire dealloc timeline, look at WWDC 2011, Session 322, 36:22. However, here’s the basic rundown (I wanted to remember it, so this is an actual comment in a piece of my code).
Note, that the associated objects are released at the end of the life cycle.