I have a ViewModel
class with a method like this:
func getUserSettings() {
UserSettingsManager.getInfo { (result, error) in
if error == nil {
self.userData = result
}
}
}
This class viewModel
is instantiated and then viewModel.getUserSettings()
is called. Such method is calling a static
method UserSettings.getInfo
which is passed an @escaping
closure to be called as completion. That closure is capturing viewModel
(it's using self
within it's body).
What consequences does calling a
static
method have in terms of memory? How would thatUserSettings
class that is not instantiated be "deallocated"?Could a strong reference cycle happen in this particular scenario? If so, how should
self
be captured:weak
orstrong
?