Do I need to dispose UIImages and CGImages in MonoTouch application after I’ve finished working with them? What are the effects of disposing either of them?
Is it safe to dispose any of them if the image is still visible?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I suggest using a
usingblock for images like so:When the object leaves that block it will get disposed automatically.
Alternatively you can call
Dispose()on the UIImage when you know you are done using it.If you do not dispose of them and load a lot of images you will eventually run out of memory. Loading big images with the
UIImage.FromBundle()method is a bad idea as they are cached and you have no control over when the cache is disposed of.If you dispose an
UIImagewhich is currently shown nothing bad will happen with theUIImageViewas it keeps its own reference to the image. So only the C# managed image is disposed of but not necessarily the Cocoatouch image.