Let’s say I have an object called Person.
Person internally loaded an UIImage called “person.png”.
In my app i create many Person objects, creating and even deleting them at runtime.
Since a Person object internally has a retained reference to UIImage, does this mean each Person has a unique memory allocation for the image?
Or do all Person objects point to the same memory location for the image?
Well, it depends on how you’re getting the UIImage.
Are you using +[UIImage imageNamed:] each time you create a new Person object? If so, UIKit caches the image and returns references to a single copy in memory. You retain it to make sure it stays loaded, then release it when you’re done referencing it, but only one UIImage object is created in memory.
If, on the other hand, you’re calling +[UIImage initWithData:] or [[UIImage alloc] initWithContentsOfFile:] you’re creating a new copy in memory each time (and you probably need to stop that 🙂