objective-c – AFHTTPSessionManager无法解除分配
更新
在将此问题作为问题发布到AFNetworking回购后,事实证明这实际上是我的使用问题.根据我的问题回复:
所以,长话短说:如果你以下面描述的方式使用AHTTPSessionManager,请确保调用invalidateSessionCancelingTasks:以确保会话最终确定并释放其委托 原始问题 我有一个名为GTAPIClient的子类AFHTTPSessionManager,我用它连接到我的REST API.我意识到文档声明要用作单例,但在某些情况下我需要编写一个新实例.但是,似乎每当我这样做时,对象永远不会被释放.目前,GTAPIClient在解除分配时除了NSLog本身之外什么都不做. GTAPIClient.m @implementation GTAPIClient - (void)dealloc { NSLog(@"Dealloc: %@",self); } @end GTViewController.m #import "GTBaseEntityViewController.h" //Models #import "GTBaseEntity.h" //Clients #import "GTAPIClient.h" @interface GTBaseEntityViewController () @property (nonatomic,weak) GTAPIClient *client; @property (nonatomic,weak) GTBaseEntity *weakEntity; @end @implementation GTBaseEntityViewController - (IBAction)makeClient:(id)sender { self.client = [[GTAPIClient alloc] init]; NSLog(@"I just made an API client %@",self.client); //Another random object assigned to a similar property,just to see what happens. self.weakEntity = [[GTBaseEntity alloc] init]; NSLog(@"I just made a random object %@",self.weakEntity); } - (IBAction)checkClient:(id)sender { NSLog(@"Client: %@",self.client); NSLog(@"Entity: %@",self.weakEntity); } @end NSLog输出 Fire makeClient: //It seems to me that both NSLog's should return (null) as they are assigning to a weak property 2014-06-22 16:41:39.143 I just made an API client <GTAPIClient: 0x10b913680,baseURL: (null),session: <__NSCFURLSession: 0x10b915010>,operationQueue: <NSOperationQueue: 0x10b9148a0>{name = 'NSOperationQueue 0x10b9148a0'}> 2014-06-22 16:41:39.144 I just made a random object (null) Fire checkClient //Again,both NSLog's should return null for the two objects. However...client is still around. Also,it's overridden dealloc method never fired. 2014-06-22 16:44:43.722 Client: <GTAPIClient: 0x10b913680,operationQueue: <NSOperationQueue: 0x10b9148a0>{name = 'NSOperationQueue 0x10b9148a0'}> 2014-06-22 16:44:43.723 Entity: (null) 作为参考,我正在使用AFNetworking的v2.3.1.编译器警告我,将保留对象分配给weak属性将在赋值后释放 – 这是正确的,并且与我的随机对象一起运行.应用程序中没有其他任何内容.没有其他视图控制器,GTAPIClient上没有其他方法,所有单例功能都被删除.对我在这里做错了什么的想法? 解决方法
复制场景并通过Instruments运行它表明AFURLSessionManagers由它们创建的NSURLSession保留,因为AFURLSessionManager充当每个创建的NSURLSession的委托.这会创建一个保留周期,因此无法释放AFHTTPSessionManager.无论这是一个库中的错误还是根本没有错误,我都不确定.您可能希望在AFNetworking GitHub页面(
https://github.com/AFNetworking/AFNetworking)上报告它.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- c# – 为什么System.Reflection.IntrospectionExtensions.G
- 使用mongofiles操作GridFS
- c# – MVC 6 Controller中的ControllerContext和ViewEngine
- cocos2dx 3.2下利用裁剪节点实现跑马灯滚动效果
- Swift开篇014->自动引用计数(Automatic Reference Counting
- ruby-on-rails – Delayed_job:任何调用都有未定义的方法错
- C和覆盖问题
- c – std :: list iterator:获取下一个元素
- C#连接Oracle数据库使用Oracle.ManagedDataAccess.dll
- webpack+react问题汇总