小编tie*_*tie的帖子

释放UnsafeMutableBufferPointer <UInt8>值

我正在实现一个纯粹的Swift NSData替代品.下面是我的Swift 2代码的一部分.据我所知,Data实例deinitialization没有destroy()和缓冲区指向的dealloc()字节block.那么,还有没有调用的任何方式destroydealloc()以防止内存泄漏之前对缓冲器指针的Data实例deinitializes?

public struct Data: DataContainer {
    public typealias Block = UInt8
    public var blocks: UnsafeMutableBufferPointer<Block>

    public init(bytes: UnsafeMutablePointer<Block>, length: Int) {
        // copy bytes
        let bytesCopy = UnsafeMutablePointer<Block>.alloc(length)
        bytesCopy.initializeFrom(bytes, count: length)
        // init byte blocks
        self.blocks = UnsafeMutableBufferPointer<Block>(start: bytesCopy, count: length)
    }
}
Run Code Online (Sandbox Code Playgroud)

memory memory-leaks memory-management swift swift2

3
推荐指数
1
解决办法
1148
查看次数

标签 统计

memory ×1

memory-leaks ×1

memory-management ×1

swift ×1

swift2 ×1