0
我聲明一個NSArray在一類這樣的:的NSArray導致EXC_BAD_ACCESS
.h
@interface HTTP : NSObject {
NSArray *listOfProfiles;
}
@property (nonatomic, retain) NSArray *listOfProfiles;
.m
-(id) init {
if ((self = [super init])) {
listOfProfiles = [[NSArray alloc] init];
}
return self;
}
-(void) someMethod {
...
case GET_LIST_OF_PROFILES:
listOfProfiles = [result componentsSeparatedByString:@"^-^"];
NSLog(@"first break: %@",[listOfProfiles objectAtIndex:0]);
break;
...
}
我可以訪問它在這裏就好了,然後當我嘗試訪問它在創建對象後的另一個類中收到錯誤EXC_BAD_ACCESS
並且調試程序轉到main.m:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
http = [[HTTP alloc] init];
[http createProfileArray];
profileListDelay = [[NSTimer alloc] init];
profileListDelay = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(profileListSelector) userInfo:nil repeats:YES];
}
- (void) profileListSelector
{
if (http.activityDone)
{
// http.listofprofiles mem leak?
for (int i = 0; i < http.listOfProfiles.count; i++)
{
NSLog(@"%@",[http.listOfProfiles objectAtIndex:i]);
}
[profileListDelay invalidate];
profileListDelay = nil;
}
}
我在想這可能是一個記憶問題,但我可能是完全錯誤的。