We're making calls to an API to get JSON data using AFHTTPRequestOperationManager
.
Currently, we are instantiating a new AFHTTPRequestOperationManager
for each request. We're considering instantiating just a single AFHTTPRequestOperationManager
and reusing it across requests.
What are the trade-offs?
There are several reasons why AFHTTPRequestOperationManager per domain is a handy pattern:
1) You save the resources of creating a new manager for each request which can create significant memory pressure
2) Having just one reference to a manager allows you to easily manage all the network requests in your app. For example, when a user logs out you may want to cancel all requests. With just one manager you can easily access the operation queue and cancel them all at once.
3) Related to #2, having one instance allows you to manage the configuration for all your requests at once. For instance adding authorization headers or configuring custom parsers. These could of course be done before every request but it adds unnecessary complexity.