views:

29

answers:

1

Hello guys!

Here's my code:

        NSLog(@"rc: %d", [_pagesButton retainCount]);
        NSMutableArray *anArray = [[NSMutableArray alloc] initWithArray:_toolbar.items];
        NSLog(@"rc: %d", [_pagesButton retainCount]);
        [anArray removeObjectAtIndex:2];
        NSLog(@"rc: %d", [_pagesButton retainCount]);
        [_toolbar setItems:anArray animated:YES];
        NSLog(@"rc: %d", [_pagesButton retainCount]);
        [anArray release];
        NSLog(@"rc: %d", [_pagesButton retainCount]);

and here is the output:
rc: 2
rc: 3
rc: 2
rc: 3
rc: 3

The first rc is 2 because the the _pagesButton has retained by the this variable and by the toolbar.items array. After I create the anArray variable the retain count is 3, then I remove the _pagesButton from the anArray variable so the retain count goes to 2. Then I set the _toolbar.items and the retain count goes to 3. But why??? And when I release the anArray variable the retaincount still 3. Why? Please help me a bit.