Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumSwiftretain cycles and capture listsSingle-choice MCQ

In this code, does the `Logger` instance get deallocated when `run()` finishes, and why?

final class Logger { var onMessage: ((String) -> Void)? func log(_ s: String) { onMessage?(s) } deinit { print("Logger gone") } } func run() { let logger = Logger() logger.onMessage = { msg in logger.log(msg) } logger.log("hi") } run()