Xcode에서 메모리 누수 확인하기
1. 샘플 프로젝트 생성하기

import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
import UIKit
// MARK: - 델리게이트 생성
protocol MyDelegate: AnyObject {
var name: String { get }
}
class MyView: UIView {
weak var delegate: MyDelegate?
// var delegate: MyDelegate?
}
// MARK: - 델리게이트 채택
class DetailViewController: UIViewController, MyDelegate {
var name: String = ""
let myview = MyView()
override func viewDidLoad() {
super.viewDidLoad()
print(#function, #fileID)
myview.delegate = self
view.addSubview(myview)
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
print(#function, #fileID)
}
@IBAction func previous(_ sender: Any) {
print(#function, #fileID)
dismiss(animated: true, completion: nil)
}
deinit {
print(#function, #fileID)
}
}
2. 메모리 누수 관련 설정하기


3. 확인하기
weak var delegate: MyDelegate? 일 때 (약한참조일때)




weak delegate: MyDelegate? 일 때 (강한참조일때)


Last updated