• 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: Memory question when added a view to the superView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Memory question when added a view to the superView


  • Subject: Re: Memory question when added a view to the superView
  • From: Ken Thomases <email@hidden>
  • Date: Fri, 10 Sep 2010 16:19:05 -0500

On Sep 10, 2010, at 4:11 PM, Dave Carrigan wrote:

> On Sep 10, 2010, at 1:08 PM, Philip Vallone wrote:
>>
>> Thanks for the prompt replay.
>>
>> Ok I added autorelease:
>>
>> PinDetailsView *detailsView= [[[PinDetailsView alloc] initWithFrame:CGRectMake(0, 0, 270, 420)]autorelease];
>>
>> Is this a correct way to release the object, or	should I use
>>
>> [detailsView release];
>>
>> Or is either acceptable?
>
> The former is more idiomatic because you don't need to remember the release at the end. That is especially important if you were to change your code at some time in the future, such as adding a return statement sometime before the release, which would give you a memory leak.

Except that Apple recommends, for iOS development particularly, that you use -release rather than -autorelease when sensible.  (If you're returning an object to a caller, then it's not sensible to try to avoid -autorelease.)

(There was a recent thread about when to do the -autorelease in the case that you're going to do it.  There, it was generally although not universally recommended to do the autorelease in the same expression as the alloc and init.)

Cheers,
Ken

_______________________________________________

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: Memory question when added a view to the superView
      • From: Philip Vallone <email@hidden>
References: 
 >Memory question when added a view to the superView (From: Philip Vallone <email@hidden>)
 >Re: Memory question when added a view to the superView (From: Dave Carrigan <email@hidden>)
 >Re: Memory question when added a view to the superView (From: Philip Vallone <email@hidden>)
 >Re: Memory question when added a view to the superView (From: Dave Carrigan <email@hidden>)

  • Prev by Date: Re: Memory question when added a view to the superView
  • Next by Date: Re: Memory question when added a view to the superView
  • Previous by thread: Re: Memory question when added a view to the superView
  • Next by thread: Re: Memory question when added a view to the superView
  • Index(es):
    • Date
    • Thread