开发者

NSMutableArray addObject freezes my app

Tons of similar questions, but none of 开发者_高级运维their answers seem to answer mine...

I'm creating my array as such:

imgArray = [NSMutableArray arrayWithCapacity:10];

Later (in another function) I am trying to add an object to it:

Attachment newAttachment = [[[Attachment alloc] init] autorelease];
newAttachment.fileName = filename;
newAttachment.file = file;
[imgArray addObject:newAttachment];

This results in the iPhone app freezing up. The simulator seems fine; the clock on the status bar keeps ticking, I don't get any error messages, but my app is no longer responding.

What am I doing wrong?


It seems you are not retaining imgArray. Are you? Try,

imgArray = [[NSMutableArray alloc] initWithCapacity:10]

if not.


just do

imgArray = [[NSMutableArray arrayWithCapacity:10] retain];

all class methods if return an object is returned with retain count 1 and object already in autorelease pool so if want to use that object beyond the current working block the you should always retain that object because then reference is lost outside the block.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜