R – How to completely unload view controller loaded from nib

iphonememory

I'm writing iPhone application which uses multiple views, each with own controller. They are loaded programmatically using initWithNibName: and released before switching to other controller, so only one view is visible at a time.
After releasing view controller (I have checked that dealloc is called) not all memory is freed. I do release all outlets when deleting controller. Also, setting self.view to nil in controller's dealloc doesn't solve the issue. Memory consumption gets bigger though Leaks from instruments doesn't show any leaks.

Is there any way to completely remove those views with their controllers from memory? I want to have the same free memory amount before new controller is created and after it is deleted.

Best Answer

You can override retain and release on any class, to get a better understanding of when the retain count gets higher than you might have expected.

Something like this:

- (id) retain
{
    NSLog(@"Retain: Retain count is now %d", self.retainCount+1);
    return [super retain];
}

- (void) release
{
    NSLog(@"Release: Retain count is now %d", self.retainCount-1);
    [super release];
}

When that is said, I think you have to check that your "memory leak" is not just something the system has cached. If you can consistently use more memory by doing the same sequence again and again, then you have a leak.

Related Topic