![](/img/trans.png)
[英]what are the differences between __strong and strong, __weak and weak?
[英]Is this strong or weak?
假設這種情況:
__weak UIImage *image = [self calculateImage];
// a few lines later...
image = [self calculateImageUsingAnotherProcess];
假設calculateImage
和calculateImageUsingAnotherProcess
返回強引用。
好的,在第一種情況下image
weak
但是第二種情況又如何呢? image
保持weak
嗎?
第二個也將保持弱勢。 聲明后不能更改。
從這種意義上講,您不能返回強有力的參考。 引用所在的容器決定了它是強還是弱。 如果您聲明了一個weak
容器,那么您分配給它的任何引用都將被弱保存。
按照慣例,除了自動釋放池之外, calculateImageUsingAnotherProcess
返回的內容將不歸所有人所有。
因此,盡管是正確的,但並不僅僅是引用“在聲明后不能更改”的強度,而是因為沒有機制允許您嘗試這樣做,因此,您的代碼也沒有這樣的嘗試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.