Swift UnsafeMutablePointer: Must I call deinitialize before deallocate?

后端 未结 1 884
予麋鹿
予麋鹿 2021-01-20 07:03

Given an instance of UnsafeMutablePointer, what\'s the point of calling deinitialize(count:) right before deallocate(capacity:)?

相关标签:
1条回答
  • 2021-01-20 07:35

    The article explains below the code, if you keep reading.

    Update: as noted by user atrick in the comments below, deinitialization is only required for non-trivial types. That said, including deinitialization is a good way to future proof your code in case you change to something non-trivial. Also, it usually doesn’t cost anything since the compiler will optimize it out.

    0 讨论(0)
提交回复
热议问题