0

I know it's all with the weak strong reference when presenting the viewController in the parent view ... correct me please if I'm wrong

this is an example how I do it

let viewHolder = viewClass()

func presentView()  {
    self.present(viewHolder, animated: true) {

    }
}

see my memory monitor only from open and dismiss the same view over and over

enter image description here I have tried this

weak var viewHolder = viewClass()

func presentView()  {
    self.present(viewHolder!, animated: true) {

    }
}

but this would give me a crash

Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

and dismiss the viewClass this way (inside itself off)

func dismissPage()  {
    self.dismiss(animated: true)
}

any help would be appreciated thanks

Jacob Kazal
  • 149
  • 1
  • 9
  • Show the declaration of `viewClass`. Also explain how the presented view is dismissed. – matt Nov 30 '17 at 02:39
  • @matt thanks for replaying, I updated my question please see the end for the dismissing part. about the declaring `viewClass`, not sure what you mean ? see the question, there was a typo from my side and I corrected it . – Jacob Kazal Nov 30 '17 at 03:43
  • You have a class called `viewClass`. Show it. Show your code! We can’t intuit by magic what is causing the retain cycle. Show us your code. – matt Nov 30 '17 at 04:13

2 Answers2

1

The problem might not be in the viewClass. You are declaring let viewHolder = viewClass() in your initial class. So when you dismiss the controller, that variable still exists. Do you need to keep a reference to it? If not, you can easily allocate it when needs to be displayed and when you dismiss it, the memory is going to be freed:

func presentView()  {
     // instead of saving viewHolder as an instance variable, you declare it locally
    let viewHolder = viewClass()
    self.present(viewHolder, animated: true) {

    }
}
Robert D. Mogos
  • 900
  • 7
  • 14
1
  1. Use deint method and check weather it is called or not after dismiss your viewcontroller.

  2. if your using any kind of blocks or closure to work done then use [weak self] in side your closure.

  3. your can also make nil your property/delegate/variable when viewDidDisappeared only if after there is no view controller will be presented or pushed