Objective-C的:内存泄漏或不带自动释放多种分配?
-
25-09-2019 - |
题
如果我做以下的事情,这样会令内存泄漏?
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
解决方案
没有,有一个在您发布的代码没有泄漏。 当自动释放池冲洗所有对象将被自动释放,不管可变保持它们的指针被改变或没有。
不隶属于 StackOverflow