内存泄漏每个实例

时间:2017-08-21 08:01:42

标签: ios swift memory-leaks instance

对不起,我是初学者。
我不知道如何修复我的内存泄漏 我用仪器来检查泄漏。 我发现我创建了城市模型实例,我应该回收什么内存 我该怎么办才能修好它? 感谢。

class CityList:DefaultModel {

    func getCities() {
    let query = mainDB.city
    do {
        let results = try mainDB.db?.prepare(query)
        results?.forEach({ (row) in
            let cityId = row[Schema.cityId.TEXT]
            if cityId.isEmpty == false {
                if let city = self.cities[cityId] {
                    city.fromQueryRow(row)
                } else {
                    let city = City(cityId) //memory leak
                    city.fromQueryRow(row)  //memory leak
                    self.cities[cityId] = city
                }
            }
        })
        self.notifySubject.onNext("")
    } catch {
        debug(object: error)
    }

}

}


class City:NSObject {

let notifySubject = PublishSubject<Any>()

var id:String = ""
@objc var name:String = ""
var userId:String = ""
var country:String = ""
var descriptions:String = ""


override init() {
    super.init()
}

init(_ id:String) {
    super.init()
    self.id = id
}
}

0 个答案:

没有答案