在我的应用程序中,我正在使用一个库,它直接返回我在 NSMutableArray 中的 sql 查询的结果。当我使用仪器时,它会显示存储结果的数组的内存泄漏。所以库的创建者没有处理 init-正确释放数组。所以有什么方法可以处理我的代码中由库外部数组引起的内存泄漏?代码如下:
-(void)getRecurringDataFromDatabase
{
SafeRelease(_arrTblList);
_arrTblList=[[NSMutableArray alloc]init] ;
NSError *error = nil;
NSString *strQuery = [NSString stringWithFormat:@"select * from wt_transaction as w where w.subcat_id in (select s.subcat_id from subcategory as s where s.subcat_type = 'expense' and IsRepeat = 1)"];
NSMutableArray *arrExpense = [NSMutableArray requestWithSynchronousQuery:strQuery withReturnningError:&error] ;
NSString *strQuery1 = [NSString stringWithFormat:@"select * from wt_transaction as w where w.subcat_id in (select s.subcat_id from subcategory as s where s.subcat_type = 'income' and IsRepeat = 1)"];
NSMutableArray *arrIncome = [NSMutableArray requestWithSynchronousQuery:strQuery1 withReturnningError:&error];
if (error) {
[AppDelegate showAlert:[error description] withTitle:@"Error!"];
}
else{
if ([arrExpense count]>0)
{
[_arrTblList addObject:arrExpense];
}
if ([arrIncome count]>0)
{
[_arrTblList addObject:arrIncome];
}
_reloadCell = YES;
[_tblView reloadData];
}
在这里它显示了 arrIncome 和 arrExpense 的内存泄漏。释放或自动释放这些数组并不能解决内存泄漏。解决这些泄漏的唯一方法是,如果它们可以由库的创建者解决?而且我也遇到了内存泄漏如果
(indexPath.row == 0) {
OverviewViewController *obj1 = [[OverviewViewController alloc] initWithNibName:@"OverviewView" bundle:nil];
[self.navigationController pushViewController:obj1 animated:YES];
[obj1 release];
} this code at line [self.navigationController pushViewController:obj1 animated:YES];
.how to resolve this leak?