On my quest to reduce memory usage, another question.
I see that UIImage and CGImage might be candidates for high memory usage in my app.
Wherever I use a UIImage, I try to wrap it in a using block to have it Dispose()‘d as soon as possible.
However, often the UIImage ends up in a UIImageView.Image property.
If I remove the UIIImageView from its Superview, am I supposed to Dispose() the Image property before and set it to null or is this wasted typing?
Quick answer: No.
Long answer:
The
UIImageView.Imageproperty,imageselector, is retained. Even if you dispose it (from the managed side) the native retainCount (Objective-C is reference counted) of theUIImagewill still be higher than 0 and the (native side of the)UIImagewon’t be freed.When you dispose the
UIImageViewit will release theUIImageit use (Apple’s Objective-C code) and, if the retainCount reach 0, it will be natively freed.If there’s a large delay between when you stop needing the
UIImageand the time you dispose of theUIImageViewthen you might want to setUIImageView.Imagetonull. That will release (in the ObjC way, i.e. drop its retainCount by one) theUIImageand, if it’s not used elsewhere, it will be (natively) freed.Note that, if the
UIImageViewis not disposed, then setting itsImageproperty to anotherUIImagewill have the same result (the old one’s will be released).