开发者

Dealloc not being called when changing nibs

开发者 https://www.devze.com 2023-02-12 21:45 出处:网络
I\'ve got quite a large project in which I change nibs frequently using code like this - level3 *screen = [[level3 alloc] initWithNibName:@\"level3\" bundle:nil];

I've got quite a large project in which I change nibs frequently using code like this -

level3 *screen = [[level3 alloc] initWithNibName:@"level3" bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:screen animated:YES];
[screen release];

When I change nibs dealloc is not being called开发者_运维百科 (it only gets called when I get a memory warning). I've did quite a lot of research on this but am unable to find any answers. Can anyone help me with this?


The answer is because iOS will cache your nibs. It gives up that cache if it hits a memory warning of course, which is the behaviour you're seeing.

Keep in mind that you may have cases where you may use the same nib, with the same objects multiple times (such as in a tableview cell). Loading a nib is an expensive process comparatively to keeping a reference to the objects in some cache.

0

精彩评论

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

关注公众号