Question

I have an application and I am profiling it. I am quite new to instrument and I am quite new ios developer as well. I am working with ios6 and I have a very unusual leak. I create a category on UIImage and added helper methods to return the image for using capinsets. My category looks like this,

@implementation UIImage (Helpers)

+(UIImage*)resizableImageWithName:(NSString *)imageName andCapInsets:(UIEdgeInsets)insets{
    UIImage *image = [UIImage imageNamed:imageName];
    return [image resizableImageWithCapInsets:insets];
}

@end

The instrument shows 3/4 leaks in this area, the same place and I could not figure out the reason for it. Is it that, I have to release the new image I created inside the category, if I release it what am I going to return ? Could any one please explain the reason that I am leaking memory here.

And I used it like this;

[self.progressView setTrackImage:[UIImage resizableImageWithName:@"progress_bar_background.png" andCapInsets:UIEdgeInsetsMake(2, 2, 2, 2)]];

Is there something wrong in using this method in this way ?

Was it helpful?

Solution

The method that Instruments shows you is the place where the leaked memory is allocated -- not necessarily the place where the memory is leaked. Indeed your method is correct as to memory management.

Thus, you better inspect how you handle the returned UIImage object... possibly, if this hint does not help you finding the leak cause, post some more code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top