I have an class method which generates a UIImage, like this:
+ (UIImage*)imageWithFileName:(NSString*)imgFile {
UIImage *img = nil;
NSBundle *appBundle = [NSBundle mainBundle];
NSString *resourcePath = [appBundle pathForResource:imgFile ofType:nil];
if (resourcePath != nil) {
NSURL *imageURL = [NSURL fileURLWithPath:resourcePath];
NSData *data = [[NSData alloc] initWithContentsOfURL:imageURL];
img = [UIImage imageWithData:data]; // should be autoreleased!!
[data release];
}
return img;
}
However, when I use this, the image data is NEVER freed. There is definitely a memory bug with this, although I didn't break any memory management rule I am aware of. My guess is that because this is a class method which gets called from instance methods, There is no active autorelease pool in place or it's one that only gets drained when I quit the app. Could that be right?