• 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: Question about scope of "convenience objects"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about scope of "convenience objects"


  • Subject: Re: Question about scope of "convenience objects"
  • From: Paul Bruneau <email@hidden>
  • Date: Fri, 21 Sep 2007 13:51:11 -0400

On Sep 21, 2007, at 11:16 AM, Scott Ribe wrote:

Yes, you've understood the rule. For more info on why, follow the link at
the bottom of that page and see the section "Creating Objects Using
Convenience Methods".

Thank you.

On Sep 21, 2007, at 11:20 AM, Charles Steinman wrote:

In general, yes. There's nothing magic about
autorelease. The documentation is pretty explicit
about what makes autoreleased objects go away -- it
happens when an NSAutoreleasePool is deallocated.

Cheers,
Chuck

Thanks. The reason for my question, though, was that I wasn't sure _when_ that would happen.


On Sep 21, 2007, at 11:30 AM, I. Savant wrote:

 How do you think dictionaries and arrays of things are handed back
to you from other Cocoa methods? A hint: the same way. :-) If you
weren't able to rely on the object being returned sticking around long
enough for you to at least retain it, nothing would work right.

I'm in full agreement :) I knew they would stick around in the current method (where I could retain it if I needed to), but I was looking for verification that the object would still be around in the method that called the method that generated it.


  I see some prefer the style (on a "getter" accessor method) of:

  return [[object retain] autorelease];

  But the memory management guide says simply returning the object is
sufficient: "... no need for retain or release:". Given that, I don't
think that really buys you anything in the general case.

I like simplicity too!

  FWIW, I use the "hand back a dictionary to return multiple values"
approach frequently. It's (IMHO) a natural use of such a "throw-away"
container.

I'm glad you took the time to write this. I always find it a thrill when I think of a way to do something and it turns out to be OK.
_______________________________________________


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: Question about scope of "convenience objects"
      • From: Milo Bird <email@hidden>
References: 
 >Re: Question about scope of "convenience objects" (From: Scott Ribe <email@hidden>)

  • Prev by Date: Re: NSArray - move Items at indexes
  • Next by Date: Re: really weird move file problem - copy fails also, more datapoints
  • Previous by thread: Re: Question about scope of "convenience objects"
  • Next by thread: Re: Question about scope of "convenience objects"
  • Index(es):
    • Date
    • Thread