我一直在考虑让我的代码少一些车。清理时,其他程序员的代码,我想知道如果我在我的假设是正确的我见过很多次,在多线程环境中的呼叫是不是安全:财产分配紧随着autorelease
self.prop1 = [[[SomeClass alloc] init] autorelease];
我的想法是,如果申请前用另一个线程干预并释放prop1,然后在下一次runLoop时,如果prop1没有被另一个线程设置为nil,init'd指针可能会再次被释放。
Timeline:
*-----------------**-----------*
| | |
| | Thread 1 autoreleases prop1 when done with function
| |
| Thread 2 releases prop1
|
Thread 1 calls the above code and doesn't finish the function
我希望这对某人有意义,他们可以澄清或减轻我的担忧。
“自动释放”实际上并没有释放对象,它只是告诉引用计数系统在稍后的某个时间点减少该对象的引用计数。 – JAB