Aren't objective-c pointers nil until when you allocate the memory?
I thought that when I declare an object the pointer is st开发者_Python百科ill nil until when I allocate memory and initialize it. Instead I run this code and I was surprised to see that it outputs "TRUE":
NSString * aString;
if (aString) {
NSLog(@"TRUE");
}
thanks
It is pointing at an undefined location - it can point to any memory location (even one that you don't have access to.
You should NIL
it out when declaring it.
When you allocate an OBJECT the storage is nilled, but when you have an automatic variable it's whatever junk it is.
精彩评论