• 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: is [[NSObject alloc] release] correct?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: is [[NSObject alloc] release] correct?


  • Subject: Re: is [[NSObject alloc] release] correct?
  • From: Graham J Lee <email@hidden>
  • Date: Wed, 7 Jun 2006 10:18:57 +0100

On 6 Jun 2006, at 04:02, Adam R. Maxwell wrote:

Periodically, it's helpful to add an init... method in a category to return a non-autoreleased object (in NSDate, for instance, since dateWithNaturalLanguageString fills autorelease pools really quickly due to its implementation). A fellow developer and I have been discussing the appropriate way to do this, as shown in the following contrived example:

// Pattern A
- (id)initWithObject:(id)anObject
{
   [self release];
   return [[OtherObject alloc] init];
}

// Pattern B
- (id)initWithObject:(id)anObject
{
   [[self init] release];
   return [[OtherObject alloc] init];
}

It's definitely the case that you can -release an object created with [NSObject alloc]; whether or not you can do it with arbitrary subclass X depends on whether X has overridden -dealloc to break if called on an uninitialised object ;-).


--
Graham J Lee
"Oxford University's UNIX Expert"
As seen in MacWorld UK
http://iamleeg.blogspot.com


Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >is [[NSObject alloc] release] correct? (From: "Adam R. Maxwell" <email@hidden>)

  • Prev by Date: Re: Function to retrieve autoresizingMask ?
  • Next by Date: Editing State in NSOutlineView
  • Previous by thread: Re: is [[NSObject alloc] release] correct?
  • Next by thread: Fastest way to "ExpandAll" in NSOutlineView
  • Index(es):
    • Date
    • Thread