yccheok
(Yan Cheng Cheok)
1
I was wondering, is there any tool, which can help to detect memory leak caused by missing [weak self].
For instance, the following code contains memory leak issue caused by lack of [weak self]
class ImagePageViewController: UIPageViewController {
lazy var memoryLeak = UIAction(
title: "memory_leak",
image: nil
) { _ in
print(">>>> \(self)")
}
override func viewDidLoad() {
super.viewDidLoad()
print("\(memoryLeak)")
}
}
Is there any tool which can help us to prevent such issue? I have tried GitHub - realm/SwiftLint: A tool to enforce Swift style and conventions. but it is not able to detect such.
tera
2
While this is impossible to do statically in general case as you can do:
// one second later:
if foo(arguments) {
self.memoryLeak = UIAction(title: "") { _ in } // break the cycle
}
hopefully static analyser could be improved to catch the majority of typical cases.