开发者

How do I release an UIImageView allocated like this?

I've allocated a UIImageView inside the setBackground method of my tableview cell like this:

 [cell setBackgroundView:[[UIImageView alloc]initWithImage:rowBackground]];

When i run Analyse in XCode 4 it highlights this 开发者_开发百科line as a possible memory leak. How do i release this UIImageView as Ive not got a pointer to reference from a release call?


You can either allocate it differently (i.e. store it in an ivar and release that), or call autorelease on it, like this:

[cell setBackgroundView:[[[UIImageView alloc]initWithImage:rowBackground] autorelease]];


Send it an autorelease message:

[cell setBackgroundView:[[[UIImageView alloc]initWithImage:rowBackground] autorelease]];

With an autorelease message you declare that you don't want to own the object beyond the scope in which you sent the message.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜