After using NSURLConnection, I'm seeing some leak issues in my code that I can't quite figure out. The specific call is:
NSURLConnection * theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:handler];
This code is run several times and is balanced by a call to release. After a few hours I'm seeing a huge number of the following reported by the leaks utility:
Leak: 0x05f75e70 size=240 instance of 'NSCFDictionary' 0x00402a70 0x00010397 0x00000003 0x00000011 .@*p............ 0x00000017 0xa1b1c1d3 0x00000000 0x00000000 ................ 0x00000000 0x05f75e9c 0x05f75ef8 0xa0eef390 ......^...^..... 0xa1b1c1d3 0xa1b1c1d3 0xa0eef2e0 0xa1b1c1d3 ................ 0xa0eef330 0xa1b1c1d3 0xa1b1c1d3 0xa1b1c1d3 ...0............ 0xa1b1c1d3 0xa1b1c1d3 0xa1b1c1d3 0xa1b1c1d3 ................ 0xa1b1c1d3 0xa1b1c1d3 0xa1b1c1d3 0xa1b1c1d3 ................ 0xa1b1c1d3 0xa1b1c1d3 0xa1b1c1d3 0xa1b1c1d3 ................ ... Call stack: [thread 9287c2b3]: | 0x0 | _pthread_body | forkThreadForFunction | +[NSURLConnection(NSURLConnectionInternal) _resourceLoadLoop:] | CFRunLoopRunSpecific | __CFRunLoopRun | __CFRunLoopDoSources0 | _resourceLoaderPerform | -[NSURLConnection(NSURLConnectionInternal) _performOriginLoad] | -[NSConnectionHTTPURLProtocol startOriginLoad] | -[NSConnectionHTTPURLProtocol continueBeginLoadInBackgroundAfterCreatingHTTPRequest] | -[NSConnectionHTTPURLProtocol createStream:] | CFHTTPConnectionCreate | _CFNetConnectionCreate | httpConnectionCreateStreams | CFReadStreamCreateHTTPStream | CFHTTPMessageCreateEmpty | _CFHTTPMessageCreate | __CFDictionaryInit | _CFRuntimeCreateInstance | CFAllocatorAllocate
More interestingly, when I examine [theConnection retainCount] immediately after the previous alloc request, the retain count is set to 2 instead of the expected 1. Consequently I'm also seeing a huge number of reports by leaks that the NSURLConnection object isn't being released.
Is the reported leak familiar to anybody and do they have any idea of the cause? And is there an explanation why NSURLConnection:initWithRequest:delegate is returning an object with a retain count of 2. Is the OS somehow caching requests for reuse?
- Steve
|