title: iphone memory deallocation issue with scrollview with image inside
body: <p>I'm having trouble deallocating a UISCrollView that contains images.
  There's something wrong with my code, but I cannot understand where.</p>
  
  <p>this is a snippet of my code. It basically create a loops adding a uiscrollview with an image and removing.
  If you run the code with instruments, no memory will be freed.
  I also add some check for the retainCount, with no luck at all..</p>
  
  <p>here's the code</p>
  
  <pre><code>- (void)loadView {
   [super loadView];
   CGRect theRect = CGRectMake(0, 0, 320, 480);
   UIView *view = [[UIView alloc] initWithFrame:theRect];
   [view setBackgroundColor:[UIColor purpleColor] ];
   self.view = view;
   [view release];
  
   UIView *pippo = [[UIView alloc] initWithFrame:theRect];
   [pippo setBackgroundColor:[UIColor redColor]];
   [self.view addSubview:pippo];
   [pippo release];
  
   [self performSelector:@selector(scrollAdd:) withObject:nil afterDelay:2.0f];
  }
  
  
  
  -(void)scrollAdd:(id)o {
   CGRect theRect = CGRectMake(0, 0, 320, 480);
   int numero = 1;
   scroll = [[UIScrollView alloc] initWithFrame:theRect];
   [scroll setContentSize:CGSizeMake( 320*numero,1)];
   [scroll setScrollEnabled:YES];
  
   UIImage *img = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"koala1b" ofType:@"jpg"]];
   int dd = [img retainCount];
   UIImageView *v2 = [[UIImageView alloc] initWithFrame:theRect];
   [v2 setImage:img];
   [scroll addSubview:v2];
   dd = [v2 retainCount];
   [v2 release];
   dd = [v2 retainCount];
   dd = [img retainCount];
   [self.view addSubview:scroll];
   [img release];
   dd = [img retainCount];
  
   [self performSelector:@selector(scrollRemove:) withObject:nil afterDelay:2.0f];
  }
  
  -(void)scrollRemove:(id)o {
   int dd = [scroll retainCount];
   UIImageView *theV = [[scroll subviews] objectAtIndex:0];
   dd = [theV retainCount];
   [scroll removeFromSuperview];
   dd = [theV retainCount];
   [theV release];
   dd = [theV retainCount];
   dd = [scroll retainCount];
   scroll = nil;
   [self performSelector:@selector(scrollAdd:) withObject:nil afterDelay:2.0f];
  }
  </code></pre>