Image retention.

Discussion in 'iOS Programming' started by bakervillia, Jul 30, 2010.

  1. bakervillia macrumors newbie

    Jul 30, 2010
    Hi there, I'm pretty new to programming on the iPhone and I've run into an issue. I have an app that's supposed to load one of 30 images based on the date. I've stored each image in a separate nib file and wrote a method to choose and load the appropriate nib file. My problem is that when I load a new nib file, the memory allocated to the image from the previous nib file doesn't get deallocated. Each image takes up one 512k Malloc.

    My question is do I need to find a way to deallocate these images? Or will my app pass apple inspection without doing so. In the very worst scenario which I'm sure would never happen in a real user situation, all 30 images would be loaded into memory thus taking up about 15 megs of memory.

    I'd like to do this cleanly, but for the life of me, I can't figure out how to deallocate an image created in a nib file...

    Any help is greatly appreciated. Thank you.
  2. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    Few comments.

    I don't understand why you would need a different nib for different images. Just load up a nib with an imageview in it and load up the image and add the image to the imageview. What if you had 100 images, or 1000?

    Apparently images loaded in a nib are loaded into memory using UIImage imageNamed: This means that they are added to the image cache. The images in the image cache are released in case of a memory warning. If you want the images to be released immediately then only have an image view in the nib and use imageWithContentsOfFile to load the image and then add the image to the imageview. This gives you more control.

Share This Page