• 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: Impossible leak warning in OS X init method
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Impossible leak warning in OS X init method


  • Subject: RE: Impossible leak warning in OS X init method
  • From: Lee Ann Rucker <email@hidden>
  • Date: Sat, 29 Aug 2015 18:02:13 +0000
  • Thread-topic: Impossible leak warning in OS X init method

Have you tried reordering it into something like
if (!self) return nil;
if (!do_stuff_successfully) {
  [self release];
  return nil;
}
...

That's our house style and I've never seen an error like yours.
________________________________________
From: cocoa-dev-bounces+lrucker=email@hidden [cocoa-dev-bounces+lrucker=email@hidden] on behalf of Bill Cheeseman [email@hidden]
Sent: Saturday, August 29, 2015 8:11 AM
To: Cocoa-Dev Cocoa-Dev Mail
Subject: Impossible leak warning in OS X init method

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 - email@hidden

_______________________________________________

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

_______________________________________________

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


References: 
 >Impossible leak warning in OS X init method (From: Bill Cheeseman <email@hidden>)

  • Prev by Date: Impossible leak warning in OS X init method
  • Next by Date: Re: setting tab stops in swift
  • Previous by thread: Impossible leak warning in OS X init method
  • Next by thread: Re: Impossible leak warning in OS X init method
  • Index(es):
    • Date
    • Thread