title: iOS - Create a Photo Viewer like Photo app
body: <p>i'm trying to create a photo viewer like the Apple Photos app in iOS.
  The layout is ok, but it receives memory warning and then crashes. Why? This happens even i load 7/8 images from the app documents folder. Have i to manage the memory with specific system? I use ARC with iOS 5.</p>
  
  <p>EDIT :</p>
  
  <p>The code :</p>
  
  <pre><code>for (int i=0; i&lt;[dataSource count]; i++) {
          UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
          [button setImage:[dataSource objectAtIndex:i] forState:UIControlStateNormal];
          [[button titleLabel] setText:[NSString stringWithFormat:@"%i",i+1]];
          [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
          [[button layer] setBorderWidth:1];
          [[button layer] setBorderColor:[UIColor darkGrayColor].CGColor];
          if (i==0) {
              [button setFrame:CGRectMake(x, y, width, height)];
          } else {
              if (i%5==0) {
                  nRow++;
                  x=18;
                  [button setFrame:CGRectMake(x, (y*nRow), width, height)];
              } else {
                  [button setFrame:CGRectMake(x+space+width, (y*nRow), width, height)];
                  x=button.frame.origin.x;
              }
          }
          [[self view] addSubview:button];
      }
  </code></pre>
  
  <p>The main part of this code is the first 6 lines, after is all x and y.
  dataSource is an NSArray declared as property (nonatomic, strong). It contains UIImage objects.</p>