CGImageRelease: [Not A Type release]: message sent to deallocated instance

前端 未结 1 997
北海茫月
北海茫月 2021-01-16 12:35

I\'m getting this error \"[Not A Type release]: message sent to deallocated instance\" on the last line of code \"CGImageRelease(imageToSave);\". Please explain why and what

相关标签:
1条回答
  • 2021-01-16 12:44

    Even worse than what someone0 is telling you:

    I would say as you defined your uiImageToSave in the else block, the reference you created with imageToSave is not valid outside of the else block - so any use of imageToSave in your code is just working by accident, as long as the memory is not overwritten yet.

    And as said, the [UIImage CGImage] call only gives you a reference to the image data, it does not make a copy or retain it - so you may not release it yourself, it is released automatically when the UIImage ceases to exist - which in your case is just one line after you make the reference.

    UPDATE:

    The code in the original posting is adjusted - the uiImageToSave is now defined in the right place (just if anyone wonders about my comment which is now not really fitting the original posting anymore :-).

    0 讨论(0)
提交回复
热议问题