(iphone) am I creating a leak when creating a new image from an image?

Posted by Eugene on Stack Overflow See other posts from Stack Overflow or by Eugene
Published on 2011-01-08T15:24:27Z Indexed on 2011/01/08 15:53 UTC
Read the original article Hit count: 149

Filed under:
|
|

Hi,

I have following code as UIImage+Scale.h category.

-(UIImage*)scaleToSize:(CGSize)size
{                                                                                                                                                                                     
  UIGraphicsBeginImageContext(size);

  [self drawInRect:CGRectMake(0, 0, size.width, size.height)];

  // is this scaledImage auto-released?                                                                                                                                                                                        
  UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext(); 

  UIGraphicsEndImageContext();

  return scaledImage;
}

I use image obtained as above and use it as following.

UIImage* image = [[UIImage alloc] initWithData: myData];
image = [image scaleToSize: size]; <- wouldn't this code create a leak since
                                    image(before scaling) is lost somewhere?

i guess above codes work fine if image was first created with auto-release.
But if image was created using 'alloc', it would create a leak in my short knowledge.

How should I change scaleToSize: to guard against it?

Thank you

© Stack Overflow or respective owner

Related posts about iphone

Related posts about uiimage