Reputation: 865
I am using server client architecture in my application.
I am using NSURLConnection class,now suppose i am sending multiple requests in for loop and using async connection with delegate methods.So my question is after I got response from server do I need to close connection manually and make that object null.
I am asking because on server there is constraint on maximum connections to be made and if that connection limit exceeds I have to restart server and I can not change maximum connection limit.
Upvotes: 3
Views: 797
Reputation: 5858
The proper way to release the connection is to set it to be nil
along with the property used to receive data from the connection:
theConnection = nil;
receivedData = nil;
This is from the URL Session Programming Guide in the section Using NSURLConnection.
Release the connection and the data object by setting the properties (declared elsewhere) to nil. Note that a real-world app usually requires the delegate to manage more than one connection at a time, so these lines would typically be replaced by code to iterate through whatever data structures you are using.
Upvotes: 1
Reputation: 8628
No. It is not needed as NSURLConnection
will close the connection by itself when an error occurs or the data has loaded.
If you wish to monitor what actually happens, I suggest looking at Technical Q&A QA1176. It describes how you can set up an environment to monitor each packet that is sent by an iPhone. Then you can verify the behavior of NSURLConnection
yourself.
Upvotes: 2
Reputation: 949
Please used this..may be helped
[self.connection cancel];
self.connection = nil;
Upvotes: 0