views:

27

answers:

2

I have an ivar, keys which is an NSMutableArray containing 50 strings. When my view loads, i am getting a zombie messaged error in Instruments, and it is directing me to this line of code:

for (int row = 0; row < r; row++) {
    for (int column = 0; column < c; column++){
        otherArray[column][row] = [[[keys objectAtIndex:0] retain] autorelease]; 
                                //^ Instruments brings me here
        [keys removeObjectAtIndex:0];
    }
}

I have retained the value to keep it alive so that the remove will not cause a crash, but it still does. I have tried not retaining, and autoreleasing and it still crashes. This method of retaining and autoreleasing works when i have a local variable, but not an ivar...

I need an ivar because i need to access the strings elsewhere.

Thanks

A: 

synthesize it and release and it in your dealloc.

Jesse Naugher
It is synthesized and released already.
joec
then you shouldn't have to autorelease it or retain it, make sure it is initialized, since if Instruments brings you to that line of code, the problem isn't the remove, its the autorelease, retain, or objectAtIndex
Jesse Naugher
I have taken the autorelease/retain out and still it messages a Zombie, i am not sure what i am missing. It is initialised as before the loop, i can print out each item. My flow should be this: loop over the first 20 elements in the array, then remove them. Next time the method is called (new instance of view controller), loop over the next 20, remove them, and so forth...
joec
A: 

Solved -- Memory management problem - keys was not being correctly retained.

joec