2013-03-06 62 views
0

我是新來的iOS開發,當我使用下面的代碼保留計數達到3和應用程序將崩潰,減少保留計數當啓用ARC模式

AsyncronousUIImage *image=[[AsyncronousUIImage alloc] init]; 
     [image loadImageFromURL:imageURL inImageView:templateView]; 
     image.delegate=self; 
     [templateScroll addSubview:templateView]; 

enter image description here

我有ARC啓用模式,我正在使用xcode 4.6。

得到的錯誤:

的malloc:*錯誤對象0xa293dd0:被釋放的指針沒有被分配 *設置malloc_error_break斷點調試

知道的任何幫助。

回答

0

如果您使用的是ARC,那麼image將在離開當前函數的範圍後發佈。它看起來像你正在使用該變量的異步方法。所以,在異步代碼接收數據並嘗試設置它時,圖像被釋放。

當使用ARC時,您需要確保您保留代碼其他部分所需的變量,或者至少將它們傳遞給其他將保留它們的對象。

+0

你可以給我發送相關的鏈接或示例代碼,我是新的iOS開發我無法正確理解你。 – Kunal 2013-03-07 12:27:06

+0

@Kunal Sure - 這是[ARC發佈說明](http://developer.apple.com/library/ios/#releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html) – Abizern 2013-03-07 12:30:26