I notice that in my app, sometimes when a view or view controller gets deallocated, the memory allocated for those is not freed. What could possibly be the reason for this?
I define deinit
method to verify that the view and view controller do get deallocated (deinit
gets called). I said sometimes because in some other cases, when I remove a view, the memory does get freed. Another thing I notice is that when I add a view, the memory usage goes up, then I remove that view (deinit
is called), the memory usage stays the same, but succeeding view additions of the same view don't affect the usage.
The view is created in a method and added by View.addSubview(UIView)
. In the view, there is a button that invokes View.removeFromSuperView()
.