Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should deinit be called in UITableViewCell?

I'm trying to find memory issues in my swift app. Found some by checking if deinit is called (strong reference in delegates for example) but checking UITableViewCell's or UICollectionViewCell's I don't see deinit never being called.

I have a really simple cell where I use:

  • Some IBOutlets
  • Setup view on awakeFromNib (corner radius)
  • A setClient function called from tableView with client object to setup view
  • prepareForReuse to reset some view parts

Update:

Checked if tableView is calling it's deinit but it's not. So UIViewController calls it's deinit but tableView is still in memory.

Update 2:

Found the issue. A guard let was keeping an strong reference to the tableView in a helper function.

like image 793
David Collado Avatar asked May 10 '16 19:05

David Collado


1 Answers

Since tableview cells are reused, they tend to be only deinited if the tableview itself is deinited. Because even if they are not used right now, the tableview would keep them alive in case they are needed for reuse.

like image 153
gnasher729 Avatar answered Sep 23 '22 10:09

gnasher729