title: Objective C Reassignment/Memory Management Crash
body: <p>As a relative Objective-C beginner, I'm obviously still not grasping certain memory management rules.  I can't figure out how to make this not crash:</p>
  
  <pre><code>@interface MyClass { NSArray *playerArray4th; }
  
  - (void) viewDidLoad { playerArray4th = [self getAudioPlayersForSoundFile:@"rimshot" ofType:@"aif"]; }
  
  - (NSArray*) getAudioPlayersForSoundFile:(NSString*)soundFileName ofType:(NSString*)soundFileType {
  
      //code instantiating objects....
  
      NSArray *toRet = [[NSArray alloc] initWithObjects:toRetTickPlayer,toRetTickPlayerCopy,toRetTickPlayerCopy2,toRetTickPlayerCopy3, nil];
      return toRet;
  }
  </code></pre>
  
  <p>Then later, in a different function:</p>
  
  <pre><code>NSArray *currentArray = playerArray4th;
  [currentArray release];
  currentArray = nil;
  currentArray = [self getAudioPlayersForSoundFile:fileName ofType:ofType];
  </code></pre>
  
  <p>And it crashes when trying to access the array again:</p>
  
  <pre><code>- (void) playSound:(NSString*)soundType {
  
      AVAudioPlayer *currentPlayer;
  
      if ([soundType isEqualToString:@"4th"]) {
          if (playerArray4thCounter &gt;= [playerArray4th count]) playerArray4thCounter = 0;
          NSLog(@"Playing from array: %@",playerArray4th);
          currentPlayer = [playerArray4th objectAtIndex:playerArray4thCounter];
          playerArray4thCounter++;
      }
  }
  </code></pre>