Are instance variables set to nil by default in Objective-C?
cocoa, cocoa-touch, iphone, memory-management, objective-c
Solution
Instance variables are initialized to 0 before your initializer runs..
Problem
I'm sorting out some memory issues with my iPhone app and I've just been thinking about some basics. If I setup an ivar and never end up using it in the lifespan of my object, when I call dealloc on it, will that cause a problem? E.g. ``` @interface testClass { id myobject; } @property (nonatomic, retain) id myobject; @end @implementation testClass @synthesize myobject; - (id)init { ... // Do I have to set myobject to nil here? // So if myobject isn't used the dealloc call to nil // will be okay? Or can you release the variable without // having set every object to nil that you may may not use ... } ... // Somewhere in the code, myobject may be set to // an instance of an object via self.myobject = [AnObject grabAnObject] // but the object may be left alone ... - (void)dealloc { [myobject release]; [super dealloc]; } @end ```