LiveLayout never deallocs View Controller

I'm using MSMessageLiveLayout to render my message bubbles however it never seems to release the message view controllers.


I've got 10 MSMessageLiveLayout message bubbles on screen. I scroll up and down a few times and using the Debug Memory Graph tool it shows that there are 100 instances of my view controller. I have also overridden deinit to print when it gets dealloced, which never happens. I thought perhaps I have a leak but I've created a brand new *blank* extension and the same thing happens.


Is this expected? It seems surprising that by scrolling, new view controllers get created but never dealloc-ed.

Replies

After quite a bit of investigation this does seem like a bug with Apple's internal Messaging framework when the presentationStyle = .transcript. The workaround I have found requires you to call the NSExtensionContext and call cancelRequest: or completeRequest:. This seems to release the view controller.


This should be fixed or at least documented somewhere, specifically within the iMessage documentation.


    override func didResignActive(with conversation: MSConversation) {
        super.didResignActive(with: conversation)

        let error = NSError(domain: "test", code: 1, userInfo: nil);
        self.extensionContext?.cancelRequest(withError: error)

        // or

        self.extensionContext?.completeRequest(returningItems: self.extensionContext?.inputItems, completionHandler: { (expired) in
        })
    }

Regards,

Richard