nsstring - Leaks with NSStirng -
nsstring - Leaks with NSStirng -
iam getting memory leaks in below code.
is proper way handle memory?
please right me.
-(void)getholidays { if (idarray!=nil) { [idarray release]; idarray=nil; } idarray=[[nsmutablearray alloc]init]; if (countryarray!=nil) { [countryarray release]; countryarray=nil; } countryarray =[[nsmutablearray alloc] init]; if (holidaynamearray!=nil) { [holidaynamearray release]; holidaynamearray=nil; } holidaynamearray =[[nsmutablearray alloc] init]; if (datearray!=nil) { [datearray release]; datearray=nil; }datearray =[[nsmutablearray alloc] init]; if (dayarray!=nil) { [dayarray release]; dayarray=nil; }dayarray =[[nsmutablearray alloc] init]; if (favoritearray!=nil) { [favoritearray release]; favoritearray=nil; } favoritearray =[[nsmutablearray alloc] init]; nsstring *destinationpath = [self getdestinationpath]; const char *dbpath = [destinationpath utf8string]; sqlite3_stmt *statement; if (sqlite3_open(dbpath, &database) == sqlite_ok) { nsstring *querysql; nsdate *today = [nsdate date]; nsdateformatter* formatter = [[[nsdateformatter alloc] init] autorelease]; [formatter setdateformat:@"mmmm-dd-yyyy"]; nsstring *todaystrng = [formatter stringfromdate:today]; nslog(@"today date %@",todaystrng); querysql=[nsstring stringwithformat:@"select * holiday_table countryname in (select country_name country country_selected =1) order date asc "]; const char *query_stmt = [querysql utf8string]; if (sqlite3_prepare_v2(database, query_stmt, -1, &statement, null) == sqlite_ok) { nslog(@"success"); while (sqlite3_step(statement) == sqlite_row) { nsstring *idstringfromdb=[[nsstring alloc] initwithutf8string:(const char *) sqlite3_column_text(statement, 0)]; nsstring *countrynamestringfromdb=[[nsstring alloc] initwithutf8string:(const char *) sqlite3_column_text(statement, 1)]; nsstring *holidaynamestringfromdb=[[nsstring alloc] initwithutf8string:(const char *) sqlite3_column_text(statement, 2)]; nsstring *datestringfromdb=[[nsstring alloc] initwithutf8string:(const char *) sqlite3_column_text(statement, 3)]; //below line gets leaking nsstring *daystringfromdb=[[nsstring alloc] initwithutf8string:(const char *) sqlite3_column_text(statement, 4)]; //belowline gets leaking nsstring *favoritestringfromdb=[[nsstring alloc] initwithutf8string:(const char *) sqlite3_column_text(statement, 5)]; [idarray addobject:idstringfromdb]; [idstringfromdb release]; idstringfromdb=nil; [countryarray addobject:countrynamestringfromdb]; [countrynamestringfromdb release]; countrynamestringfromdb=nil; [holidaynamearray addobject:holidaynamestringfromdb]; [holidaynamestringfromdb release]; holidaynamestringfromdb=nil; [datearray addobject:datestringfromdb]; [datestringfromdb release]; datestringfromdb=nil; [dayarray addobject:daystringfromdb]; [daystringfromdb release]; daystringfromdb=nil; [favoritearray addobject:favoritestringfromdb]; [favoritestringfromdb release]; favoritestringfromdb=nil; } } sqlite3_finalize(statement); } sqlite3_close(database); }
nsstring
Comments
Post a Comment