[英]How do I release an UIImageView allocated like this?
我在tableview單元格的setBackground方法中分配了一個UIImageView,如下所示:
[cell setBackgroundView:[[UIImageView alloc]initWithImage:rowBackground]];
當我在XCode 4中運行Analyze時,它會將此行突出顯示為可能的內存泄漏。 我如何發布這個UIImageView,因為我沒有指向發布調用的引用?
發送自動回復消息:
[cell setBackgroundView:[[[UIImageView alloc]initWithImage:rowBackground] autorelease]];
使用自動釋放消息,您聲明您不希望擁有超出發送消息范圍的對象。
您可以以不同方式分配它(即將其存儲在ivar中並釋放它),或者在其上調用autorelease
,如下所示:
[cell setBackgroundView:[[[UIImageView alloc]initWithImage:rowBackground] autorelease]];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.