0

これが私の質問です。強力なプロパティを手動で nil に設定して解放する必要がありますか?

mytest.h ファイル内

@property(nonatomic,strong) IBOutlet UIView *myView;
@property(nonatomic,weak)   IBOutlet UILabel *myLabel;
@property(nonatomic,strong) MyObject *myObject;
@property(nonatomic,strong) NSArray  *theArray;

1)iOS5で正しいのはどれ? 関数 A? または機能B?または機能C?

//function A
-(void)viewDidUnLoad{
 [super viewDidUnLoad];
 self.myView=nil; //strong property
 //I do not need to  self.myLabel=nil, because it is weak property
 self.myObject=nil;//strong property
 self.theArray=nil;//strong property
}

//function B
-(void)viewDidUnLoad{
 [super viewDidUnLoad];
 self.myView=nil; //strong property
 //I do not need to  self.myLabel=nil, because it is weak property
 //self.myObject=nil;//strong property ,but ARC will release it in dealloc
 //self.theArray=nil;//strong property ,but ARC will release it in dealloc
}

//function C
-(void)viewDidUnLoad{
[super viewDidUnLoad];
//do nothing here
//ARC will release it in dealloc
}

2) iOS6 では viewDidUnLoad は非推奨であり、ドキュメントには IBOulet プロパティを気にしないようにと書かれています。

//function A
- (void)didReceiveMemoryWarning
{
 [super didReceiveMemoryWarning];
 //self.myView=nil;  //strong property ,but ios6 document tells me not to care IBOutlet
 //self.myObject=nil;//strong property ,but ARC will release it in dealloc
 //self.theArray=nil;//strong property ,but ARC will release it in dealloc
}

//function B
- (void)didReceiveMemoryWarning
{
 [super didReceiveMemoryWarning];
 //self.myView=nil;  //strong property ,but ios6 document tells me not to care IBOutlet
 self.myObject=nil;//strong property 
 self.theArray=nil;//strong property 
}

どなたか詳しい方、ご回答お願いします

ところで、コンパイラがリリースを追加した後、ARC が私のファイルをスキャンし、自動的に「リリース」を下に追加すると思いますか (実際には ARC にリリースは表示されません)。

-(void)dealloc{
  [self.myView release];
  [self.myObject release];
  [self.theArray release];
  [super dealloc];
}
4

2 に答える 2

0
于 2013-01-26T23:28:51.250 に答える
0

apple_eater、

iOS v5 & v6 の ARC では、メイン ビューがサブビューを保持するため、 IBOutlets を作成する必要がありますweak。他のリソースを解放する必要がない限り、-deallocARC の下では安全に無視できます。実装しないでください。

質問 1: IBOutlets が弱い iOS 5 では、関数 C を使用します。 質問 2: IBOutlets が弱い iOS 6 では、関数 A を使用します。

最後の質問: あなたの-deallocメソッドはコンパイラによって拒否されます。削除するだけです。

アンドリュー

于 2012-10-26T12:59:43.903 に答える