Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ViewController not being deallocated due to internal retain cycle

Some of my view controllers don't get deallocated after being popped from view. I've gotten rid of the other strong references so I'm left with this internal retain cycle held through a reference form _externalObjectsTableForViewLoading. It's a private UIViewController property so I'm unable to clear it myself. I don't know if iOS has an API to clear it or why it's not being cleared after popping the view controller.

I've tested with with my app running in Release mode both in iOS 11 and 12. Running the app in Instruments renders the same stairs pattern seen in Xcode with the view controllers being retained.

Any ideas? Thanks in advance!

Retain Cycle

like image 531
Carlos Avatar asked Nov 08 '18 04:11

Carlos


People also ask

How do I remove Viewcontroller from memory?

You can't remove a view controller from within itself (i.e. viewDidDisappear) - what you need to do is to remove all references to it, at which point ARC will deallocate it.

Why Deinit is not called?

So the deinit is not called if there is no additional scope.

What is a navigation controller?

NavController manages app navigation within a NavHost . Apps will generally obtain a controller directly from a host, or by using one of the utility methods on the Navigation class rather than create a controller directly. Navigation flows and destinations are determined by the navigation graph owned by the controller.


1 Answers

In your problem, is one viewController accessing another viewController? Our problem is that there was a non weak reference to a callback in another viewController.

As mentioned in your and in other posts on this, _externalObjectsTableForViewLoading is a viewController private property, but a storyboard related property. This leads me to think that your code has strong references to another object that is a view controller through a callback or through a direct property reference to its instance.

like image 190
Alex Zavatone Avatar answered Nov 05 '22 11:11

Alex Zavatone