I am using NSFileHandle
to read data from a socket.
This is how I am creating the filehandle
:
filehandle = [[NSFileHandle alloc] initWithFileDescriptor:sock closeOnDealloc:YES];
I am doing this:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(readData:) name:nil object:filehandle];
[filehandle readInBackgroundAndNotify];
I notice that, readInBackgroundAndNotify
is increasing the retainCount
of the fileHandle
by 1. Hence when I release this filehandle
once I am done reading data, the memory is not released. And hence it is trying to read some invalid data and the app is crashing. Please note that this issue is occurring in ios 4.3 but not in ios 5.
I am removing observer before releasing the filehandle
. Is there anything else I should be doing before releasing the file handle object?