Update
After publishing this question in the AFNetworking repository, it turns out that this is actually a problem of use on my part. In response to my problem:
NSURLSession saves its delegate (i.e. AFURLSessionManager). Call invalidateSessionCancelingTasks: to ensure completion and release of its delegates.
So, a long story: if you use the AHTTPSessionManager in the manner described below, be sure to call invalidateSessionCancelingTasks: to make sure the sessions end and free the delegate.
Original question
I have subclasses of AFHTTPSessionManager called GTAPIClient that I use to connect to my REST API. I understand that the state of docs is used as a singleton, but there are several cases where I need to create a new instance. However, it seems that whenever I do this, the object is never freed. Currently, GTAPIClient literally does nothing but NSLog itself when released. Here is a sample code demonstrating the behavior
GTAPIClient.m
@implementation GTAPIClient - (void)dealloc { NSLog(@"Dealloc: %@", self); } @end
GTViewController.m
NSLog output
Fire makeClient:
Fire checkClient
//Again, both NSLog should return null for the two objects. However...client is still around. Also, it overridden dealloc method never fired. 2014-06-22 16:44:43.722 Client: <GTAPIClient: 0x10b913680, baseURL: (null), session: <__NSCFURLSession: 0x10b915010>, operationQueue: <NSOperationQueue: 0x10b9148a0>{name = 'NSOperationQueue 0x10b9148a0'}> 2014-06-22 16:44:43.723 Entity: (null)
For reference, I am using v2.3.1 AFNetworking. The compiler warns me that the assignment of the stored weak property object will be released after the assignment - this is correct and will function as expected with my random object. Nothing happens in the application. No other view controllers, no other methods in GTAPIClient , all singleton functions are removed. Any thoughts on what I'm doing wrong here?
memory-management objective-c afnetworking-2
natenash203
source share