Krumelur
Krumelur

Reputation: 33048

How to load a UIImage from file without caching in Monotouch?

If I look at the discussion here: http://monotouch.2284126.n4.nabble.com/UIImageView-td4303177.html

Both, UIImage.FromFile() and UIImage.FromFileUncached() map to imageWithContentsOfFile: and are not supposed to cache, however my experience is different and I'm pretty sure that UIImage.FromFile() caches (from what I see in Instruments).

The documentation here (http://docs.xamarin.com/ios/tutorials/Working_with_Images) states that UIImage.FromBundle() does cache, but UIImage.FromFile() does not. Is that still true? Or is there maybe some magic that FromFile() caches if the image is inside the app bundle?

Can somebody please make clear what is the correct way to:

Upvotes: 4

Views: 3232

Answers (1)

poupou
poupou

Reputation: 43553

UIImage.FromFile and UIImage.FromFileUncached are identical. They both call the same imageWithContentsOfFile: selector.

Xamarin's documentation on FromFileUncached explain why this was done.

Alias to FromFile, merely with a more explicit name to draw attention to the cache-less nature of this call compared to FromBundle.

Historically the original API for this selector was named FromFileUncached, while the old FromFile method was mapped to imageNamed: - but it turned out this was a mistake since the later selector means from the bundle.

A new FromBundle methods was added and, not to break the API, FromFile became identical to FromFileUncached.

I'll add an [Obsolete] attribute to the FromFileUncached method since it will make it more obvious inside the IDE, i.e. without reading the documentation.

Can somebody please make clear what is the correct way to:

FromFile[Uncached] does not cache, FromBundle does.

Upvotes: 7

Related Questions