Does setting `constraint.isActive = false` deallocate the constraint?

Viewed 1889

Say I want to remove a constraint, traditionally I would do:

view.removeConstraint(constraint)

However, there is now the new isActive methods for installing/uninstalling constraints.

If I do the following:

constraint.isActive = false

Will it remove it from memory correctly?

2 Answers

Let say if you define the constraint outlet as weak var in unreusable UIViewController, and you deactivate it by constraint.isActive = false will remove it from the memory.

However, if you define the constraint outlet as weak var in reusable view like UICollectionViewCell, and this UICollectionViewCell is rendered as multiple views in a parent view. Deactivating it by constraint.isActive = false won't remove it from the memory since the other cells still hold the reference for that constraint.

Defining the constraint outlet as (strong) var, executing constraint.isActive = false won't remove it from the memory despite UIView it's defined on.

Related