我使用CFStreamCreateBoundPair
创建一对流以上传大文件。代码如下所示。
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() {
}
除了内存问题,一切都很顺利。我检查了 Instruments 并发现CFStreamCreateBoundPair
无法释放缓冲区大小的内存,在这种情况下,两者都关闭后为 1M CFReadStream
。我CFWriteStream
也有一个屏幕截图。