小编DrE*_*tro的帖子

如果我将指针设置为nil,自动引用计数是否释放对象?

如果我将指针设置为nil或将指针指定给另一个对象,自动引用计数是否释放对象?

例如做类似的事情:

//in .h file

@interface CustomView : UIView
{
   UIView *currentView;
}


// in .m file:

-(void)createView1
{
   currentView = [[UIView alloc] init];
   [self addSubview:currentView];
}

-(void)createView2
{
   [currentView removeFromSuperview];

   // does the former view get released by arc
   // or does this leak?
   currentView = [[UIView alloc] init];
   [self addSubview:currentView];
}
Run Code Online (Sandbox Code Playgroud)

如果此代码泄漏,我将如何正确声明*currentView?或者我如何让ARC"释放"当前视图?谢谢!

cocoa-touch ios automatic-ref-counting

4
推荐指数
1
解决办法
4368
查看次数

标签 统计

automatic-ref-counting ×1

cocoa-touch ×1

ios ×1