Understanding memory pointer and usage

Discussion in 'iOS Programming' started by beardedpig, Mar 11, 2009.

  1. beardedpig macrumors member

    Joined:
    Dec 17, 2008
    #1
    I have an array of images loaded using imagewithcontentsof file so no caching occurs.

    Now lets say for arguments case the array has just 2 images (a lot more in reality) and these 2 images when loading into the array take up 2mb of memory.

    Now I have an imageview which I set to switch between the images in the array using imageview.image = [myArray objectAtIndex: n];

    When I do this memory usage increases as if I am loading another version of each image into memory so I end up with 4mb of memory usage.

    In reality the numbers involved are greater and not so even but you get the idea.

    I was under the impression that the image in the imageview was pointing to the array and not creating a new copy?

    Have I lost the plot here?

    Any help would be greatfully received

    Thanks
     
  2. caveman_uk Guest

    caveman_uk

    Joined:
    Feb 17, 2003
    Location:
    Hitchin, Herts, UK
    #2
    It is (or it should be) but that's not to say that setting a pointer is all that happens when you set the image property. There may be an internal representation of the image that's created for display. So maybe the memory usage will go up (especially if the previous value of .image was nil). I'd only worry if the memory usage keeps going up or you find you actually have a leak.
     
  3. beardedpig thread starter macrumors member

    Joined:
    Dec 17, 2008
  4. caveman_uk Guest

    caveman_uk

    Joined:
    Feb 17, 2003
    Location:
    Hitchin, Herts, UK
    #4
    Actually I should be more accurate here. It's not pointing to the array but it's pointing to the same object a pointer in the array is pointing at.
     

Share This Page