Did any body get this issue? If I need an instance variable, not as a property, and initialize this variable in a method, then when I need it, it is already released. It happens for autoreleased objects. What is the reason for this?
Usually instance variable should have the whole lifetime of the class object. But it seems if the variable is local to a function, and its a autorelease object, it is released when the function exits.
MyClass.h
@interface MyClass:UIViewController {
NSDate * date;
}
MyClass.m
@implementation MyClass {
- (void) anInit {
date = [NSDate date];
}
- (void) useDate {
NSLog (@"%@", date);
// here date is already release, and get bad access.
}
}