0
將自定義對象添加到目標c中的mutableArray時發生內存SIGBUS錯誤。發佈自定義對象時出現Iphone SIGBUS錯誤
@interface stak : NSObject {
NSString *idval,
*username,
*userid,
*password,
*snippet,
*curStakId,
*pageCount,
*memberCount,
*imgURL,
*tags;
UIImage *icon;
}
@property (nonatomic,retain) NSString *idval,*username,*userid,*password,*curStakId,*snippet,*pageCount,*memberCount,*imgURL,*tags;
@property (nonatomic,retain) UIImage *icon;
-(id)initWithidval:(NSString *)idvalue
username:(NSString *)user
userid:(NSString *)uid
password:(NSString *)pass
curStakId:(NSString *)stakid
snippet:(NSString *)snip
pageCount:(NSString *)page
memberCount:(NSString *)members
tags:(NSString *)tag_vals
imgURL:(NSString *)img
icon:(UIImage *)iconImg;
@end
與.m
@implementation stak
@synthesize idval;
@synthesize username;
@synthesize userid;
@synthesize password;
@synthesize curStakId;
@synthesize snippet;
@synthesize pageCount;
@synthesize memberCount;
@synthesize imgURL;
@synthesize icon;
@synthesize tags;
-(id)initWithidval:(NSString *)idvalue
username:(NSString *)u
userid:(NSString *)uid
password:(NSString *)p
curStakId:(NSString *)stakid
snippet:(NSString *)snip
pageCount:(NSString *)page
memberCount:(NSString *)members
tags:(NSString *)tag_vals
imgURL:(NSString *)img
icon:(UIImage *)iconImg{
if (self = [super init]) {
[self setIdval:idvalue];
[self setUsername:u];
[self setUserid:uid];
[self setPassword:p];
[self setCurStakId:stakid];
[self setSnippet:snip];
[self setPageCount:page];
[self setMemberCount:members];
[self setTags:tag_vals];
[self setImgURL:img];
[self setIcon:iconImg];
}
return self;
}
-(void)dealloc{
[idval release];
[username release];
[userid release];
[snippet release];
[imgURL release];
[icon release];
[tags release];
[curStakId release];
[memberCount release];
[password release];
[super dealloc];
}
@end
而這正是它被稱爲和釋放。
NSMutableArray *_return_staks = [[NSMutableArray alloc]init];
stak *_stakItem = [[stak alloc]initWithidval:[NSString stringWithFormat:@"%@",[staks objectAtIndex:i]]
username:[NSString stringWithFormat:@"%@",[creators objectAtIndex:i]]
userid:[NSString stringWithFormat:@"%@",[creatorid objectAtIndex:i]]
password:[NSString stringWithFormat:@"%@",[privacy objectAtIndex:i]]
curStakId:[NSString stringWithFormat:@"%@",[idvals objectAtIndex:i]]
snippet:tempString
pageCount:tempPcount
memberCount:tempMcount
tags:[NSString stringWithFormat:@"%@",[tags objectAtIndex:i]]
imgURL:[NSString stringWithFormat:@"%@",[img objectAtIndex:i]]
icon:nil];
[_return_staks addObject:_stakItem];
[_stakItem release];
當我去引用存儲的項目我得到一個SIGBUS錯誤,但是當我刪除「[_stakItem發行]」它工作正常,但是這造成泄漏。有什麼方法可以糾正這個問題嗎?