我NSFileHandle
用来从套接字读取数据。这就是我创建的方式filehandle
:
文件句柄 = [[NSFileHandle alloc] initWithFileDescriptor:sock closeOnDealloc:YES];
我正在这样做:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(readData:) name:nil object:filehandle];
[filehandle readInBackgroundAndNotify];
我注意到,readInBackgroundAndNotify
正在增加retainCount
1。fileHandle
因此,当filehandle
我在完成读取数据后释放它时,内存不会被释放。因此它试图读取一些无效数据并且应用程序崩溃了。请注意,这个问题在 ios 4.3 中发生,但在 ios 5 中没有。我在发布filehandle
. 在释放文件句柄对象之前我还应该做些什么吗?