Swift Struct Memory Leak

前端 未结 4 1885
轻奢々
轻奢々 2021-01-30 09:05

We\'re trying to use Swift structs where we can. We are also using RxSwift which has methods which take closures. When we have a struct that creates a closure that refers to

4条回答
  •  南方客
    南方客 (楼主)
    2021-01-30 09:39

    For anyone still facing this issue.

    1. [weak self] is not possible because Struct is value type and not a Reference type, so no pointer as such.

    2. The main issue of leak here is you are trying to access the Struct property self.someState = something inside the completion block which will basically create a new copy of your structure on assignment.

    You should not access Struct Property inside completion block.

提交回复
热议问题