Lowering Your Memory Usage

Discussion in 'iOS Programming' started by harryslotwiner, Apr 17, 2012.

  1. harryslotwiner macrumors newbie

    Joined:
    Mar 28, 2012
    #1
    Hello,
    I have an application in which I have an array of around 200 Labels, 400 Image Views, 600 Strings and 200 Text Views. So in short a lot of views, and this is causing some memory issues.

    After about 2 minutes of intimate use a.k.a. interaction with the views the app is closed due to using to much memory.

    How can I fix this?
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Why do you have so many UI components? Perhaps start by justifying the need for that much.
     
  3. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #3
    Why not have 1 of each, and just reuse them? >.<
    Depends in your situation ofcourse :)
     
  4. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #4
    My guess is that you have a scrolling view with all those elements. You need to reuse the elements as they leave the screen. IE, if 10 fit on the screen at a time, have 11 of them. As the topmost one gets scrolled off the top of the screen, move it to be the bottom most one (the one about to scroll onto the screen,) and change its contents to make it look like a new label. This is how long scrolling table views like the built in music app are done. (The all songs list can easily have over 10K rows in it, so it recycles like I said and only actually has a dozen or so that just get reused hundreds of times when the user scrolls.)
     
  5. helpfulzerox, Apr 18, 2012
    Last edited by a moderator: Apr 18, 2012

    helpfulzerox macrumors newbie

    Joined:
    Apr 18, 2012
    #5
    Check Your Image Sizes

    Images take the most memory. Make sure your images are not huge, as they only really need to be twice the final size to look nice. If you have fifty foot long images, your wasting memory. Also, are you using automatic reference counting? Most users are on ios 5, so your not really losing anything by taking advantage of this. If you are stubborn, and don't want to use arc, then make sure you are releasing EVERYTHING that you don't need.
     

Share This Page