본문 바로가기
Swift

[Swift] Swift Object Lifetime

by Sky Titan 2022. 8. 26.
728x90

https://www.raywenderlich.com/966538-arc-and-memory-management-in-swift#toc-anchor-003

 

ARC and Memory Management in Swift

In this tutorial, you’ll learn how ARC works and how to code in Swift for optimal memory management. You’ll learn what reference cycles are, how to use the Xcode 10 visual debugger to discover them when they happen and how to break them using an exampl

www.raywenderlich.com

Swift Object Lifetime

 Swift object의 lifetime은 5 단계로 이루어진다.

  1. Allocation: stack이나 heap영역에서 메모리를 가져온다.
  2. Initialization: init 코드를 실행한다.
  3. Usage
  4. Deinitialization: deinit 코드를 실행한다.
  5. Deallocation: 메모리를 stack이나 heap 영역에 반환한다.

 allocation과 deallocation 과정에 대한 직접적인 hook는 존재하지 않지만, init과 deinit에서 print함수를 이용해서 해당 프로세스들을 관찰하기 위한 proxy로 활용할 수 있다.

728x90

댓글