Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swift deinit method not working when UIView is removed from memory

In Swift ARC is calling deinit when any UIViewController is removing from memory , but it's not getting called if any UIView is removed from memory.

for example

In case of UIViewController Class deinit is working great

class MusicPlayerUIViewController: UIViewController,UITableViewDelegate,UITableViewDataSource
    {
    deinit
        {
            APP_DELEGATE.RemovePlayerContents()
        }
    }

but in case of UIView Class deinit not working

class MusicPlayerView: UIView,UITableViewDelegate,UITableViewDataSource
{
deinit
    {
        APP_DELEGATE.RemovePlayerContents()
    }
}

any idea .

like image 659
Anupam Mishra Avatar asked Oct 15 '25 10:10

Anupam Mishra


1 Answers

Parent ViewController can hold you UIView. You have to set to nil a property, that stored you UIView in parent UIViewController for release uiview.

Or override removeFromSuperview() and place your deinit code in it.

like image 57
Igor Avatar answered Oct 18 '25 07:10

Igor