I want to keep one single object in application, and do not release.
@implementation MyClass
static MyClass *sharedInstance = nil;
+ (MyClass *)sharedInstance {
if (!sharedInstance) {
sharedInstance = [[super alloc] init];
}
return sharedInstance;
}
@end
I can get single object by [MyClass sharedInstance]
, it works well in Non-ARC mode.
But the object will release when change to ARC mode.
Why do you think it would release? You've assigned it to a static variable tracked by ARC.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.