title: Memory leak when scrolling UIScrollView
body: <p>In my iPhone app, I am dynamically adding a <code>UIScrollView</code> and adding n number of <code>UIImage</code>s and <code>UIButton</code>s into the scrollview. Here, the images are loaded from different urls and the button titles are coming from SQlite database. Everything is fine. But when I scroll the scrollview, now I am getting memory warning Level=1 and after some time it is Level=2 and crashes the app. I am using ARC. How can I fix this problem?</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>- (void)setUpViewLayout{
      int newContentSize = [appDelegate.itemArray count] * 125;
  
      menuItemIdArray = [[NSMutableArray alloc]init];
      mainView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 100, 480, 220)];
      mainView.contentSize = CGSizeMake(newContentSize, 220);
      mainView.tag = 100;
      mainView.delegate = self;
      mainView.userInteractionEnabled = YES;
      mainView.backgroundColor = [UIColor clearColor];
  
      int xPosition = 20;
  
      for (tagVal = 0; tagVal &lt; [appDelegate.itemArray count]; tagVal++) {
          [self createImage:xPosition];
          [self createButton];
          xPosition = xPosition + 120;
      }
      [self.view addSubview:mainView];
  }
  
  - (void)createImage:(int)xPosition{
      DataBaseClass *itemObj = [appDelegate.itemArray objectAtIndex:tagVal];
  
      NSString *url = [NSString stringWithFormat:@"%@",itemObj.notAvialableIcon];
      imgView = [[UIImageView alloc]initWithFrame:CGRectMake(xPosition+8, 48, 110, 123)];
      imgView.userInteractionEnabled = YES;
      imgView.tag = tagVal;
  
      [imgView setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"item01.png"]];
  
      [mainView addSubview:imgView];
  }
  - (void)createButton{
      DataBaseClass *itemObj = [appDelegate.itemArray objectAtIndex:tagVal];
      button = [UIButton buttonWithType:UIButtonTypeCustom];
      button.frame = CGRectMake(5, 90, 100, 26);
      button.tag = tagVal;
      button.userInteractionEnabled = YES;
      button.tag = tagVal;
      button.titleLabel.textColor = [UIColor blueColor];
      button.titleLabel.font = [UIFont systemFontOfSize:9.0];
      NSString *name = [NSString stringWithFormat:@"%@",itemObj.itemStatus];
      itmName = [NSString stringWithFormat:@"%@",itemObj.itemName];
  
      NSString *date = [self changeDateFormat:itemObj.itemReleaseDate];          
      [button setTitle:date forState:UIControlStateNormal]; 
      button.userInteractionEnabled = NO;
      button setBackgroundImage:[UIImage imageNamed:@"not_available_bttn_bck_img"] forState:UIControlStateNormal];
  
      [imgView addSubview:button];
  }
  </code></pre>