I cannot find in the documentation how memory is handled for the userInfo dictionary of an NSNotification. If you specify one, is this merely a pointer to an existing place in memory, or is new memory allocated to “carry” this data into the notification?
If the latter, it would affect performance if you want to reference a large dictionary; if the former, I would expect that it doesn’t matter how large the dictionary is, since it is already in memory.
Also on this point, if the dictionary is not retained before it is added to a notification, how long does it live? Can we safely assume that the recipient of this notification will have access to this dictionary at the moment it is received, even if the dictionary was not retained prior to sending the notification?
I believe that
userInfoobject provided to+ (id)notificationWithName:(NSString *)aName object:(id)anObject userInfo:(NSDictionary *)userInfois retained. And I am sure that not any additional memory will be allocated to storeuserInfo.So object referenced by
userInfowill be alive while a notification is not released (send and procedes by all the observers of that notification). Yes, you can assume that the dictionary (or whatever you will provide asuserInfo) will be accesible in observers (if, of course, you are not overreleasing it).From the Memory Management Programming Guide for Core Foundation -> Ownership Policy