On Wed, Jun 17, 2009 at 10:10 PM, Jim Correia<[email protected]> wrote: > On Wed, Jun 17, 2009 at 9:51 PM, Bill Bumgarner <[email protected]> wrote: > >> You can't assume that the container didn't make a copy or do something else. >> >> If you need the object, you should hold a retain. > > In general, I agree. However, the following code is also problematic: > > [o release]; > [testTable setObject:[testTable objectForKey:k] forKey:k]; > > NSDictionary does not have the same failure mode. Bug in NSMapTable > (for the edge case of replacing the current value)?
IMO this is a bug in your code, which is being hidden by NSDictionary and exposed by NSMapTable. That's not to say that Apple shouldn't make it better, but this kind of behavior is wrong. Collection classes are documented as retaining their contents, and of course releasing them when appropriate. It explicitly warns against removing an object from a container and then trying to use it. For this code to work, you're relying on NSMapTable (or NSDictionary) to retain the new content object before releasing the old one, even though there is no such guarantee in the API contract. Mike _______________________________________________ Cocoa-dev mailing list ([email protected]) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
