Re: Responding to view controller memory warnings (was Re: Outlets / IBOutlet declarations)
Re: Responding to view controller memory warnings (was Re: Outlets / IBOutlet declarations)
- Subject: Re: Responding to view controller memory warnings (was Re: Outlets / IBOutlet declarations)
- From: James Montgomerie <email@hidden>
- Date: Sat, 22 Nov 2008 15:58:03 +0000
On 22 Nov 2008, at 00:53, mmalcolm crawford wrote:
Context:
UIViewController provides a method, didReceiveMemoryWarning, which
is invoked on view controllers when the amount of memory available
to the application is severely constrained. The goal of the method
is to allow view controllers to dispose of resources that are
currently not needed and that can be recreated later if required.
One such resource is the view controller's view itself. Assuming
that it does not have a superview, the view is disposed of ([self
setView:nil];).
A "issue" arises in that outlets to elements within the nib file are
typically declared as follows:
@property (nonatomic, retain) IBOutlet ElementClass *element;
Thus even though the main view is disposed of, absent any further
action the outlets are still retained. This is not in and of itself
a problem -- if and when the main view is reloaded, they will simply
be replaced -- but it does mean that the beneficial effect of the
didReceiveMemoryWarning is reduced.
There are, currently, a couple of possible remedies...
Maybe I'm missing something (I stopped following the previous thread),
but, presuming that super's -didreceiveMemoryWarning does indeed
"Release[] the view if it doesn't have a superview", as documented,
couldn't these contortions be avoided (in a future-proof way) by doing
something like this in -didReceiveMemoryWarning, and not touching -
setView:?
- (void)didReceiveMemoryWarning
{
if(self.anOutlet && !self.view.superview) {
// Will not call loadView if the view is not loaded, because
// we can assume that if we get past the check for anOutlet
// the view must already be loaded.
self.anOutlet = nil;
}
[super didReceiveMemoryWarning]; // Releases the view if it doesn't
have a superview
}
Jamie.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden