Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
释放自定义对象时出现Iphone SIGBUS错误_Iphone_Objective C_Ios - Fatal编程技术网

释放自定义对象时出现Iphone SIGBUS错误

释放自定义对象时出现Iphone SIGBUS错误,iphone,objective-c,ios,Iphone,Objective C,Ios,在目标c中将自定义对象添加到可变数组时,获取内存SIGBUS错误 @interface stak : NSObject { NSString *idval, *username, *userid, *password, *snippet, *curStakId, *pageCount, *memberCount, *imgURL, *tags; UIImage *icon; } @property (no

在目标c中将自定义对象添加到可变数组时,获取内存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错误,但是当我删除“[\u stakItem release]”时,它工作正常,但是这会造成泄漏。有没有办法纠正这一点?

如果不了解实际崩溃的背景,很难给你一个明确的答案,但你可能在某个地方过度释放了stackItem。这可能是因为保留了对它的引用,但释放了唯一拥有它的数组。您发布的代码实际上没有什么问题(嗯,字符串属性应该是复制属性,但这不是导致崩溃的原因)

发布后您是否使用_stakItem

你有这样的序列吗

 stak* foo = [_return_staks objectAtIndex: fooIndex];

 //  etc 

[_return_staks release];

// etc

[foo doSomething]; // Likely to have gone away by now.