【问题标题】:Objective-C : memory leak or not with multiple assignation with autorelease?Objective-C:内存泄漏与自动释放的多重分配?
【发布时间】:2011-01-05 17:42:50
【问题描述】:

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

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

【问题讨论】:

    标签: objective-c memory-leaks autorelease assign


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2011-10-16
      • 2011-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-03
      相关资源
      最近更新 更多