2012-03-05 5 views
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; 
} 
} 

メモリの問題だと思っていますが、私は完全に間違っている可能性があります。

答えて

3

それはsomeMethod

-(void) someMethod { 
... 
    case GET_LIST_OF_PROFILES: 
     listOfProfiles = [result componentsSeparatedByString:@"^-^"]; 
     NSLog(@"first break: %@",[listOfProfiles objectAtIndex:0]); 
     break; 
... 
} 

componentsSeparatedByString:にあるメモリの問題

は、あなたがretainプロパティとして配列を宣言しているので、あなたはそのようにそれを更新する必要があります自動解放オブジェクト
を返します:

self.listOfProfiles = [result componentsSeparatedByString:@"^-^"];