I am attempting to use NSURLConnection to talk to a device that supports HTTP. It works great, but I noticed there are occasional memory leaks when using the Leak instrument. I have a RequestHelper class that has its own secondary thread. The secondary thread is there to parse and process the data when it arrives from the URLConnection. Here is the stack trace I get for the leak:
EDIT: I have also tried removed the secondary thread and created the connection in the main thread with the same results.
Code:
20 libSystem.B.dylib thread_assign_default
19 libSystem.B.dylib _pthread_start
18 Foundation __NSThread__main__
17 Foundation -[NSThread main]
16 Server Control -[RequestHelper backgroundThread:] /.../Server Control/Classes/RequestHelper.m:593
15 CoreFoundation CFRunLoopRunInMode
14 CoreFoundation CFRunLoopRunSpecific
13 CFNetwork MultiplexerSource::_perform(void*)
12 CFNetwork MultiplexerSource::perform()
11 CFNetwork URLConnection::multiplexerClientPerform(RunLoopMultiplexer*)
10 CFNetwork URLConnectionClient::processEvents()
9 CFNetwork URLConnectionClient::ClientConnectionEventQueue::processAllEventsAndConsumePayload(XConnectionEventInfo<XClientEvent, XClientEventParams>*, long)
8 CFNetwork URLConnectionClient::_clientWillSendRequest(_CFURLRequest const*, _CFURLResponse*, URLConnectionClient::ClientConnectionEventQueue*)
7 CFNetwork URLConnectionClient::getRequestForTransmission(_CFURLResponse*, _CFURLRequest const*, __CFError**)
6 CFNetwork URLConnectionLoader::copyProtocolCanonicalRequest()
5 CFNetwork HTTPProtocol::copyCanonicalRequest()
4 CFNetwork HTTPProtocol::_createCanonicalRequest(__CFAllocator const*, _CFURLRequest const*, void const*)
3 CFNetwork HTTPProtocol::_createMutableCanonicalRequest(__CFAllocator const*, _CFURLRequest const*, void const*)
2 CFNetwork createCanonicalURL
1 CoreFoundation CFAllocatorAllocate
0 CoreFoundation __CFAllocatorSystemAllocate
Now, I've been pretty frustrated trying to figure this out, so I created a stripped down, basic version of the URLConnection class with similar methods and the same delegate methods (Basically, just a TCPClient that parses the response and the content). When replacing my version of the URLConnection into RequestHelper class and changing nothing else, I no longer have any leaks. I really don't want to use the stripped down version because I think it's a waste of time to reinvent the wheel.
This is what is on line 593 in the RequestHelper class:
Code:
RequestHelper.m Line 593:
SInt32 result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 10, YES);
Any thoughts?
Thanks,
Matt