iphone - Is something leaking from the following code -


my app seems crashing on line (console not give exact idea). program received error signal. please let me know if there leak or other issue in following code...i releasing properties in dealloc method;

- (void)viewwillappear:(bool)animated {     [super viewwillappear:animated];     self.curr_rep_date = [[nsmutablestring alloc] init];     retrievedarray = [[shared sharedmanager] books];      nsstring *urlstr_replist_curr = [[[nsstring alloc] initwithformat:@"http://xyz.com", [[retrievedarray objectatindex:selectedindex] booknumber]] autorelease];     nsdata* xmldata_replist = [nsdata datawithcontentsofurl:[nsurl urlwithstring:urlstr_replist_curr] ];     replist_rptdt_dict = (nsmutabledictionary *)performxmlxpathquery(xmldata_replist, @"//xx/yy[@rd]");      replist_rpttype_dict = (nsmutabledictionary *)performxmlxpathquery(xmldata_replist, @"//xx/yy[@rt='a']");       nsdateformatter *dateformatter = [[[nsdateformatter alloc] init]  autorelease];     [dateformatter setdateformat:@"yyyy"];     nsdate *date = [nsdate date];     int tmpcurryearint = [[dateformatter stringfromdate:date] intvalue];      nsstring *tmprptdt;     nsmutablearray *temparrdt;      (nsdictionary *period in replist_rpttype_dict){         (nsdictionary *nodeattributearray in [period objectforkey:@"nodeattributearray"]){             nsstring *tmpattrname = [nodeattributearray objectforkey:@"attributename"];              if ([tmpattrname isequaltostring:@"reportdate"]) {                 tmprptdt = [nodeattributearray objectforkey:@"nodecontent"];                  temparrdt = (nsmutablearray *)[tmprptdt componentsseparatedbystring:@"-"];                 tmpyrval = [[temparrdt lastobject] intvalue];                  if (tmpyrval == tmpcurryearint) {                     self.curr_rep_date = [nsstring stringwithformat:@"%d", tmprptdt];                 }                 else if (tmpyrval == (tmpcurryearint-1)) {                     self.curr_rep_date = (nsmutablestring *)[tmprptdt stringbyreplacingoccurrencesofstring:[nsstring stringwithformat:@"%d",tmpyrval] withstring:[nsstring stringwithformat:@"%d",(tmpcurryearint-1)]];                 }                 else if (tmpyrval == (tmpcurryearint-2)) {                     self.curr_rep_date = (nsmutablestring *)[tmprptdt stringbyreplacingoccurrencesofstring:[nsstring stringwithformat:@"%d",tmpyrval] withstring:[nsstring stringwithformat:@"%d",(tmpcurryearint-2)]];                 }                 else {                     parse_error_str = [nsmutablestring stringwithstring:@"report error"];                 }              }         }     }     nslog(@"tmprptdt %@, curr rep date %@",tmprptdt, self.curr_rep_date);      [urlstr_replist_curr release];      [tableview reloaddata]; } 

in dealloc, releasing;

[parse_error_str release];     [replist_rptdt_dict release];     [replist_rpttype_dict release];     [curr_rep_date release];     [abook release];     [tableview release]; 

if curr_rep_date property declared retain or copy, leak:

self.curr_rep_date = [[nsmutablestring alloc] init]; 

+alloc return instance own, , property going declare ownership (by sending retain array).

you should doing:

self.curr_rep_date = [nsmutablestring string]; 

in addition, doing things like:

temparrdt = (nsmutablearray *)[tmprptdt componentsseparatedbystring:@"-"]; 

or

self.curr_rep_date = (nsmutablestring *)[tmprptdt stringbyreplacingoccurrencesofstring:[nsstring stringwithformat:@"%d",tmpyrval] withstring:[nsstring stringwithformat:@"%d",(tmpcurryearint-1)]]; 

are totally wrong. casting not change type of object. shuts compiler. -componentsseparatedbystring: return immutable array, if cast nsmutablearray (or else). pay attention return types.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -