title: Getting exceptions when using thumb images from web with iphone tableviews cells
body: <p>I have a drill-down tableviews of categories and products, these are loaded from dictionaries which were populated from JSON via a request to a web service, no problems there, all works fine and displays the text as required and navigation works as expected.</p>
  
  <p>The problem arises when I want to use thumb images with the text, which have to be sourced and loaded from the website where they are contained, and displayed with the text, this works to the point of loading the initial view and say the first 8 visible products, but when you try to scroll the list of products I get various exceptions occurring, like:</p>
  
  <pre><code>*** -[UIImage isKindOfClass:]: message sent to deallocated instance 0x5f94b90
  </code></pre>
  
  <p>I know its something to do with how the tableview saves memory by only allocating and displaying for the visible items in the list, but I can't seem to figure out if I need to clean up my allocation of image before another is sourced from the web to be display.</p>
  
  <p>Ideally, I would like the images cached in some way to avoid having to reload for every scroll the user makes, but I'm not sure how to do that just yet.</p>
  
  <p>Here's the code for the loading of the cell.</p>
  
  <pre><code>// Customize the appearance of table view cells.
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
      static NSString *ProductCellIdentifier = @"ProductCell";
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ProductCellIdentifier];
      if (cell == nil) {
          cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ProductCellIdentifier] autorelease];
      }
  
      // Configure the cell...
      NSInteger row = [indexPath row];
  
      // get data from dictionary for index
      NSDictionary *rowData = [self.productsDict objectAtIndex:row];
  
      // load image and display
      NSString *imgUrl = [rowData valueForKey:@"image_url"];
      NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:imgUrl]];
      UIImage *image = [UIImage imageWithData:imageData];         
      cell.imageView.image = image;
  
      cell.textLabel.text = [rowData valueForKey:@"name"];
      return cell;
  }
  </code></pre>