title: Optimize loading of many images on iPad
body: <p>I'm working on a project for the iPad where I'm trying to simulate the rotation of a 3D-body with touch by switching pre-rendered images.</p>
  
  <p>I'm not the sharpest man when it comes to memory management so I wonder if anyone has any tips on how to optimize this.</p>
  
  <p>My solution now looks something like this:</p>
  
  <pre><code>- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
  UITouch *myTouch = [[event allTouches] anyObject];
  CGPoint location = [myTouch locationInView:self.view];
  int pictureIndex;
  //Rough mapping of image to point on screen
  if (location.x &lt;= 384 ) {
      pictureIndex = (384 - location.x)/(768/rotatingPictures)+1;
  }
  else {
      pictureIndex = rotatingPictures - (location.x-384)/(768/rotatingPictures)+1;
  }
  [theImageView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"image_%d.png", pictureIndex]]];
  </code></pre>
  
  <p>}</p>
  
  <p>Is it efficient to load the images this way? Would it be better to load the images to an array first or something like that?</p>
  
  <p>I would prefer to have all loading time at once and not while rotating.</p>