+[UIImage imageNamed:]
• Reads the file, uncompresses it, caches result
• Cached copy of data is kept even if the UIImage is deallocated
• Low memory condition causes cache to be purged.
• No direct control over when cache is purged.
• Use for small frequently drawn images.
+[UIImage imageWithContentsOfFile:]
• Just reads enough of file to determine if it can open the file.
• Reads and uncompresses the file each time it draws. Uses uncompressed size worth of memory only temporarily.
• Assigning a UIImage created this way to a UIImageView or as the contents of a CALayer also causes it to read and uncompress the file. The UIImageView or CALayer keep the expanded version.
Memory Usage (in MB) 8.6 MB image used with UIImageView
imageNamed | imageWithContentsofFile | |
Initial | 2.46 | 2.46 |
Load UIImage | 11.12 | 2.51 |
Assign to UIImageView | 11.09 | 11.09 |
Remove from UIImageView | 11.12 | 2.51 |
Memory Usage (in MB) 8.6 MB image used with UIView subclass (stored in instance variable and drawn with drawinRect: )
imageNamed | imageWithContentsofFile | |
Initial | 2.73 | 2.73 |
Load UIImage | 11.38 | 2.78 |
Assign to UIImageView | 11.81 | 3.20 |
Remove from UIImageView | 11.84 | 3.04 |
Спасибо за некоторые пояснения Андрею Копаневу :)
– Robert Clair