Re: Should I retain a variable returned from this accessor?
Re: Should I retain a variable returned from this accessor?
- Subject: Re: Should I retain a variable returned from this accessor?
- From: Sean DeNigris <email@hidden>
- Date: Tue, 12 Aug 2008 08:37:43 -0400
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;
}
you could do:
NSString* todoUid = [[[newTodo uid] retain] autorelease];
YES! Many, many of memory managemt problems are solved with this
technique. BTW: You can do the same inside a getter to get rid of
thread problems.
Is the performance hit of keeping objects around until the next pool
drain (instead of releasing them when you're done with them)
insignificant? In other words, should it be a practice to always
autorelease with alloc and init (except for loops as previously
mentioned)?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden