我有這個靜態/ singelton類有一個成員變量。Objective C - 釋放變量
一切都運行得很好,但是,當我退出應用程序,以及回來時,該成員變量會導致應用崩潰。
我試圖重新初始化成員變量,但似乎並沒有這樣的伎倆。
我在下面包括我的代碼示例,有沒有人看過這個?
頭(.h)文件中:
@interface Metrics : NSObject {
Metrics *metrics;
Distance *distance;
}
實施(.M)文件:
@implementation Metrics
static Metrics *metrics = nil;
+ (Metrics *)sharedInstance {
@synchronized(self) {
if (metrics == nil) {
metrics = [[Metrics alloc] init];
}
}
return metrics;
}
- (id)init {
self = [super init];
if (self) {
}
return self;
}
-(void) setupDistance
{
distance = [[Distance alloc] init];
distance.test; // it dies here after I quit the app and come back
}
而且它被使用,AppDelegate.m
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[[Metrics sharedInstance] setupDistance];
}
謝謝
Tee
崩潰說的是什麼(即在控制檯崩潰時看到什麼,以及調用堆棧是什麼樣的)? – SVD
這是一個iOS應用嗎?另外,請發佈Distance的聲明和'getTest'的實現; – Perception
@Perception:什麼getTest?他正在調用方法測試作爲屬性。 –