delegate property assign problem, RestKit RKRequest
property "assign" and "retain" for delegate
I know use 'assign' is better, but I have in case that use retain is 开发者_JS百科better.
I call web service by making RKRequest object.
RKRequest *request = [[RKClient sharedClient] get:urlString delegate:self];
request object itself is retained and managed by singleton request queue, so I don't care about request object and I concern about delegate methods only.
there's methods handle request results.
These codes are in UIViewController, and view controller itself is delegate.
If view controller is become dealloc during request is processing, RKRequest call delegate that is dead pointer and program crashes.
so I have to retain RKRequest and assign nil to delegate when view controller is dealloc.
furthermore, I have to release RKRequest when request is succeeded or failed.
but I don't think if RKRequest have delegate pointer as 'retain' pointer, how can I manage these objects BEAUTIFULLY?
All that's needed is to add the following call to your controller (RKRequestDelegate) dealloc method:
[[RKRequestQueue sharedQueue] cancelRequestsWithDelegate:self];
精彩评论