开发者

UINavigationController crashes due to a NSArray variable

开发者 https://www.devze.com 2023-01-06 13:58 出处:网络
I push a view controller into current navigation controller. It works fine, except when I am getting out of the current view controller, it crashes.

I push a view controller into current navigation controller. It works fine, except when I am getting out of the current view controller, it crashes.

MyTableView *newPage = [[MyTableView alloc] initWithNibName:@"table2" bundle:nil];
[[self navigationController] pushViewController:newPage animated:YES];
//[newPage release];

I comment out the last line to prevent crash. I read another post about variables being over released. In the newPage, I only have one variabl开发者_运维知识库e (arrCellText), and is initialized in the initWithNibName

NSArray *temp = [[NSArray alloc] initWithObjects:@"string1", @"string2", @"string3", nil];
[self setArrCellText: temp];
[temp release];

I put the release in the dealloc

[arrCellText release];

If I comment out setting and release of arrCellText, it works fine too. I must not have complete understanding of memory management, and I would like to understand this better. TIA


Where does the crash happen exactly? First you can release 'newPage' after pushing it onto the navigationController (because it's retained there).

You might try to access anything from newPage after coming back. 'newPage' was released in the mean time and thus has some garbage value (but not nil).

0

精彩评论

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

关注公众号