Can someone please explain why the following code causes my app to bomb?
NSData *myImage = UIImagePNGRepresentation(imageView.image); : [myImage release];
If I comment out the ‘release’ line, the app runs… but a few times calling the function containing this code and I get a crash – I guess caused by a memory leak.
Even if I comment EVERYTHING else in the function out and just leave those two lines, when the release executes, the app crashes.
I’m sure this must be a newbie ‘you don’t know how to clean up your mess properly’ kind of thing 😉
Cheers,
Jamie.
Are you sure you should be calling
release— the general rule of MacOS APIs is that methods that transfer ownership haveCopyorCreatein their name. I suspect you’re being given a reference to the underlying image representation, rather than a copy, in which case you’re releasing an object owned by something else.