Singleton pattern is a common pattern, but crash initiator or even in a single embodiment ridiculous applications. Is really a single case caused it? not necessarily. But the phenomenon are pointing to a single case caused. Today, I experienced an example of a seemingly crashes on a single case, but actually is not, today, to be a record for the analysis of similar problems in the future.
@interface SNNetState : NSObject
// current network status
@property (nonatomic, assign) SNNetWorkStates networkStateInstance;
+ (SNNetState *)intance;
@end
Implementation as follows:
+ (SNNetState *)intance {
static SNNetState* _intance = nil;
static dispatch_once_t netStateOnece;
dispatch_once(&netStateOnece, ^{
_intance = [[SNNetState alloc] init];
});
return _intance;
}
Look phenomenon is caused by a single case of problems, but the background has informed us really want:
IMsViewController listener objects have been released, and when our time networkStateInstance change IMsViewController the object does not exist led to the collapse. So we have wronged a single case, but a lot of people stubbornly rigid thought to be caused by a single example. In this there is a commonly used method can help you to accurately cause of the problem. Select Product in the xcode - "Scheme-" Edit Scheme pop-up edit box as shown in settings: you can easily locate the cause of the problem.