Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-06-2009, 04:04 PM   #1 (permalink)
New Member
 
Join Date: Jul 2008
Posts: 33
Default Know when a controller's view is released in didReceiveMemoryWarning

As a controller's view is only released in the didReceiveMemoryWarning method when such view is not currently displayed. Is it correct to perform this test in the didReceiveMemoryWarning method:

Code:
// Test if the view is attached to a superView
if([[self view] superView] == nil)
{
    NSLog(@"View is going to be released as not showing");
}
Is that piece of code Ok to test in the didReceivememoryWarning method the condition when the view is going to be released?

Thanks

B-
obrand is offline   Reply With Quote
Old 04-06-2009, 04:24 PM   #2 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 1,431
Default

It's not a great idea to do this. [self view] will always load the nib, call viewDidLoad etc. Even if the view was unloaded during the last memory warning it will now be loaded again.

If you do use this code anyway make sure it goes before calling super. You want to give the base class the opportunity to unload the view.
PhoneyDeveloper is offline   Reply With Quote
Old 04-06-2009, 04:35 PM   #3 (permalink)
New Member
 
Join Date: Jul 2008
Posts: 33
Default

Thanks. I am not using Interface Builder in my application. Would the [self view] then forces the reload of the view in the didReceiveMemoryWarning method?

Quote:
Originally Posted by PhoneyDeveloper View Post
It's not a great idea to do this. [self view] will always load the nib, call viewDidLoad etc. Even if the view was unloaded during the last memory warning it will now be loaded again.

If you do use this code anyway make sure it goes before calling super. You want to give the base class the opportunity to unload the view.
obrand is offline   Reply With Quote
Old 04-06-2009, 08:04 PM   #4 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 1,431
Default

In that case it will call loadView and then viewDidLoad. I assume that you're building your self.view in loadView and/or viewDidLoad. So yes, it will cause the view to be reloaded even if you're not using IB.

You can easily test this in the Sim by using the Simulate Memory Warning menu item.
PhoneyDeveloper is offline   Reply With Quote
Old 04-07-2009, 12:41 PM   #5 (permalink)
New Member
 
Join Date: Jul 2008
Posts: 33
Default

Great. Found out that the best way to handle this is to override the setView and check when the controller is passing nil to it.
When it does such thing, you can be sure that the view has been discarded.

B-
obrand is offline   Reply With Quote
Reply

Bookmarks

Tags
didreceivememorywarning, release, view

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 273
20 members and 253 guests
ADY, Bertrand21, Dani77, HemiMG, iDifferent, IphoneSdk, jakerocheleau, JasonR, jimbo, macquitzon216, MACralik, mer10, NSeven, prchn4christ, Rudy, silverwiz, spiderguy84, Sunny46
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,767
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:01 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0