I was going through this link, where I came across a point Avoid UIImage’s imageNamed. For what reason we should avoid this?
It caches the images and not releasing it, until it receives memory warning. I am not sure, but i guess it might prone to app crashes, if your app has a lot of images (big ones)
For me, I normally use "imageWithContentsOfFile":
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fileName ofType:nil]]
In Apple WWDC videos section they are saying imageNamed leaked once..But no longer do..I remember seeing the video, but cant remember which video section..It was in 2010 WWDC I think..ImageNamed still caches images..From documentation of imageNamed..
This method looks in the system caches for an image object with the specified name and returns that object if it exists. If a matching image object is not already in the cache, this method loads the image data from the specified file, caches it, and then returns the resulting object.
But I think these cache's will be cleared when any low memory condition occurs..Just for your information..I am an avid fan of imageNamed and I always use it..I never had any memory issues with it..
You should read the article to the end.
Avoid UIImage’s imageNamed: Alex Curylo has written an absolutely great article about the problems with UIImage’s imageNamed: static method. It seems (and in my tests this appears to be true) that the iPhone OS (versions 2.0 and 2.1 at least) uses an internal cache for images loaded from disk using imageNamed:, and that in cases of low memory this cache is not cleared up completely (this seems to be corrected with version 2.2, though, but I cannot confirm).
It says that it should be avoided in versions 2.0 and 2.1 of the SDK. It has been working properly for a long time.
Take a look at this question
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With