NSArray Memory Management
<p>For some reason when I release the NSArray I get the EXC_BAD_ACCESS exception. Here is the implementation: </p>

<pre><code>-(void) loadAllAlphabets
{
    NSBundle *bundle = [NSBundle mainBundle]; 
    NSArray *imagesPath = [[NSArray alloc] init]; 

    imagesPath = [bundle pathsForResourcesOfType:@"png" inDirectory:@"Images"];

    alphabets = [[NSMutableArray alloc] init]; 

    NSString *fileName = [[NSString alloc] init]; 

    for(int i=0; i&lt;= imagesPath.count -1 ; i++) 
    {
        fileName = [[imagesPath objectAtIndex:i] lastPathComponent];
        CCSprite *sprite = [CCSprite spriteWithFile:fileName];

        sprite.userData = [[fileName stringByDeletingPathExtension] uppercaseString];   

        [alphabets addObject:sprite]; 
    }

    // release fileName 
    [fileName release]; 
    fileName = nil; 

    [imagesPath release]; // this causes the application to crash with EXC_BAD_ACCESS
//  imagesPath = nil; 
</code></pre>

<p>}</p>

<p><strong>UPDATE 1:</strong></p>

<p>So, the problem was that although I was responsible for releasing the imagesPath object since I used alloc that soon become irrelevant when pathsForResourcesOfType returned an autorelease object. 
This means I should not release the imagesPath object manually. </p>

<p>The following line should be used: </p>

<pre><code>NSArray *imagesPath = [bundle pathsForResourcesOfType:@"png" inDirectory:@"Images"];
</code></pre>

<p><strong>UPDATE 2:</strong> </p>

<p>Another question which is related to this post. In the following code I initialize a new NSMutableArray manually. </p>

<pre><code>alphabets = [[NSMutableArray alloc] init]; 
</code></pre>

<p>Later I insert CCSprite (Cocos2d objects) into alphabets array. CCSprite are autorelease objects. Do I still have to release alphabets manually? Since, after some time all objects are released and memory will be returned but then what will be left inside alphabets NSMutable array? </p>
