开发者

Will my view be released too soon if I do this

Currently I have the code below to add my view to a navigation controller. If I used autorelease on the first line and removed release from the 3rd line am I in any danger of my view getting deallocated befo开发者_如何学运维re it is retained by the pushViewController method????

    WeaponStoreView *weaponStoreView = [[WeaponStoreView alloc] initWithNibName:@"WeaponStoreView" bundle:nil];

    // ...
    // Pass the selected object to the new view controller.
    [self.navigationController pushViewController:weaponStoreView animated:YES];
    [weaponStoreView release];


No, the weaponStoreView should be retained by pushViewController: as soon as it receives it, there are some complication issue when dealing with thread where you have to be careful, but in this situation no. Technically you are still better of doing it the way you have it now as it mean the weaponStoreView can be released as soon as it is no longer needed instead until your release pool is flushed but in this case you navigationController is going to be hanging onto your weaponStoreView long after the current event loop has finished.


Autorelease will not release the object until the end of the current function, so you should be fine.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜