• 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
Memory management on returning nil in init
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Memory management on returning nil in init


  • Subject: Memory management on returning nil in init
  • From: Eiko Bleicher <email@hidden>
  • Date: Mon, 21 Jun 2010 16:43:46 +0200

One of my initializers can fail and thus it should return nil. Consider the following example:

-(id) initWithBool:(BOOL)ok
{
   if (self = [super init])
   {
      if (!ok) {
         return nil; // Point of interest
      }
   }
   return self;
}

Does this code leak? I am inclined to think I need to call [self release] before returning nil, but I am yet to see a piece of example code for this. Or is my approach stupid? :-)

Running in no-GC environment here.

Thanks,
Eiko

_______________________________________________

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

  • Follow-Ups:
    • Re: Memory management on returning nil in init
      • From: "Sean McBride" <email@hidden>
    • Re: Memory management on returning nil in init
      • From: Scott Anguish <email@hidden>
    • Re: Memory management on returning nil in init
      • From: Markus Hanauska <email@hidden>
    • Re: Memory management on returning nil in init
      • From: Bryan Henry <email@hidden>
    • Re: Memory management on returning nil in init
      • From: Ken Thomases <email@hidden>
    • Re: Memory management on returning nil in init
      • From: vincent habchi <email@hidden>
  • Prev by Date: Problem controlling a NSScrollView
  • Next by Date: Re: NSAllocateCollectable memory allocation problem
  • Previous by thread: Re: Problem controlling a NSScrollView
  • Next by thread: Re: Memory management on returning nil in init
  • Index(es):
    • Date
    • Thread