title: How should I handle a failure in an init: method in Objective-C?
body: <p>Let's say I'm building a new class for the iPhone in Objective-C.  In one of my init methods I want to manually allocate some memory.  So, I might have something like this:</p>
  
  <pre><code>- (id)initWithSomeObject:(SomeObject *)someObject {
    self = [super init];
    if (self != nil) {
      myObject = someObject;
      [myObject retain];
      if ( (memory = calloc(1, sizeof(SomeStruct)) == NULL) {
        // What should I do here to clean up
        [self release];
        self = nil;
      }
    }
    return self;
  }
  </code></pre>
  
  <p>Now, assuming that the calloc() could fail, and that failing to allocate memory is catastrophic for my object, what should I do inside the if-body to clean up properly?  Is there an Objective-C idiom or pattern that I should be using?</p>
  
  <p>Edit:  I included the code posted by Rob Napier.  But, I still have to release myObject, right?  Or does the added code somehow trigger dealloc()?</p>