快速代码中的内存泄漏

时间:2017-08-04 16:23:46

标签: swift xcode macos memory-leaks

我是swift的新手。 我正在尝试编写以下代码来查找哈希值。但似乎这个代码正在泄露。

func CalculateHash(InputStr: String) -> UInt64 {
    let PRIME = 12345678
    var hash: UInt64 = 0
    var iCnt: Int = 0
    let Strlen = countElements(InputStr)
    var UInt64EqOfChar: UInt64 = 0

    //    for (;iCnt < Strlen; ++iCnt) {
    for TmpChar in InputStr {
        //var CharName = InputStr[advance(InputStr.startIndex, iCnt)]
        for TmpData in String(TmpChar).unicodeScalars {
            UInt64EqOfChar = UInt64(TmpData.value)
        }
        hash += UInt64EqOfChar
        //        hash += (hash << 1)
        hash ^= (hash >> 6)
    }

    hash += (hash << 12)
    hash ^= (hash >> 23)
    hash += (hash << 34)
    hash = hash & UInt64(PRIME)
    return hash
}

Leak from instruments attached here

0 个答案:

没有答案