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);
- Where are they?
- In general, how can I tell so I don’t create leaks in the future?
- What’s the proper way to fix them?
Thanks so much!
AS far as I can tell you have memleaks in:
You need to call CGContextRelease. Check this SO question out.
You need to release
imageaswell. After creatingimageData, do:You don’t have to release
fileNamesince 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.