Which is right? This:
NSArray* foo = [[NSArray alloc] initWithObjects:@"a", @"b", nil];
[bar performSelectorInBackground:@selector(baz:) withObject:foo];
- (void)baz:(NSArray*)foo {
...
[foo release];
}
Or:
NSArray* foo = [[[NSArray alloc] initWithObjects:@"a", @"b", nil] autorelease];
[bar performSelectorInBackground:@selector(baz:) withObject:foo];
- (void)baz:(NSArray*)foo {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
...
[pool release];
}
I know the first one works, but Clang complains about it, so I wonder if there's a better pattern to use.
I would "just try out" the 2nd one, but with autoreleasing, who knows whether the absence of EXC_BAD_ACCESS
means that you're doing it right or that you just got lucky...
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…