Swift의 Type은 Named, Compound type와 Reference, Value type을 기준으로 나눌 수 있습니다.
class, struct, enum tuple, function더 자세한 내용을 알고 싶은 분들은 Swift Types를 보시면 도움이 될 것 같습니다.
class, func, closure 등call by reference:parameter 전달 시 객체를 가리키고 있는 메모리 주소값이 복사됩니다.allocate하며 reference counting을 통해 deallocate가 필요struct, enum, tuple 및 swift 기본 자료형(Int, Float, String, Array, Dictionary, Set 등은 모두 struct로 구현되어 있음)call by value: parameter 전달 시 value copy가 일어납니다.scope based lifetime: comfile time에 compiler가 언제 메모리를 할당/해제할지 정확히 알고 있다.기본적으로 value type은 stack 영역에 저장되고 reference type은 heap 영역에 저장됩니다. 하지만 특정 경우에는 value type임에도 heap영역에 저장되고 reference type임에도 stack 영역에 저장되는 경우가 있습니다.
Copy on Write를 사용합니다. 수정 전까지는 기존 element가 저장된 메모리 주소를 참조합니다.protocol 을 채택 할 때, generic을 사용할 때 등 다양한 상황들 (참고)
Reference type을 Stack에 할당할 수도 있다고 합니다. 이러한 최적화는 SIL 생성 구간에서 발생합니다.(참고)