[NSMutableArray release] crashes ?????

Discussion in 'iOS Programming' started by sanniv, Apr 22, 2009.

  1. sanniv macrumors newbie

    Apr 22, 2009
    Hello Guys,

    I am stuck in crashes. I m doing following thing in a function

    NSMutableArray *myMutableArray=[[NSMutableArray alloc] initWithCapacity:0]];

    for (int i=0;i<10;i++)
    [myMutableArray addObject:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:mad:"img000%d.png",(start+i+1)] ofType:nil]]];


    [myMutableArray removeAllObjects];

    //[myMutableArray release];

    I have around 50 images and I load only 10 at a time for a purpose, I am controlling this by "start" variable which contains the initial point. And I want to free previous loaded images while loading new ones.

    But when I uncomment the release method My program crashes..
    And if I do not release, my memory is not being freed, as I checked in Instruments, although there is not leak in Leaks but still object allocation goes on and on with overall system memory of 100 MB. And because of this I get Low Memory Warning in program when I test in the device. I don't know what is the problem here. Please let me know if anyone has resolution.

    Thanks in advance.

  2. BlackWolf macrumors regular

    Apr 9, 2009
    do you get any kind of helpful output in the console? like "trying to release already released object" or something?

    try to take out the "removeAllObjects" line, it's unnecessary anyway.

    But to be honest it should work even with that line in, so I think your problem is outside of the code you posted.
  3. sanniv thread starter macrumors newbie

    Apr 22, 2009
    No the problem is in this code only, thats I m sure..
    because Crash occurs only when I uncomment the release method and if I comment the release method program works fine but it doesn't free the memory of previously loaded images and thats why I get Low Memory warning after playing some time...
    So need some suggestions.

  4. kalimba macrumors regular

    Jun 10, 2008
    There doesn't appear to be anything about the code you posted that would in and of itself cause a crash. I'm guessing that your crash is happening somewhere else outside of this code, and it's happening because you're accessing an array which you've released.

    Have you stepped through the code in the debugger to determine precisely where the crash is occurring?
  5. sanniv thread starter macrumors newbie

    Apr 22, 2009

Share This Page