I read the Apple doc about the function of @autoreleasepool. It says in a new thread, the programmer should declare a new autorelease pool using the following code in ARC.
@autoreleasepool{
//etc
}
But as my test, I did not add the @autoreleasepool block in my code, it still run well.My code is like below.
[NSThread detachNewThreadSelector:@selector(threadTest) toTarget:self withObject:nil];
- (void)threadTest
{
// @autoreleasepool {
for (int i=0; i<1000000; i++) {
NSNumber *num = [NSNumber numberWithInt:i];
[NSString stringWithFormat:@"%@",num];
}
// }
}
I used the Xcode Leaks instruments to see whether it has any memory leaks, but I did not find any memory leaks. So the result is that "It seems it is not required to declare the @autoreleasepool block in a secondary thread", is my word correct, can someone clarify this?