【发布时间】:2012-02-07 11:34:32
【问题描述】:
我正在使用NSFileHandle 从套接字读取数据。
这就是我创建filehandle 的方式:
filehandle = [[NSFileHandle alloc] initWithFileDescriptor:sock closeOnDealloc:YES];
我正在这样做:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(readData:) name:nil object:filehandle];
[filehandle readInBackgroundAndNotify];
我注意到,readInBackgroundAndNotify 正在将fileHandle 的retainCount 增加1。因此,当我释放这个filehandle 时,一旦我完成读取数据,内存就不会被释放。因此它试图读取一些无效数据并且应用程序崩溃了。请注意,这个问题在 ios 4.3 中发生,但在 ios 5 中没有。
在发布filehandle 之前,我将移除观察者。在释放文件句柄对象之前我还应该做些什么吗?
【问题讨论】:
标签: iphone objective-c ios nsfilehandle