참고사이트 : https://medium.com/@jungkim/%EC%8A%A4%EC%9C%84%ED%94%84%ED%8A%B8-%ED%83%80%EC%9E%85%EB%B3%84-%EB%A9%94%EB%AA%A8%EB%A6%AC-%EB%B6%84%EC%84%9D-%EC%8B%A4%ED%97%98-4d89e1436fee

 

스위프트 타입별 메모리 분석 실험

struct와 class 가 메모리 영역을 어디를 사용하는지 분석한 실험 결과

medium.com

 

 

LLDB 메모리 덤프 저장

 

XCode Console에서 저장하고 싶은 부분에 브레이크 포인트 설정 후 아래 명령어 실행

(lldb) process save-core /Users/xxxxxxxx/memoryData.dump

 

[iTerm2 에서 열어보기]

> lldb -c memoryData.dump

(lldb) gui

 

[LLDB에서 덤프파일 읽기]

> lldb

(lldb) target create --core "momoryData.dump"

(lldb) gui

 

[메모리 주소 알아보기]

struct Memory {
    @inlinable static func dump<T>(variable: inout T) {
        withUnsafePointer(to: &variable) { print($0) }
    }
    
    @inlinable static func dump(with: UnsafeRawPointer) {
        let address = Int(bitPattern: with)
        print(String(format:"%018p", address))
    }
    
    @inlinable static func dump(object: AnyObject) {
        print(Unmanaged.passUnretained(object).toOpaque())
    }
}

//////////////////////////////////////////////
Memory.dump(variable: &jsParam)
결과 : 0x000000016d2c21b8

 

+ Recent posts