我有这样的测试代码
- (void)viewDidLoad
{
[super viewDidLoad];
NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(test) object:nil];
[thread start];
}
-(void)test
{
MyClass *my = [[[MyClass alloc] init] autorelease];
NSLog(@"%@",[my description]);
}
Run Code Online (Sandbox Code Playgroud)
我没有为自己的线程创建任何自动释放池,但是当线程退出时,对象"我的"只是dealloc.why?
即使我改变我的测试代码如下
- (void)viewDidLoad
{
[super viewDidLoad];
NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(test) object:nil];
[thread start];
}
-(void)test
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
MyClass *my = [[[MyClass alloc] init] autorelease];
NSLog(@"%@",[my description]);
}
Run Code Online (Sandbox Code Playgroud)
我创建了自己的autoreleasepool但在线程退出时不会将其耗尽.无论如何,对象"我的"仍然可以dealloc.为什么?
我使用Xcode5而不使用ARC