IBOutlet造成的內存泄漏

在iphone中,只要控件使用IBOutlet連接 ,則必須release它。無論它是否有

@property(nonatomic,assign),

@property(nonatomic,retain)

屬性。

原因如下:

On Mac OS X, IBOutlets are connected like this:

  1. Look for a method called set<OutletName>:. If it exists call it.
  2. If no method exists, look for an instance variable named <OutletName>, set it without retaining.

On iPhone OS, IBOutlets are connected like this:

  1. call [object setValue:outletValue forKey:@"<OutletName>"]

The behavior of set value for key is to do something like this:

  1. Look for a method called set<OutletName>:. If it exists call it.
  2. If no method exists, look for an instance variable named , set it and retain it.
補充:控件一般不會用assign屬性!!!
所以無論寫沒寫property屬性(retain),均會ratain。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章