I have the following code in a method of my app:
NSArray *array = [NSArray arrayWithObjects:@"1", @"2", @"3", nil];
[someObject someMethodThatTakesAnArray:array];
I know that the arrayWithObjects method returns an autoreleased array. Does this mean I should retain it directly after it’s made? Is it guaranteed that the autorelease pool won’t be drained before I pass the array along to someMethodThatTakesAnArray? What about when it gets into the method? If I never retain it, the array could potentially disappear while I’m using it inside the someMethodThatTakesAnArray, couldn’t it?
The autorelease pool isn’t drained until the next pass of the event loop of the thread it serves. That’s not going to happen as long as you’re working inside your current method. So yes, array is safe for someMethodThatTakesAnArray: to use; you needn’t worry.
Event management: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/EventOverview/Introduction/Introduction.html
Memory management: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/MemoryMgmt.html