Lot of memory consumed while drawing Image

Discussion in 'iOS Programming' started by amalshah71, May 13, 2009.

  1. amalshah71 macrumors member

    Joined:
    Feb 1, 2009
    #1
    At this stage i am going through memory usage issue's in my app...

    i have a app whereing i have some 10-12 UIView subclass's objects...and each object has some kind of base image that i render on respective object in drawRect using [image drawAtPoint];....

    while doing analysis found out that this image drawing actually takes a lot of space( > 1.5 MB) whereas each image is of size less then 5 kb.

    I create image using [UIImage imageNamed]....but i don't think that should be the issue....since memory shoots up whenever i make a view currently displayable which in turn draws it's respective image....

    If i comment [image drawAtPoint] part...then memory consumption after drawing is not greater than 200 kb

    what am i missing?


    amal
     
  2. jnic macrumors 6502a

    Joined:
    Oct 24, 2008
    Location:
    Cambridge
    #2
    Not sure if it's helpful, but imageNamed's caching behaviour can cause memory problems in many cases as you don't have control of when images are cleared from the cache. You might find initWithContentsOfFile preferable.
     
  3. amalshah71 thread starter macrumors member

    Joined:
    Feb 1, 2009
    #3
    Yeah...tried initWithContentsOfFile....but the result the same.....

    the problem is actually with drawing of image....i just don't understand why does a drawing of image take so much memory....


    amal
     
  4. RobertBlackburn macrumors newbie

    Joined:
    Oct 7, 2008
    #4
    When an image is stored in memory it is converted to bitmap format regardless of the input format. If the image has Alpha then the image will take up 8 bits for red, 8 for green, 8 for blue and 8 for alpha per pixel in the image, this is a 32bit bitmap if there is no alpha channel it will use 24bit bitmaps.

    An Image of 480 x 320 x 32BitsPerPixel = 4915200bits roughly 4.6mb

    The only way around this problem would be to use opengl and use RGB565 which uses 5 bits per pixel or use PVRTC which is 2 or 4 bpp but has alot of artifacts in the picture. This is obviously alot harder than using UIImages.

    Hope that clears things up for you :)
     

Share This Page