Dealloc not being called when changing nibs

379 Views Asked by At

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?

1

There are 1 best solutions below

0
On

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.