2015年1月16日 星期五

使用Instrument找出被retain無法釋放的instance

使用⌘+I叫出Instrument
選擇allocation
allocation

看右邊的面板,勾選Record reference counts
Record reference counts

然後開始檢測程式,執行那些你懷疑有問題的動作。執行完後在搜尋框輸入你要找的Class名稱。
滑鼠移到在Category那欄的物件名稱後面會有小箭頭,點進去,出現所有instance,再找要研究的instance一樣點小箭頭。
Search

進去之後會出現所有retain跟release的紀錄,上方標籤選unpaired可以列出沒有成對的retain或是release。
選擇懷疑有問題的那一行,在右邊面板選擇第三個頁籤,可以看call stack。
reference count

這次我遇到的問題是KVOController的block retain自己所在的instance,下次要記得unobserve。
還有使用[[FBKVOController alloc] initWithObserver:self retainObserved:NO]才不會retain被觀察的物件。

沒有留言:

張貼留言