RestKit/RestKit — Issue #487: RKObjectLoader, RKRequest, RKResponse aren't released
Author: smclelland
Created: 2011-12-31 09:59:56+00:00
State: open

Looks like neither RKRequest or RKResponse are getting deallocated and there appears to be a retain/release cycle happening if you forcibly release it. RKResponse retains RKRequest and RKRequest retains RKResponse.

RKResponse init retains request: _request = [request retain]; dealloc has [_request release] which can never happen because of the
cross reference. That reference to _request is only needed until all of the delegate calls are finished.

I patched it with this and all is well again:

```objective-c
- (void)dealloc {
// [_request release]; <-- it has already been released
_request = nil;
[_httpURLResponse release];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
RKLogTrace(@"Read response body: %@", [self bodyAsString]);
[_request didFinishLoad:self];
[_request release]; // <-- moved it here
}

- (void)connection:(NSURLConnection *)connection didFailWithError: (NSError *)error {
_failureError = [error retain];
[_request didFailLoadWithError:_failureError];
[_request release]; // <-- moved it here
}

```