Memory increasing by 20 MB every time i scale the image
I have following method to scale down an image. But Every time i click a
picture using my ipad 2 and call this method the Real memory size of the
application in instruments goes up up 20 MB. Eventually crashing the
application. This method always runs on the main thread. What could be a
possible reason for such a huge increase in memory.
+ (UIImage*)imageWithImage:(UIImage*)image
scaledToSize:(CGSize)newSize
{
CGFloat ratioForCompressionAspect = 1.0;
if ( image.size.width/newSize.width >
image.size.height/newSize.height){
ratioForCompressionAspect = image.size.width/newSize.width;
}
else{
ratioForCompressionAspect = image.size.height/newSize.height;
}
newSize = CGSizeMake(image.size.width/ratioForCompressionAspect,
image.size.height/ratioForCompressionAspect);
UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
No comments:
Post a Comment