ios - Memory leaks with "weak" and "strong" attributes -
using lrresty api calls on 1 of project work on. have noticed project leaks memory lot, have been given work fix leakage , improve stability of current application.
the following scenario: entire project under arc, lrresty non-arc. view controller initialises "customservice" object passes self delegate. customservice object calls lrresty client handles request , returns response. customservice has private property request attribute "weak".
the problem is: when run instruments (either on iphone or simulator) leaks detected, in both cases property request attribute "weak" , "strong". request (lrrestyrequest) weak (in case customservice dealloc gets called) otherwise customservice gets caught in retain cycle , dealloc not called. attribute "weak" leak "malloc" , can't identify source, if change attribute "strong" "instruments" shows me leaks @ initwithdelegate:self , [customservice serviceschedulerequest], , dealloc of customservice never called.
how can make code leak free? spent hours , have no clue. possible lrresty framework in charge of memory issue? has experience working framework?
myviewcontroller
customservice *customservice = [[customservice alloc] initwithdelegate:self]; [customservice serviceschedulerequest];
customservice.h
@protocol customservicedelegate; @interface customservice : service <lrrestyclientresponsedelegate> @property (nonatomic, weak) id<customservicedelegate> delegate; - (id) initwithdelegate:(id)adelegate; - (void)serviceschedulerequest; @end @protocol customservicedelegate <nsobject> @optional - (void) serviceschedulerequestdidstart; - (void) serviceschedulerequestdidendwithsuccessjson:(id) json; - (void) serviceschedulerequestdidendwithsuccess:(bool) status; - (void) serviceschedulerequestdidendwitherror:(nserror *)error; @end
customservice.m
@interface customservice () @property (nonatomic, weak) lrrestyrequest *request; @end @implementation customservice @synthesize delegate=_delegate; - (id) initwithdelegate:(id)adelegate { self = [super init]; if (self) { _delegate = adelegate; } return self; } - (void)serviceschedulerequest { nsmutabledictionary* parameters = [self getparams]; self.private_request = [[lrresty client] post:@"http://mylink.com/apicall" payload:parameters delegate:self]; } - (nsmutabledictionary*) getparams { nsmutabledictionary* parameters = [super getparams]; return parameters; } - (void)restclient:(lrrestyclient *)client receivedresponse:(lrrestyresponse *)response { [self.delegate callsomemethod]; // something... } - (void) dealloc { nslog(@"\n\n\n\n dealloc gets called \n\n\n\n"); } @end
stack trace in case if gives clue
0 libsystem_c.dylib realloc 1 foundation _nsmutabledatagrowbytes 2 foundation -[nsconcretemutabledata appendbytes:length:] 3 foundation -[nsconcretemutabledata appenddata:] 4 myapp -[lrurlrequestoperation connection:didreceivedata:] /users/admin/.jenkins/jobs/lrresty nightly builds/workspace/classes/lrurlrequestoperation.m:107 5 myapp -[lrrestyrequest connection:didreceivedata:] /users/admin/.jenkins/jobs/lrresty nightly builds/workspace/classes/lrrestyrequest.m:177 6 foundation ___nsurlconnectiondidreceivedata_block_invoke_0 7 foundation __65-[nsurlconnectioninternal _withconnectionanddelegate:onlyactive:]_block_invoke_0 8 foundation -[nsurlconnectioninternalconnection invokefordelegate:] 9 foundation -[nsurlconnectioninternal _withconnectionanddelegate:onlyactive:] 10 foundation -[nsurlconnectioninternal _withactiveconnectionanddelegate:] 11 foundation _nsurlconnectiondidreceivedata 12 cfnetwork ___delegate_cachetrifecta_block_invoke_0 13 cfnetwork ___withdelegateasync_block_invoke_0 14 cfnetwork ___performasync_block_invoke_068 15 corefoundation cfarrayapplyfunction 16 cfnetwork runloopblockcontext::perform() 17 cfnetwork non-virtual thunk runloopblockcontext::multiplexerclientperform() 18 cfnetwork multiplexersource::perform() 19 corefoundation __cfrunloop_is_calling_out_to_a_source0_perform_function__ 20 corefoundation __cfrunloopdosources0 21 corefoundation __cfrunlooprun 22 corefoundation cfrunlooprunspecific 23 corefoundation cfrunloopruninmode 24 foundation -[nsrunloop(nsrunloop) runmode:beforedate:] 25 foundation -[nsrunloop(nsrunloop) run] 26 myapp -[lrurlrequestoperation start] /users/admin/.jenkins/jobs/lrresty nightly builds/workspace/classes/lrurlrequestoperation.m:63 27 myapp -[lrrestyrequest start] /users/admin/.jenkins/jobs/lrresty nightly builds/workspace/classes/lrrestyrequest.m:136 28 foundation __block_global_6 29 libdispatch.dylib _dispatch_call_block_and_release 30 libdispatch.dylib _dispatch_client_callout 31 libdispatch.dylib _dispatch_root_queue_drain 32 libdispatch.dylib _dispatch_worker_thread2 33 libsystem_c.dylib _pthread_wqthread 34 libsystem_c.dylib start_wqthread
Comments
Post a Comment