1

I am considering using sprites for an image heavy game.

I'm trying to determine whether any extra memory is allocated when sharing a single UIImage between image views. I ran a test by creating 40 image views, once with a single image and once by creating 40 image instances and they appeared to use the same amount of memory.

If extra memory is allocated per image view using a single image, what's the use of using sprites?

modfrq
  • 31
  • 3

1 Answers1

2

I believe I've just answered my own question. It appears the memory allocations for both tests are the same because I was using imageNamed: to load the images. And as noted here: Dispelling the UIImage imageNamed: FUD

With respect to the general behavior of the cache, it does cache based on filename (so two instances of +imageNamed: with the same name should result in references to the same cached data)

I reran the test using imageWithContentsOfFile: and found that no extra memory was allocated when sharing the same UIImage.

Community
  • 1
  • 1
modfrq
  • 31
  • 3
  • Congrats on the fix. When you are able, please mark your answer as accepted so that others might learn of your solution. Cheers~ – Andrew Kozak Mar 27 '12 at 16:47
  • Thanks for pointing this out- I'm new to SO. I tried to it accept it, but it said I can't until tomorrow. Will do it then, though. – modfrq Mar 27 '12 at 17:27