• 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: Methods that return autoreleased objects?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Methods that return autoreleased objects?


  • Subject: Re: Methods that return autoreleased objects?
  • From: "Owen Yamauchi" <email@hidden>
  • Date: Sat, 28 Jun 2008 18:29:22 -0700

Don't think about it.

If memory management confuses you in any way, don't try to think about
the status of objects returned from framework methods. Only worry
about it from the perspective of your code. Do you need the object to
stay around after your method returns? Then retain it, and remember to
release it somewhere else as appropriate. If you make an object with
+alloc or -copy, then you'll need to release it somewhere too.

In practice, most framework methods return autoreleased objects (if
the method creates it). There are other situations, for example:
-[NSArray objectAtIndex:] will return an object that is retained by
the array, and is not in any autorelease pools (unless you've put it
in one). But that's because the object was not created by the array.

Bottom line: don't think about it. Follow the rules in your own code,
and all will be well.

Owen
_______________________________________________

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: 
 >Methods that return autoreleased objects? (From: "john muchow" <email@hidden>)

  • Prev by Date: valueForKey: on collections [was: Re: Using isMemberOfClass with a tree of subclass of NSManagedObject]
  • Next by Date: Re: valueForKey: on collections [was: Re: Using isMemberOfClass with a tree of subclass of NSManagedObject]
  • Previous by thread: Re: Methods that return autoreleased objects?
  • Next by thread: RE: Methods that return autoreleased objects?
  • Index(es):
    • Date
    • Thread