I have two problems
1) My App works fine on the device the first few times its run. Then it crashes after the First screen pops up(Tab BAr). If i connect the device to my MAC and then run the device app it works(not debug mode).
I Checked the crash Logs, it crashed cos of "EXC_BAD_ACCESS (SIGSEGV)" and Thread0 crashed.The error was NSAutorelease released a deallocated Object.
2) I ran the app using instruments on the simulator. It show a lot of leaks on this function call. Here is a sample code. When i run it using Instruments it shows a leak on the "setObject" line.
//class A- subclass of NSObject
+(NSMutableDictionary *)Hello {
NSMutableDictionary *dctONE = [[NSMutableDictionary alloc]initWithCapacity:0];
NSMutableArray *arrKeys = [[NSMutableArray alloc] initWithCapacity:0];
[arrKeys addObject:@"Object1"];
[arrKeys addObject:@"Object2"];
[dctONE setObject:[NSString stringWithFormat:@"dsfsdf"] forKey:[arrKeys objectAtIndex:0]];
[dctONE setObject:[NSString stringWithFormat:@"dsfsdf"] forKey:[arrKeys objectAtIndex:1]];
[arrKeys release];
return dctONE;
}
/// class B
-(void)some_Function {
NSMutableDictionary * dct = [A Hello]; //all declarations are done
//do stuff with dct
[dct release];
}
WHy does it Leak at "setObject"?? I am releasing everything properly right? Only thing is the [NSString stringWithFormat:] but that is autorelease right??
This is driving me Crazy?
Are the two problems related?? PS: It Doesnt crash on the sim, and strangely doesnt crash even when i connect my device to my MAC and then test it on device(not debugging, directly clicking the app on the device)
EDIT:
-(NSMutableDictionary *) ExecuteDataSet:(NSString *)strQuery
{
NSMutableDictionary *dctResult = [[[NSMutableDictionary alloc] init] autorelease];
// BOOL isSucess = FALSE;
const char *sql = [strQuery UTF8String];
sqlite3_stmt *selectStatement;
//prepare the select statement
int returnValue = sqlite3_prepare_v2(database, sql, -1, &selectStatement, NULL);
if(returnValue == SQLITE_OK)
{
sqlite3_bind_text(selectStatement, 1, sql, -1, SQLITE_TRANSIENT);
//loop all the rows returned by the query.
NSMutableArray *arrColumns = [[NSMutableArray alloc] init];
for (int i=0; i<sqlite3_column_count(selectStatement); i++)
{
const char *st = sqlite3_column_name(selectStatement, i);
[arrColumns addObject:[NSString stringWithCString:st encoding:NSUTF8StringEncoding]];
}
int intRow =1;
while(sqlite3_step(selectStatement) == SQLITE_ROW)
{
NSMutableDictionary *dctRow = [[NSMutableDictionary alloc] init];
for (int i=0; i<sqlite3_column_count(selectStatement); i++)
{
int intValue = 0;
const char *strValue;
switch (sqlite3_column_type(selectStatement,i))
{
case SQLITE_INTEGER:
intValue = (int)sqlite3_column_int(selectStatement, i);
[dctRow setObject:[NSString stringWithFormat:@"%d",intValue] forKey:[arrColumns objectAtIndex:i]];
break;
case SQLITE_TEXT:
strValue = (const char *)sqlite3_column_text(selectStatement, i);
[dctRow setObject:[NSString stringWithCString:strValue encoding:NSUTF8StringEncoding] forKey:[arrColumns objectAtIndex:i]];
break;
default:
strValue = (const char *)sqlite3_column_value(selectStatement, i);
[dctRow setObject:[NSString stringWithCString:strValue encoding:NSUTF8StringEncoding] forKey:[arrColumns objectAtIndex:i]];
break;
}
}
[dctResult setObject:[dctRow retain] forKey:[NSString stringWithFormat:@"Table%d",intRow]];
intRow ++;
[dctRow release];
}
[arrColumns release];
}
return dctResult;
}