AppDataModel is retained

Hi,

In the scanning objects using object capture project, when the content view is dismissed the AppDataModel is always retained and the deinit is never called.

@StateObject var appModel: AppDataModel = AppDataModel.instance

I am presenting the contentView using a UIHostingController

       let hostingController = UIHostingController(rootView: ContentView())
        hostingController.modalPresentationStyle = .fullScreen
        present(hostingController, animated: true)

I have tried to manually detach the listeners and setting the objectCaptureSession to nil.

In the debug memory graph there is a coachingoverlay retaining the AppDataModel.

I want to remove the appModel from memory when the contentView is dismissed.

Any suggestions?

If instance is a singleton, then that is the cause of your retain issue. @StateObject is all you need with AppDataModel inited.

@StateObject var appModel = AppDataModel()

Here is the memory graph:

I've tried canceling the objectCaptureSession :

   objectCaptureSession?.cancel()
   objectCaptureSession = nil

and detaching the listeners

  for sub in subscriptions {
            sub.cancel()
        }
        subscriptions = Set<AnyCancellable>()

Could it be a leak in the ARCoachingOverlayView?

AppDataModel is retained
 
 
Q