Add CFRelease((CFStreamRef)inputStream); and CFRelease((CFStreamRef)outputStream); to the streamClose method.
When CFStreamCreatePairWithSocketToHost returns, ownership of readStream and writeStream is transferred to you:
Ownership follows the Create Rule in Memory Management Programming Guide for Core Foundation.
Core Foundation objects must be explicitly released even when using ARC:
The compiler does not automatically manage the lifetimes of Core Foundation objects; you must call CFRetain and CFRelease (or the corresponding type-specific variants) as dictated by the Core Foundation memory management rules (see Memory Management Programming Guide for Core Foundation).
Alternatively, change this line (and the corresponding line for outputStream ):
inputStream = (__bridge NSInputStream *)readStream;
to:
inputStream = (__bridge_transfer NSInputStream *)readStream;
This is because readStream has an outstanding save value that ARC does not know. By granting ARC ownership of this index, you give it permission to issue the index at the appropriate time. Further reading: 1 , 2
source share