1
我使用CFStreamCreateBoundPair
來創建一對流來上傳一個大文件。代碼如下所示。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() {
}
一切順利的話,除了內存issue.I用儀器檢查並找出CFStreamCreateBoundPair
無法釋放緩衝區大小的內存,在這種情況下是1M後,無論是CFReadStream
和CFWriteStream
是closed.I有屏幕截圖也是。
我對swift中的Core Foundation框架不太熟悉,不知道爲什麼它不能自動發佈。