Malloc error: double free in OBJC
<p>I'm working with an array of NSNumbers, and i have a method to fill them based on the button pressed; </p>

<pre><code> - (NSMutableArray *)addNumberToArray:(int)numPressed andWithGuessArray:(NSMutableArray *)guessArray andWithActiveIndex:(int)activeIndex {
NSNumber *numberPressed = [NSNumber numberWithInt:numPressed];
switch (numPressed) {
    case 1:
        [guessArray replaceObjectAtIndex:activeIndex withObject:numberPressed];
        break;

    case 2:
        [guessArray replaceObjectAtIndex:activeIndex withObject:numberPressed];
        break;

    case 3:
        [guessArray replaceObjectAtIndex:activeIndex withObject:numberPressed];
        break;

    case 4:
        [guessArray replaceObjectAtIndex:activeIndex withObject:numberPressed];
        break;

    case 5:
        [guessArray replaceObjectAtIndex:activeIndex withObject:numberPressed];
        break;

    case 6:
        [guessArray replaceObjectAtIndex:activeIndex withObject:numberPressed];
        break;

    case 7:
        [guessArray replaceObjectAtIndex:activeIndex withObject:numberPressed];
        break;

    case 8:
        [guessArray replaceObjectAtIndex:activeIndex withObject:numberPressed];
        break;

    case 9:
        [guessArray replaceObjectAtIndex:activeIndex withObject:numberPressed];
        break;

    default:
        break;
}
[numberPressed release];

for (int i = 0; i &lt; 4; i++) {
    NSLog(@"%i",[[guessArray objectAtIndex:i]intValue]);
}
NSLog(@"----");

return guessArray;
</code></pre>

<p>}</p>

<p>Then i have a method to delete all the numbers in the array.</p>

<pre><code>- (void)deleteAll:(id)sender {
NSLog(@"%@",guessArray);
for (int i = 0; i &lt; numbersInAns; i++) {
    [guessArray replaceObjectAtIndex:i withObject:[NSNumber numberWithInt:0]];

}

activeIndex = 0;
for (int i = 0; i &lt; 4; i++) {
        NSLog(@"%i",[[guessArray objectAtIndex:i]intValue]);
}
</code></pre>

<p>}</p>

<p>The problem occurs when i fill the array, clear it, fill it again, and try to clear it again. </p>

<p>2011-03-19 13:58:43.492 BombDefusal[4711:207] (
    2,
    2,
    3,
    3
) //this is whats in the array right before its cleared, these are all NSNumbers</p>

<p>BombDefusal(4711,0xa096a540) malloc: <strong>* error for object 0x4e0cc40: double free
*</strong> set a breakpoint in malloc_error_break to debug</p>

<p>(gdb) print-object 0x4e0cc40</p>

<p>2</p>

<p><em>Solved</em></p>
