-
(Swift) deinitializeriOS💖 2024. 9. 3. 17:34
- struct 에는 없고, class 에 있는 것
(struct: value type, class: reference type)
- 해당 인스턴스가 메모리에서 해제될때 호출됨
class Human { var name: String init(name: String) { self.name = name print("***initialize instance***") } deinit { print("***deinitialize instance: \(name)") } func printName() { print("my name: \(name)") } } func createJohn() { let john = Human(name: "John") john.printName() } createJohn()creatJohn() 함수가 끝날때, 함수 안에서 인스턴스는 일을 다했기 때문에, 메모리에서 해제된다.
'iOS💖' 카테고리의 다른 글
(Swift) POP (Protocol Oriented Programming) (0) 2024.09.04 (Swift) Structures VS. Classes (0) 2024.09.03 (Swift) Access Control (2) 2024.09.03 (Swift) Type Properties & Methods (0) 2024.09.03 (Swift) Lazy Properties (0) 2024.09.03