In my application i am using one library that directly returns me the result of sql queries in NSMutableArray.When i am using instrument then it shows me memory leaks for the array in which result is stored.So creater of library has not handled the init-release for the array properly.so there any way that i can handle memory leaks caused by that array outside libary in my code? The code is as below:
-(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];
}
Here it shows memory leaks for arrIncome and arrExpense.and releasing or autoreleasing these arrays does not resolve the memory leaks.Is the only way to resolve these leaks is if they can be solved by creator of library?and also i am getting memory leaks for if
(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?
Whatever library you are using, it seems like it is really poorly designed. Specifically, sticking a category on NSMutableArray (or NSArray) to perform database access is a horrible anti-pattern.
As well, your code has some serious problems; get
should not be used as a prefix, checking error
directly to determine if an error happens is wrong, etc...
Finally, leaks tells you where a leak was allocated, not where the actual leak occurs. If there is an over-retain bug in the library, you should fix that (or replace the library) and not try to hack around it.