On Mon, Aug 11, 2008 at 3:12 PM, Sean DeNigris <[EMAIL PROTECTED]> wrote: > Hi, how do I handle memory management for todoUid below? Do I have to > retain or autorelease it? > > [...snip...] > > // Get uid to return > NSString* todoUid = [newTodo uid]; > > [...snip...] > > return todoUid; > }
http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Tasks/MemoryManagementRules.html You've gotten todoUid from a method that is not +alloc and does not begin with +new or contain -copy, so you do not own it. Therefore you must -retain it if you want to hold on to it beyond "now". Since you don't, just let it go, it's not your responsibility. That's it. Done. If you're really paranoid, you could instead hand off a copy of todoUid that you know is not mutable by instead returning [[todoUid copy] autorelease], but that seems unnecessary. After all, your caller (and even you) can't be sure that todoUid is mutable at all, since it's only known to be an NSString. In this case, however, since you're using -copy, you are responsible for that copy and so must autorelease it. --Kyle Sluder _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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]