title: UIScrollview not smoothly scrolling , there is no paging and no calculation on swipe
body: <p>I am adding <code>UIButtons</code> with background images to <code>UIScrollview</code> Programmatically. If I have added 4 to 5 <code>UIButtons</code> then I am receiving memory warning and my app quits. I don't understand to optimize my below code what wrong with this , could anyone please let me know ? I am using ARC. Having this issue on only iPhone4 with iOS 7.1.2 . on iPad with latest iOS working fine.</p>
  
  <pre><code>- (void)showAttachment
  {
     // UIImage* imgVideoThumbnail=[self getThumbNailFromURL:[NSURL URLWithString:self.notesEntity.videoPath]];
  
      NSMutableDictionary* dict=[NSMutableDictionary dictionary];
  
      NSArray* arr=[self.notesEntity.imagePath componentsSeparatedByString:@"-&gt;"];
      if (imgVideoThumbnail)
          [dict setObject:imgVideoThumbnail forKey:self.notesEntity.videoPath];
      for (NSString* stringPath in arr)
      {
          if ([stringPath length]&gt;2)
          {
  
              UIImage* img=[UIImage imageWithContentsOfFile:stringPath];
              [dict setObject:img forKey:stringPath];
              img=nil;
          }
      }
  
      for (UIButton* view in self.scrollView.subviews)
      {
          [view removeFromSuperview];
      }
  
      CGRect rect=self.scrollView.bounds;
      CGFloat x=5;
      for (NSString* urlImg in dict)
      {
          UIButton* btn=[UIButton buttonWithType:UIButtonTypeCustom];
          btn.frame=CGRectMake(x, 2, 60, 60);
          [btn setImage:[dict objectForKey:urlImg] forState:UIControlStateNormal];
          [btn setTitle:urlImg forState:UIControlStateNormal];
          btn.titleLabel.textColor=[UIColor clearColor];
          btn.layer.borderWidth=1.0;
          btn.layer.borderColor=[UIColor blueColor].CGColor;
          btn.layer.cornerRadius=7.0;
          btn.layer.masksToBounds=YES;
  
          [self.scrollView addSubview:btn];
          btn=nil;
          x+=105;
          if (x&gt;self.view.bounds.size.width)
              self.scrollView.contentSize=CGSizeMake(x, rect.size.height);
      }
      dict=nil;
  }
  - (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
      NSLog(@"Picker returned successfully.");
     // NSLog(@"%@", info);
      NSString     *mediaType = info[UIImagePickerControllerMediaType];
  
      if ([mediaType isEqualToString:(__bridge NSString *)kUTTypeMovie])
      {
          NSURL *urlOfVideo = info[UIImagePickerControllerMediaURL];
          NSData* data=[NSData dataWithContentsOfURL:urlOfVideo];
          NSString* diskFilePath;
          if ([self.notesEntity.videoPath length]&gt;2)
              diskFilePath=self.notesEntity.videoPath;
          else
              diskFilePath=[NSString stringWithFormat:@"%@/%@.MOV",self.appDeleage.notesDirectoryPath,[self.appDeleage getFileName]];
          NSError* err;
  
          [data writeToFile:diskFilePath options:NSDataWritingAtomic error:&amp;err];
          if (err==nil)
          {
              self.notesEntity.videoPath=diskFilePath;
              //[self showAttachment];
          }
          data=nil;
      }
      else if ([mediaType isEqualToString:(__bridge NSString *)kUTTypeImage])
      {
          UIImage *theImage = info[UIImagePickerControllerOriginalImage];
          NSData* data=UIImagePNGRepresentation(theImage);
          NSError* err;
          NSString* diskFilePath=[NSString stringWithFormat:@"%@/%@.png",self.appDeleage.notesDirectoryPath,[self.appDeleage getFileName]];
  
  
          [data writeToFile:diskFilePath options:NSDataWritingAtomic error:&amp;err];
          if (err==nil)
          {
              if ([self.notesEntity.imagePath length]&gt;2)
              {
                  self.notesEntity.imagePath=[NSString stringWithFormat:@"%@-&gt;%@",self.notesEntity.imagePath,diskFilePath];
              }
              else
              {
                  self.notesEntity.imagePath=diskFilePath;
              }
              NSError *error;
              if (![managedObjectContext save:&amp;error])
              {
                  NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
              }
          }
      }
      [picker dismissViewControllerAnimated:YES completion:nil];
      info=nil;
  }
  </code></pre>