Switching views: Release or reuse?

Discussion in 'iOS Programming' started by arnekolja, Feb 12, 2010.

  1. arnekolja macrumors newbie

    Joined:
    Jan 17, 2009
    #1
    Hello everybody,

    I am trying to find my way into iPhone programming right now and have one very basic question about view handling that doesn't seem to get covered in any resources I read so far:

    What's the best practise when switching views? Of course I know that every application is always sort of memory critical, so I would tend to releasing view objects when switching views and reinstantiating them when I need them again, but on the other hand I don't think that's a very performant way to handle views. So what is your experience and/or advice?

    Let's say we have an application that constantly switches views back and forth, like a Twitter app that views single tweets and then switched back to the list view. Would you keep the views that represent the single tweet display in memory or would you unload it with every switch?

    [edit] One more "version" of my question: Given the fact that I have some views that I switch constantly and some that I do not switch to that often (like settings), would I pre-instantiate the ones that I use regularly to have them available in the most performant way and the settings dialogs not, because they're not used so often and I can save RAM by doing it this way? That's the way I think I'd do it, but please correct me if there's a better way or if my idea's actually absurd or something.[/edit]

    And talking about single objects you want to display: I would instantiate a single view that loads different content objects instead of one view per content object, right?

    Any advice is very welcome here, so thanks in advance for your kind answers :) If anyone knows a good resource that's covering this very topic I'd be grateful for this too, of course. Be it a book or just a tutorial, I take everything that makes me understand common practises a bit better here :) It's not the code thing, but rather the theory here that I need.

    Cheers

    Arne
     
  2. PhoneyDeveloper macrumors 68040

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    By and large it's best to do everything lazily. Load things when they're needed. Unload them when done and in response to memory warnings.

    If you have some special reason to want to pre-load something you can do that. But only after you've proved to yourself that there's a performance problem.

    If you design things to load lazily then dumping them and setting their reference to nil in response to a memory warning will result in using less memory and simply reloading the required objects when they're needed again.
     
  3. arnekolja thread starter macrumors newbie

    Joined:
    Jan 17, 2009
    #3
    Hey PhoneyDeveloper,

    thanks, this is an answer I can work with, thank you _very_ much!

    Think I'm just a bit too afraid of performance issues, I'll try to internalize lazy loading while developing with cocoa touch.
     

Share This Page