在mrc情况下用Build And Analyze分析常见提示的总结

46 篇文章 0 订阅
12 篇文章 0 订阅

之前做了一个图片的webp格式,后来发现有内存泄露,在此特别找了2篇文章


1,Incorrect decrement of the reference count of an object that is not owned at this point by the caller

Java代码   收藏代码
  1. AttrTable = [[AttrTable node] initAttrTable];  

 

其中node已经创建并初始化了,不需要再调用initAttrTable。如果要调用initAttrTable需改为

Java代码   收藏代码
  1. [[[AttrTable alloc] initAttrTable] autorelease]  

 

这种问题一般就是变量申请了内存并初始化了,但没有使用此变量,接着将此变量又重新赋值。如下:

Java代码   收藏代码
  1. NSString *imageString = [[NSString alloc] init];  
  2. imageString = @"HResout";  

 

2,Value stored to 'isHD' is never read

变量isHD没有使用


3,Potential leak of an object allocated on line 226 and stored into 'smallclassname'

潜在的内存泄露点

Java代码   收藏代码
  1. NSString *smallclassname = [[NSString alloc] initWithString:[NSString stringWithFormat: @"%d",m_NpcClass]];  

 

创建变量的时候尽量使用静态创建,因为静态方法都添加了anturelease,若使用alloc,init时后面最好加上autorelease


4,Pass-by-value argument in function call is undefined

Java代码   收藏代码
  1. CGFloat x,y;  
  2. CGFloat w,h;  
  3.   
  4. w = [backSprite boundingBox].size.width;  
  5. h = [backSprite boundingBox].size.height;  
  6.   
  7. myRect = CGRectMake(x, y,w ,h );  

 


使用方法CGRectMake时,变量要初始化。代码里的x,y没有赋值。


5,Receiver in message expression is a garbage value

Java代码   收藏代码
  1. UIColor* tempCol;  
  2.   
  3. if (level==4) {  
  4.     tempCol= [[UIColor alloc] initWithRed:0.39f green:0.82f blue:0.32f alpha:1.0f];  
  5. }else if (level==5) {  
  6.     tempCol= [[UIColor alloc] initWithRed:0.61f green:0.68f blue:0.83f alpha:1.0f];  
  7. }else if (level==6) {  
  8.     tempCol= [[UIColor alloc] initWithRed:0.90f green:0.68f blue:0.99f alpha:1.0f];  
  9. }else if (level==7) {  
  10.     tempCol= [[UIColor alloc] initWithRed:0.68f green:0.97f blue:0.99f alpha:1.0f];  
  11. }  
  12.   
  13. return [tempCol autorelease];  

 
被赋值的是个要回收的变量


6,Assigned value is garbage or undefined

Java代码   收藏代码
  1. Icon *leftTemp,*centerTemp,*rightTemp;  
  2. if(isHD)  
  3. {  
  4.     leftTemp = cell;  
  5. }  
  6. iconLeft = leftTemp;  
  7. iconCenter = centerTemp;  
  8. iconRight = rightTemp;  

 

变量没有初始化就赋值给其他变量时会出现这个提示。即使有条件语句也会有提示。



-------------------------------------------------------------------------------

Incorrect decrement of the reference count of an object that is not owned at this point by the caller1

第一种情况

这种问题一般就是变量申请了内存并初始化了,但没有使用此变量,接着将此变量又重新赋值。如下:

NSString *imageString = [[NSString alloc] init];  

imageString = @"HResout";  

 第二种情况

测出的问题提示是 Incorrect decrement of the reference count of an object that is not owned at this point by the caller

问题出现在这一行[self.tableView initWithFrame:self.view.bounds style:UITableViewStyleGrouped];

本人的这个类是继承UITableViewController的,所以它应该会有个成员是tableView的,我想初始化它风格的样式,但是这里出现了这个问题,原因应该是没有创建就初始化了,后来改成这个:

self.tableView =[[[UITableView alloc ]initWithFrame:self.view.boundsstyle:UITableViewStyleGrouped] autorelease]; 

第三种情况

    LoginViewController *loginViewController = [[LoginViewController allocinitwithLoginUrl: loginUrl];

    CustomNavigationController *customNavigationController = [[CustomNavigationController alloc]initWithRootViewController: loginViewController];

    customNavigationController.navigationBar.tintColor = NavgaitonBar_Color;

    [self.navigationController presentModalViewController: customNavigationController animatedYES];

    [loginViewController release];

    [customNavigationController release];

红色为提示内存泄露的地方 

只要把    LoginViewController *loginViewController = [[LoginViewController allocinitwithLoginUrl: loginUrl];

修改为     LoginViewController *loginViewController = [[LoginViewController allocinitWithLoginUrl: loginUrl];

就可以解决内存泄露(就一大小写的差别)

原文地址: 项目使用Build And Analyze分析常见提示  Incorrect decrement of the reference count of an object that is not owned at this point by the caller

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值