• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Should I retain a variable returned from this accessor?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Should I retain a variable returned from this accessor?
      • From: Negm-Awad Amin <email@hidden>
References: 
 >Should I retain a variable returned from this accessor? (From: Sean DeNigris <email@hidden>)
 >Re: Should I retain a variable returned from this accessor? (From: "Kyle Sluder" <email@hidden>)
 >Re: Should I retain a variable returned from this accessor? (From: Peter N Lewis <email@hidden>)
 >Re: Should I retain a variable returned from this accessor? (From: Negm-Awad Amin <email@hidden>)

  • Prev by Date: Re: Create a calendar group using CalendarStore framework
  • Next by Date: Re: Should I retain a variable returned from this accessor?
  • Previous by thread: Re: Should I retain a variable returned from this accessor?
  • Next by thread: Re: Should I retain a variable returned from this accessor?
  • Index(es):
    • Date
    • Thread