title: how do i scroll through 100 photos in UIScrollView in IPhone
body: <p>I'm trying to scroll through images being downloaded from a users online album (like in the facebook iphone app) since i can't load all images into memory, i'm loading 3 at a time (prev,current &amp; next). then removing image(prev-1) &amp; image (next +1) from the uiscroller subviews.
  my logic works fine in the simulator but fails in the device with this error:
  [CALayer retain]: message sent to deallocated instance
  what could be the problem
  below is my code sample</p>
  
  <pre><code>- (void)scrollViewDidEndDecelerating:(UIScrollView *)_scrollView 
  {
      pageControlIsChangingPage = NO;
      CGFloat pageWidth = _scrollView.frame.size.width;
      int page = floor((_scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
  
      if (page&gt;1 &amp;&amp; page&lt;=(pageControl.numberOfPages-3)) {
          [self removeThisView:(page-2)];
          [self removeThisView:(page+2)];
      }
  
      if (page&gt;0) {
          NSLog(@"&lt;&lt; PREVIOUS");
          [self showPhoto:(page-1)];
      }
  
      [self showPhoto:page];
      if (page&lt;(pageControl.numberOfPages-1)) {
          //NSLog(@"NEXT &gt;&gt;");
          [self showPhoto:page+1];
          NSLog(@"FINISHED LOADING NEXT &gt;&gt;");
      }
  }
  
  -(void) showPhoto:(NSInteger)index
  {
      CGFloat cx = scrollView.frame.size.width*index;
      CGFloat cy = 40;
  
      CGRect rect=CGRectMake( 0, 0,320, 480);
      rect.origin.x =  cx;
      rect.origin.y = cy;
      AsyncImageView* asyncImage = [[AsyncImageView alloc] initWithFrame:rect];
      asyncImage.tag = 999;
      NSURL *url = [NSURL URLWithString:[pics objectAtIndex:index]];
  
      [asyncImage loadImageFromURL:url place:CGRectMake(150, 190, 30, 30) member:memberid isSlide:@"Yes" picId:[picsIds objectAtIndex:index]];
  
      [scrollView addSubview:asyncImage];
      [asyncImage release];
  }
  
  - (void) removeThisView:(NSInteger)index
  {
      if (index&lt;[[scrollView subviews] count] &amp;&amp; [[scrollView subviews] objectAtIndex:index]!=nil) {
          if ([[[scrollView subviews] objectAtIndex:index] isKindOfClass:[AsyncImageView class]] || [[[scrollView subviews] objectAtIndex:index] isKindOfClass:[UIImageView class]]) {
              [[[scrollView subviews] objectAtIndex:index] removeFromSuperview];
          }
      }
  }
  </code></pre>
  
  <p>For the record it works OK in the simulator, but not the iphone device itself.
  any ideas will be appreciated.
  cheers,
  fred.</p>