我对内存泄漏有疑问 我想释放记忆,使用[弱自我],但似乎无法释放 如何释放记忆成功?
代码:
class City:NSObject {
let notifySubject = PublishSubject<Any>()
var id:String = ""
@objc var name:String = ""
var kind:String = ""
var userId:String = ""
var country:String = ""
var subject:String = ""
var descriptions:String = ""
var cities:[City] = [City]()
override init() {
super.init()
}
init(_ id:String) {
super.init()
self.id = id
}
func getData() {
API.Data.get({ json in
json.forEach({ [weak self] (index, data) in
self?.cities.append(City(data))
})
self.fromJson(json)
self.notifySubject.onNext(json)
})
}
}