Objective-c – jpg or png for UIImage — which is more efficient

cocoa-touchiphoneobjective cuiimage

I am grabbing an image from the camera roll and then using it for a while as well as save it to disk as a PNG on the iPhone. I am getting the odd crash, presumably due to out of memory.

Does it make a difference if I save it as PNG or JPG (assuming I choose note to degrade the quality in the JPG case)? Specifically:

  • is more memory then used by the UIImage after I reload it off of disk if I saved it as a PNG?
  • is it possible the act of saving as PNG uses up more memory transiently during the saving process?

I had been assuming the UIImage was a format neutral representation and it shouldn't matter, but I thought I should verify.

Best Answer


I am getting the odd crash, presumably due to out of memory


Then STOP WHAT YOU ARE DOING RIGHT NOW and first figure out if that's actually the cause of the crash. Otherwise there's a very good chance that you're chasing the wrong problem here, fixing a memory problem that doesn't exist while ignoring the real cause of the crash. If you want to fix a crash, start by figuring out what caused the crash. Following up on what's "presumably" the problem is a recipe for wasted time and effort.

Related Topic