Reputation: 41745
I'm having trouble with UIImage memory size.
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?
does a screen size(resolution) affect the memory usage of an image?
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
Reputation: 1778
TO CHECK MEMORY ALLOCATION
If you want to test for specific images, run your application in the iPhone/Simulator while using Instruments.
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.
Upvotes: 2
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