• 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: Negm-Awad Amin <email@hidden>
  • Date: Tue, 12 Aug 2008 14:45:03 +0200


Am Di,12.08.2008 um 14:37 schrieb Sean DeNigris:

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 most cases: Yes. You can recognize the other cases after checking it. (Insert quotation of Donald Knuth here).

More: As I wrote, releasing the allocated object let this object disappear. It does not free any object that had been allocated in the autorelease pool, when the released object was constructed. The isolated -release is a king of prying.

So the solution is not to send some release-messages to anything aorund, trying to hit one or another object, but using a custom ARP.

In other words, should it be a practice to always autorelease with alloc and init (except for loops as previously mentioned)?

Amin Negm-Awad email@hidden




_______________________________________________

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


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>)
 >Re: Should I retain a variable returned from this accessor? (From: Sean DeNigris <email@hidden>)

  • Prev by Date: Re: Should I retain a variable returned from this accessor?
  • Next by Date: Re: NSImage and zooming PDFs vs. bitmaps
  • 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