Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

amalshah71

macrumors member
Original poster
Feb 1, 2009
51
0
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
 
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.
 
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.

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
 
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

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 :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.