• 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: There's obviously something I don't understand about NSDate.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: There's obviously something I don't understand about NSDate.


  • Subject: Re: There's obviously something I don't understand about NSDate.
  • From: Dave Fernandes <email@hidden>
  • Date: Sat, 17 Mar 2012 19:27:17 -0400

On 2012-03-17, at 7:10 PM, G S wrote:

> If a Cocoa method name doesn't begin with “alloc”, “new”, “copy”, or “mutableCopy”, then the returned object is autoreleased.
>
>
> Thanks, Dave.  That's what I thought.  But I don't understand why I need to retain it then; it's assigned to a member pointer.  Why does it get released, and when?  If I call retain on it, do I have to call release on it later?

If you are using manual retain-release semantics (not ARC or GC), then instance (member) variables are not retained. This means the object will be released whenever the autorelease pool is drained - probably at the end of the event cycle. So you should retain it (increasing its retain count), and then release it when you no longer need it (decreasing its release count and causing it to be deallocated).

>
> I create another NSDate, on the stack, to hold "now" for use within that function.  Do I need to retain that too?  If not, why not?

As long as it is used only within the function, it is safe to use the autoreleased object. You only need to retain it if you want to keep it around after the method returns.
_______________________________________________

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: 
 >There's obviously something I don't understand about NSDate. (From: G S <email@hidden>)
 >Re: There's obviously something I don't understand about NSDate. (From: Dave Fernandes <email@hidden>)
 >Re: There's obviously something I don't understand about NSDate. (From: G S <email@hidden>)

  • Prev by Date: Re: There's obviously something I don't understand about NSDate.
  • Next by Date: Re: There's obviously something I don't understand about NSDate.
  • Previous by thread: Re: There's obviously something I don't understand about NSDate.
  • Next by thread: Re: There's obviously something I don't understand about NSDate.
  • Index(es):
    • Date
    • Thread