ios - Block / Completion handler memory leak -


i'm trying figure out why following code retaining memory 'dictionarywithdata' variable. can tell me best way send objects through completion handler, , how make sure object correctly released afterwards?

// convert json dict nserror *error = nil; nsdictionary *dictionarywithdata = [nsjsonserialization jsonobjectwithdata:((dataurlconnection *)connection).data options:nsjsonreadingallowfragments error:&error]; //dataconnection.data = nil;  dispatch_async(dispatch_get_main_queue(), ^{  if (((dataurlconnection *)connection).completion)      ((dataurlconnection *)connection).completion(yes, dictionarywithdata); }^; 

i release connection using following:

[connection cancel]; ((dataurlconnection *)connection).data = nil; ((dataurlconnection *)connection).completion = nil; connection = nil; 

however, getting 803 leaks on dictionarywithdata object when profiling it. noticed if comment out calling functions code:

...^(bool successful, id object) {  //[[coredatahandler coredatahandler] createnewentityoftype:@"ticketentity" withdictionary:object];  //[[coredatahandler coredatahandler] savecontext]; } 

then memory no longer held on too. createnewentityoftype function follows:

- (id)createnewentityoftype:(nsstring *)sentity withdictionary:(nsdictionary *)dict {      id entity = [nsentitydescription insertnewobjectforentityforname:sentity inmanagedobjectcontext:context];       if ([entity iskindofclass:[ticketentity class]])      {           [entity setnid:dict[@"id"]];      }  return entity; } 

so maps dictionary parameters relevant entity type (above simplified version). returns entity incase calling function needs it. thing uses reference original dictionarywithdata object '[entity setnid:dict[@"id"]];'. stop original dictionary being released?

can let me know if should using weak reference somewhere, or copying original dictionary when passing functions / completion handlers?


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -