Possible memory leak #509

Closed
rodowi opened this Issue Sep 12, 2012 · 6 comments

3 participants

@rodowi

I've just done some heapshot analysis with Instruments and it appears that the following method is growing the heap

AFURLConnectionOperation.m 540 (self.responseData)

- (void)connectionDidFinishLoading:(NSURLConnection *)__unused connection {
    self.responseData = [self.outputStream propertyForKey:NSStreamDataWrittenToMemoryStreamKey];

    [self.outputStream close];

    [self finish];

    self.connection = nil;
}

Does anyone have the same issue? When does self.responseData gets deallocated?

@tewha

It's released in AFURLConnectionOperation's dealloc. Is it possible you're retaining it somewhere else? You should be able to see all the places it's retained and released with Instruments.

@mattt

When loading a lot of data, AFNetworking will often make a lot of allocations that may stick around for a while. They look like a leak, but they're just operating on a longer timeline.

@tewha is correct about where that's released. Try running the static analyzer to see if you're perhaps retaining or copying the operation or its responseData property somewhere along the way.

That said, If you can demonstrate a memory leak with a reproducible test case, I'd love to see it. Thanks!

@mattt mattt closed this Sep 12, 2012
@tewha

As I re-learned last night, after identifying a memory leak with Instruments, the best way to find it is to read code and think about what it's doing. Look for where you're using the responseData. It's probably being assigned to something (maybe even through several levels of indirection) which isn't releasing it properly. Just follow it around and think about what it's doing. I bet it'll jump right out.

@rodowi

Thanks guys for the quick response.

I agree that more evidence is needed, I'll have to investigate it further.

By the way, I implemented a AFHTTPClient singleton as in the AFTwitterAPIClient example so there's no retaining of the AFURLConnectionOperation (plus the project has ARC).

@tewha

Any chance you're leaking the responseObject from the success half of setCompletionBlockWithSuccess:failure:? That's the same object.

@rodowi

Don't think so, I'm just getting the root key and that object is never used again.

@crfeliz crfeliz referenced this issue in RestKit/RestKit Feb 8, 2014
Open

Abandoned memory #1786

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment