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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 06-17-2010, 02:21 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 1
alexidoia is on a distinguished road
Default Memory and life cycle of passed variables

There is one thing I don't manage to get a good understanding of and it is holding me back when I try to optimise my apps. Better is to give you an exemple of the common situation I am dealing with.
I use a UINavigationController for most of my apps. The root VC will set some vars depending of localisation and Internet Connexion and start stacking up VCs.
The first VC (after the root one) will used the var passed by the root VC to set some other vars that it will pass in turn to another VCs that it will ask the rootVC to push onto the stack. That works fine.
Now imagine that the second VC takes quite a bit of memory which make the app to unload the first VC, now if I come back from the second VC to the first one, the first VC load again but has lost the data that the rootVC had passed on to it the first time it stacked it up.
Hopping that I made myself clear, what is the best approach to avoid this kind of problem that lead fataly to an application crash ?
Should I implement the viewWillAppear Methods of each VC to check the existance of the data that I need, but then what ? used a notification to ask the precedent VC to pass the data back again ? From whom ? That sounds a lot of tedious works and not a very helpful infrastructure.
My second thought was to store on the root VC object all the important data that I would need and use notification to send them back on demand (as I proposed before) but then what garantie have I got that this rootVC will not be unloaded.

I am sure 90% of anyone's application needs to pass on data from views to views, so from VC to VC, even so you don't use UINavigationController, how do you deal with the problem of keeping essential data when memory is required.

If at least I could be sure that the object responsable for the UINAvigation COntroller is never unloaded, I would start thinking working on a class that work upon notification to pass data back and forth but am I going in the right direction there ?
If you had any suggestion I would greatly appreciated.
alexidoia is offline   Reply With Quote
Old 06-17-2010, 08:54 AM   #2 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

The system does not unload view controllers automatically; it may unload the *view* associated with the controller and then reload the view later, though. I'm not sure why your data would be erased just because of low memory.

Are you erasing or setting data in the viewDidLoad method? That would cause the data to get erased or reset every time the view is loaded. Try setting the data in initWithNib instead.
__________________

Free Games!
smasher is offline   Reply With Quote
Reply

Bookmarks

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: 379
9 members and 370 guests
.Snipe, AragornSG, baja_yu, ChrisYates, davejas69, guusleijsten, hussain1982, Kryckter, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,645
Threads: 94,111
Posts: 402,862
Top Poster: BrianSlick (7,990)
Welcome to our newest member, leighec68
Powered by vBadvanced CMPS v3.1.0

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