gpt4 book ai didi

ios - CFStreamCreateBoundPair 不能释放

转载 作者:行者123 更新时间:2023-11-28 08:36:42 27 4
gpt4 key购买 nike

我使用 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 检查并找出 CFStreamCreateBoundPairCFReadStream 之后无法释放缓冲区大小的内存,在本例中为 1M和 CFWriteStream已关闭。我也有屏幕截图。

Instruments screen shot我对 swift 中的 Core Foundation 框架不太熟悉,不知道为什么不能自动发布。

最佳答案

这是我的做法:

class func createBound(inputStream: inout InputStream?, outputStream: inout OutputStream?, bufferSize: UInt) {
var readStream: Unmanaged<CFReadStream>?
var writeStream: Unmanaged<CFWriteStream>?
CFStreamCreateBoundPair(nil, &readStream, &writeStream, CFIndex(bufferSize))
if inputStream != nil {
inputStream = readStream!.takeUnretainedValue()
}
if outputStream != nil {
outputStream = writeStream!.takeUnretainedValue()
}
}

关于ios - CFStreamCreateBoundPair 不能释放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37535767/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com