Reputation: 18578
Here's a block of code that has leaks...
NSString *filename = [NSString stringWithFormat:@"%@.png", sketchID];
CGImageRef imageRef = CGBitmapContextCreateImage(paintView.canvas.mBitmapContext);
UIImage* image = [[UIImage alloc] initWithCGImage:imageRef];
NSData* imageData = UIImagePNGRepresentation(image);
Thanks so much!
Upvotes: 1
Views: 426
Reputation: 58097
The general rule is that when you call alloc
then you need a corresponding release
. The exception is when you call autorelease
. Also, when you use convenience methods, such as 'stringWithFormat'.
Upvotes: 0
Reputation: 181420
AS far as I can tell you have memleaks in:
CGImageRef imageRef = CGBitmapContextCreateImage(paintView.canvas.mBitmapContext);
You need to call CGContextRelease. Check this SO question out.
You need to release image
aswell. After creating imageData
, do:
[image release];
You don't have to release fileName
since you are not explicitly allocating memory for it. It will autorelease when variable falls out of scope. There are naming conventions in objective-c that will tell you when you will have to release and when you don't. Check out Apple documentation for it.
Hope it helps.
Upvotes: 4