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

本文分析了三种典型的Objective-C内存泄漏场景,包括未使用的变量重新赋值、未创建即初始化的对象及错误的消息发送方式,并提供了相应的解决方案。

第一种情况

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

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];

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

转载于:https://www.cnblogs.com/ygm900/archive/2013/02/04/2891852.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值