The following initialization code has generated a leak warning in Xcode 4, 5, 6 
and 7 beta in a framework of mine for several years. It has never caused an 
issue in the wild. I would really like to get rid of the warning. Can anybody 
tell me what I'm doing wrong?

@implementation MyObject // subclass of NSObject

- (id)initWithSomeThing:(id)someThing {
     self = [super init];
     if (self) {
          if (do_stuff_successfully) {
               ...
          } else {
               [self release];
               return nil; // <-- Error (quoted below)
          }
     }
     return self;
}

- (MyObject *)objectWithThing:(id)thisThing {
     if (thisThing) {
          MyObject *object = [[MyObject alloc] initWithSomething:thisThing];
          return [object autorelease];
     }
     return nil;
}

@end

Error: "Object leaked: object allocated and stored into 'self' is not 
referenced later in this execution path and has a retain count of +1"

-- 

Bill Cheeseman - wjcheese...@comcast.net

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to