title: objective c perform selector in background and autoreleasepool
body: <p>I am developing an iphone application which has some data stored in a sqllite database. When my view loads i would like to load the data from the database on a background thread. The problem is the application keeps crashing and i dont know why. </p>
  
  <p>The code:</p>
  
  <pre><code>-(id) init
  {
      if((self=[super init]))
      {
         [self performSelectorInBackground:@selector(loadList) withObject:nil];
      }
   }
  
  -(void) loadList
  {
     @autoreleasepool
     {
        Loader * loader = [[Loader alloc] init];
        NSMutableArray * array = [loader getItemList];
        [array retain];
        NSLog(@"Got %d items",[array count]);
  
        [self performSelectorOnMainThread:@selector(createList:) withObject:array waitUntilDone:false];
        [loader release];
     }
  }
  
  -(void) createList: (NSMutableArray*) array
  {
      items = array;
      int i;
      Item * it;
      for(i = 0; i &lt; [items count]; i++)
      {
        it = [items objectAtIndex: i];
        [it getName]; // crashes
        // populate the list
      } 
  }
  </code></pre>
  
  <p>Loader returns a NSMutableArray with Item objects. The application crashes when i call the item getName (which returns a NSString*). From what i understand it crashes because the item name properties is being released. What am i doing wrong? </p>
  
  <p>Thanks!</p>