[iOS]Swift Value Memory Study
스위프트 메모리 타입 요약
[High]
Stack
Dynamic
Heap
BSS
GVAR
TEXT
[Low]
value type
dump(variable:)
dump(with:)
dump(object:)
EX) String
stack 16byte 할당
heap 문자열 할당(짧은 문자열은 stack영역도 사용)
dump(with:)
copy-on-write
Collection Heap
print(MemoryLayout<String>.size)//16
var fString = "a"
var sString = "bb"
print(MemoryLayout.size(ofValue: fString)) //16
print(MemoryLayout.size(ofValue: sString)) //16
주어진 instance 의 memory footprint 를 리턴하고, pointer나 class 인스턴스에 대해서는 reference data의 size 와 상관없이 동일한 memory footprint 를 return 한다.
copy on write
수정 시점에는 copy-object를 사용하고 instance공유(origin-object 메모리 주소를 참조) 수정 후 변경된 데이터를 반영
고정된 Reference Type Value 메모리는 Heap영역에 할당 될 수도 있다.
스위프트 타입별 메모리 분석 실험
struct와 class 가 메모리 영역을 어디를 사용하는지 분석한 실험 결과
medium.com
The story of one mother & two sons: value type vs reference type in Swift
Swift is a mother?and it has two sons ?- Value Type ??♀️Reference Type ?♂️But what are their characteristics??♂️ Do they behave the same or opposite to each other? ?♂️ Swift is a multi-paradigm programming language developed by
www.freecodecamp.org
https://swiftrocks.com/memory-management-and-performance-of-value-types
Memory Management and Performance of Value Types
It's very likely that you asked yourself at least once in your iOS career what's the difference between a struct and a class. While realistically the choice between using one or another always boils down to value semantics versus reference semantics, the p
swiftrocks.com