• 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: Shawn Erickson <email@hidden>
  • Date: Mon, 05 Jun 2006 20:21:47 -0700


On Jun 5, 2006, at 8:02 PM, Adam R. Maxwell wrote:
// 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];
}

From my reading of the docs, Pattern A is correct in theory. However, it breaks badly with NSDate, and I'm curious as to whether Pattern B is needed for only a few cases ([[NSArray alloc] release] and [[NSString alloc] release] work fine, for instance), or is more correct.

It isn't safe to assume that you can send a release message to an uninitialized object since the release method for that class may make assume that it was initialized (which is the normal situation).


So you either have to call its designated initializer and then release it or possibly use the foundation function NSDeallocateObject (id).

-Shawn
_______________________________________________
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: stringWithContentsOfURL: usedEncoding: error:
  • Next by Date: Fastest way to "ExpandAll" in NSOutlineView
  • Previous by thread: is [[NSObject alloc] release] correct?
  • Next by thread: Re: is [[NSObject alloc] release] correct?
  • Index(es):
    • Date
    • Thread