[ad_1]
I’ve checked out some feedback to questions on stackoverflow about utilizing [weak self] and [unowned self]. I must be certain I perceive appropriately.
To start with, I’m utilizing the newest Xcode – Xcode 13.4, the newest macOS – macOS Monterey 12.4, and I am writing code appropriate with iOS 12.0 to the newest iOS 15.
To start with, am I right that reminiscence that has a robust reference to it’s owned by whichever the sturdy reference belongs to?
Additionally, and that is what I really want to know, I need to know what occurs if I exploit [weak self] in initially of a closure, after which I’ve the assertion guard let `self` = self else { return }. I imagine the guard assertion, if the situation succeeds, assigns the reference self holds to the newly declared sturdy reference named self within the let `self a part of the guard assertion. Is that right?
What that leads me to ask is, What occurs on the finish of the closure. Am I right that although the newer self holds a robust reference, the reminiscence the sturdy reference factors to is deallocated as soon as the code within the closure has executed the final assertion within the closure, as a result of the newer self with the sturdy reference is said throughout the closure itself, and is deallocated together with all reminiscence that had been allotted for that closure.
I believe I acquired all of this proper. If not, please let me know.
I’m concerned about any further data or any clarifications if you’ll.
[ad_2]
