• 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
Initializing object pointers to nil
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Initializing object pointers to nil


  • Subject: Initializing object pointers to nil
  • From: Jeffrey Mattox <email@hidden>
  • Date: Thu, 17 Apr 2003 03:10:56 -0500

I know that [nil release] is allowed (although I can't find documentation), but am I guaranteed that an object pointer will be nil if it hasn't been explicitly set? That is, must I declare variables this way:

NSArray *myArray = nil;

-(void)myMethod
{
NSString *tempString = nil;
// ... code here, maybe alloc-ing and using tempString and myArray
[tempString release]; // might be [nil release]
[myArray release]; // might be [nil release]
}

as opposed to this:

NSArray *myArray;
NSString *tempString;

In general, what are the ramifications of initializing variables where they are declared as opposed to in-line, in the code itself?

Jeff
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Initializing object pointers to nil
      • From: Sherm Pendley <email@hidden>
  • Prev by Date: AppleScript issue
  • Next by Date: Re: import PB project
  • Previous by thread: AppleScript issue
  • Next by thread: Re: Initializing object pointers to nil
  • Index(es):
    • Date
    • Thread