Skip to content

Instantly share code, notes, and snippets.

@devxoul
Last active October 16, 2019 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devxoul/a376db02653ccff732d365636d486f03 to your computer and use it in GitHub Desktop.
Save devxoul/a376db02653ccff732d365636d486f03 to your computer and use it in GitHub Desktop.
Does UIViewController get deallocated synchronously? NO. (if view is loaded)
weak var weakViewController: UIViewController?
_ = {
let viewController = UIViewController()
viewController.loadViewIfNeeded() // this line prevents from deallocation
weakViewController = viewController
}()
XCTAssertNil(weakViewController) // (fail) weakViewController = Optional(<UIViewController: 0x7fd55e705080>)
DispatchQueue.main.async {
print(weakViewController) // nil
}
@oozoofrog
Copy link

oozoofrog commented Oct 16, 2019

arc 에서의 autorelease 최적화와 관련한 이슈라고 생각합니다. 같은 문제를 일으키는 좀 더 간단한 구현체를 만들어보는 중이네요. (아니면 -fno-objc-arc 플래그로 컴파일을 해봐야하나 .. 고민)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment