alllllllll 2013-06-21 02:41 采纳率: 0%
浏览 2053
已采纳

iphone-应用报错incorrect decrement

创建NSString属性,并且合成属性,在viewDidLoad中对属性进行初始化。

问题:使用 [self.fName release],静态分析其显示错误
'Incorrect decrement of the reference count of an object that is not owned at this point by the caller'.

相关代码:

@interface ViewController : UIViewController
@property(nonatomic,retain)NSString *fName;
@end
@implementation ViewController
@synthesize fName;
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.fName =@"Hello";
    [self.fName release];//Analyzer showgin error here.
}
---------
------
end
  • 写回答

1条回答 默认 最新

  • ReyZhang 移动开发领域新星创作者 2013-06-21 03:30
    关注

    对于控制器中的引用类型的释放,我们通常会把它放到- (void)dealloc -(void)viewDidUnLoad 中来处理,而不是在使用的过程中。在使用的过程中去释放对象可能导致其它地方对该对象的引用无效,致使在访问相关对象时导致程序崩溃。 常用的做法是

    -(void)viewDidUnLoad {
        self.fName=nil;
        [super viewDidUnLoad];
    }
    
    -(void)dealloc {
      [_fName release];
      [super dealloc];
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?