1

i´ve created a little game in which images are loaded when the user is touching the screen while moving. It depends on the screen position to load different images immediately. I´ve got an UIImageView and because within the "touchesMoved" function, i´m loading the different images like this:

 imageView.image =  [UIImage imageNamed: [photos objectAtIndex: newImage ] ] ;

Now i want to improve my memory management using Instruments with "Allocations" & "Memory Monitor". Here´s i´m setting different snapshots with "Mark Heap" points and look for leaks. The line above is highlighted and now i want to know what´s wrong with it.. How can i improve that image-loading (without caching)?

geforce
  • 2,593
  • 3
  • 28
  • 44

3 Answers3

0

Read this Dispelling the UIImage imageNamed: FUD

and also read the links in the question as well. Should answer everything you need.

Community
  • 1
  • 1
Bourne
  • 10,094
  • 5
  • 24
  • 51
0

First of all: imageNamed: does cache images. If you're getting this line highlighted then there are 2 possible reasons (or both):

  1. you're not properly releasing imageView
  2. you're not properly releasing the photos array
Max
  • 16,679
  • 4
  • 44
  • 57
0

+imageNamed returns an autoreleased object, yet the @property image in UIImageView retains it through its use until overwritten. -objectAtIndex: must return an object with a retain count of 1 which is not released.

If that indeed is the problem then the fix is

imageView.image =  [UIImage imageNamed: [[photos objectAtIndex: newImage ] autorelease]];

However I doubt that is the real issue here.

Alan Zeino
  • 4,406
  • 2
  • 23
  • 30
  • bad solution. you have to find the real cause of the leak and no to fix it like this. – Max Feb 17 '11 at 00:26