开发者

NSArray becoming invalid after assignment

Thi开发者_StackOverflow中文版s is a strange problem, but two of my NSArrays are becoming invalid right after assignment. I went into debug and verified this during assignment. The screenshot shows it all. I must be missing a silly error somewhere - can someone please help!

Link to Screenshot

Thank You!


You need to send the -retain message to the array on assignment, like this:

ivar = [[NSArray arrayWithObjects:@"a", @"b", @"c", nil] retain];

The reason why they are going out of scope is because -arrayWithObjects: returns an autoreleased object. It is for this reason that you must send it the -retain message.

Also, don't forget to -release these objects in your -dealloc method.


Use -retain- dude. This will solve your problem.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜