eugene
eugene

Reputation: 41745

(iphone) how much memory UIImage takes up?

I'm having trouble with UIImage memory size.

  1. When you have 320*320 resolution image data(png), when you load the image onto memory,
    using [UIImage imageWithData:], the resulting UIImage will take up 320*320*4?

  2. does a screen size(resolution) affect the memory usage of an image?

  3. Would the code below take up twice memory size of myImage or just single image memory size? (320*320*4) * 2 vs (320*320*4)? or something else?

    UIImage* myImage = [UIImage imageWithData:];    
    myImage = [myImage scaleToSize:];
    

    when scaleToSize is defined as

    - (UIImage*)scaleToSize:(CGSize)size
    {
      // Create a bitmap graphics context                                                                                              
    
    
      // This will also set it as the current context                                                                                                                                                                                                                             
      UIGraphicsBeginImageContext(size);
    
      // Draw the scaled image in the current context                                                                                                                                                                                                                             
      [self drawInRect:CGRectMake(0, 0, size.width, size.height)];
    
      // Create a new image from current context                                                                                                                                                                                                                                  
      UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    
      // Pop the current context from the stack                                                                                                                                                                                                                                   
      UIGraphicsEndImageContext();
    
      // Return our new scaled image                                                                                                                                                                                                                                              
      return scaledImage;
    }
    

Upvotes: 0

Views: 529

Answers (2)

OFRBG
OFRBG

Reputation: 1778

TO CHECK MEMORY ALLOCATION

If you want to test for specific images, run your application in the iPhone/Simulator while using Instruments.

Run with the Allocations profile

Make sure you choose the appropriate target. When you run the program, you'll see the memory space taken by a specific allocation.


WHILE RUNNING

You'll see the objects allocated in the window. Like this one, to which I attached iTunes.

While running

Upvotes: 2

WrightsCS
WrightsCS

Reputation: 50727

Obviously the larger the image the more memory you will use, same goes for the amount of images you load into memory at once.

Upvotes: 0

Related Questions