views:

103

answers:

3
UIGraphicsBeginImageContext(targetSize); //instruments show here a leak 128bytes

CGRect thumbnailRect = CGRectZero;

thumbnailRect.origin = thumbnailPoint;
thumbnailRect.size.width  = scaledWidth;
thumbnailRect.size.height = scaledHeight;

[sourceImage drawInRect:thumbnailRect];

newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Hi I'm trying to scale a UIImage so I load it with

[UIImage imageNamed:@"myImage.png"];

and then pass it into a method. In that method I have the code above that resizes my image and at the end of the method I have a

return newImage;

The instruments show me a leak at line

UIGraphicsBeginImageContext(targetSize); //instruments show here a leak 128bytes

What am I doing wrong? Where exactly is the leak?

A: 

According to the docs, the argument to UIGraphicsBeginImageContext should be the actual size of the object returned from UIGraphicsGetImageFromCurrentImageContext(). Why are you calling it before you've received such an object?

ShadowRanger
I think you're misunderstanding the purpose of these methods. `UIGraphicsBeginImageContext` creates a graphics context with the dimensions (in a `CGSize` struct) that you give it. `UIGraphicsGetImageFromCurrentContext` returns an image with the dimensions and content of the current graphics context.
Noah Witherspoon
Probably. I'm not familiar with Mac programming and probably misunderstood the example.Oh well. I guess this is one of the risks that comes with using provided libraries; you don't control your own bugs.
ShadowRanger
A: 

You don't appear to be doing anything wrong; it could be a bug in the UIGraphicsBeginImageContext method. 128 bytes is kind of trivial, though—unless you're doing this thumbnail creation a huge number of times, you probably don't need to worry about it.

Noah Witherspoon
I'm only doing it once but it pisses me off not knowing what is wrong. Thanks for your response
Horatiu Paraschiv
+1  A: 

Instruments will tell you where the memory was first allocated; this apparently is in UIGraphicsBeginImageContext(). I think double-clicking the leak (or so) will list all the retains/autoreleases/releases; look in one of those.

tc.