Group Group Group Group Group Group Group Group Group

Advanced Swift: Memory Management · Conclusion | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1940727-advanced-swift-memory-management/lessons/9

In this lesson, why don’t you use unowned instead of weak? Is it possible to cause any crash?

I am not sure which lesson you are referring to but, using unowned is a much stronger assertion than weak. Unowned says I don’t own that memory, but I guarantee that it won’t go away. Weak says I don’t own that memory but don’t guarantee anything.

In a way, unowned is quite similar to an implicitly unwrapped optional (or doing a force unwrap) where weak is like using a real optional.

If you want to really run with scissors and want zero overhead, you can use “unowned(unsafe)” but I don’t recommend it because if you get it wrong you get undefined behavior instead of a deterministic trap.

Hi Ray

Thank you for this course. It was quite useful in understanding memory management in Swift. I have a suggestion though.

It would be more beneficial if in the next update you could include more videos on memory management in iOS in case of ViewControllers, animations, segues etc that is focusing more on the real world application scenarios.