I use CFStreamCreateBoundPair
to create a pair of stream in order to upload a large file.The code is like below.
let readStreamPointer = UnsafeMutablePointer<Unmanaged<CFReadStream>?>.alloc(1)
let writeStreamPointer = UnsafeMutablePointer<Unmanaged<CFWriteStream>?>.alloc(1)
let bufferSize = 1024*1024 //1M buffer size
CFStreamCreateBoundPair(kCFAllocatorDefault, readStreamPointer,writeStreamPointer, Int(bufferSize) as CFIndex)
if let rStream = readStreamPointer.memory?.takeRetainedValue(),writeStream = writeStreamPointer.memory?.takeRetainedValue() {
}
Everything goes well except a memory issue.I check out with Instruments and find out CFStreamCreateBoundPair
can not free the memory of buffer size which in this case is 1M after both the CFReadStream
and CFWriteStream
are closed.I have a screen shot too.
I am not quite familiar with Core Foundation framework in swift and don't know why it can not be auto released.