开发者

Should this variable release manually?

Memory need to be release for alloc, retain and copy. My q开发者_开发百科uestion is for following situation where I retain the UIImage property, but it was autorelease by the function of imagedNamed. Should I still release following variable?

@property (nonatomic, retain) UIImage *image;
self.image = [UIImage imageNamed:@"image.png"];

Thanks!


In your code you don't use your property but assign autoreleased UIImage object to your iVar directly, so you need

  1. retain your image (or better actually use property) - otherwise your image object will be destroyed when you exit current scope and accessing it in other methods will result in an error. So use:

    self.image = [UIImage imageNamed:@"image.png"];
    
  2. Release your image in dealloc method


Yes you have to release image since you retained it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜