Deinit never called

前端 未结 13 1849
清歌不尽
清歌不尽 2020-11-30 03:51

I\'m creating a ViewController object an pushing it to a navigation controller. When the object is being popped from the stack - it is not being release and Deinit is not be

13条回答
  •  臣服心动
    2020-11-30 04:21

    First of all make sure to define deinit

    deinit {
        print("OverlayView deinit")
    }
    

    Use Xcode's object graph to check number of instances being created and if they are not getting deallocated then they will keep growing. I was creating property of another ViewController on top of the file so i move it and place it in the scope it was being used that solved my problem. And its deinit started calling.

    Moreover i was using a uiview property to show a overlay that need to be accessed from my viewcontroller at some places i make it optional and set it nil when after calling removefromsuperview on it.

    var overlay: OverlayView?
    overlay = nil
    

    If still dealloc not calling then there could be a retain cycle issue as described above in that case you will have to check another viewcontroller(B) too if its calling back this controller(A) then set one of them as a weak variable.

提交回复
热议问题