Objective-C:内存是否泄漏,多次分配自动释放?

Oli*_*ver 1 memory-leaks objective-c autorelease assign

如果我做了以下事情,这会导致内存泄漏吗?

SomeClass* tmp;
NSDate* thetmpdate;

tmp = [[[SomeClass alloc] init] autorelease];
thetmpdate = [NSDate date];
// Do something long with tmp and date

tmp = [[[SomeClass alloc] init] autorelease];
thetmpdate = [NSDate date];
// Do something long with tmp and date

tmp = [[[SomeClass alloc] init] autorelease];
thetmpdate = [NSDate date];
// Do something long with tmp and date
Run Code Online (Sandbox Code Playgroud)

fil*_*ipe 6

不,您发布的代码没有泄漏.刷新自动释放池时,无论是否更改保持其指针的变量,都将自动释放所有对象.