What is the difference in Swift between 'unowned(safe)' and 'unowned(unsafe)'?

前端 未结 4 1628
醉话见心
醉话见心 2020-12-24 06:51

Apple\'s Swift Programming Language Guide mentions the capture specifiers unowned(safe) and unowned(unsafe), in addition to weak

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-24 07:14

    Variable is accessed when it was dellocated already with attribute:

    unowned

    • Program knows it is invalid, and goes crash immediately.
    • Behavior is defined.

    unowned(unsafe)

    • Program knows nothing.
    • It may crash immediately.
    • It may access unknown memory address and have strange state until it it dies at surprise location.
    • Behavior is undefined. Life gets harder.

提交回复
热议问题