i have an app that on the init method , i need to load an array with many backgrounds, and than this array will stay valid during this scene, till i leave it(and release it in dealloc)
in my init i have this :
backgrounds=[ [NSArray alloc] initWithObjects:BACK,BACK1,BACK2,BACK3,BACK4,BACK5,BACK6,BACK7,BACK8,BACK9, nil];
int imageDelta=1;
for (background in backgrounds)
{
background.position=ccp(240*imageDelta,160);
imageDelta=imageDelta+2;
[self addChild:background ];
}
//release backgrounds here ????
now, my question is, can i and should i release backgrounds now ??
i still need this array to be valid during the code .
it seems i didnt really understood arrays .
thanks a lot.
No you shouldn’t release that backgrounds array in the init method because it’s an instance variable. You are correct in saying that it should only release it in dealloc, which is when you have finished with it.
If you release that backgrounds array in you init method you won’t be able to access it again after that because it would be a deallocated instance. I take it that the reason you have the backgrounds array as an instance variable is because you want to access it again?