maui: DisconnectHandler is never called

Description

I created a Custom Control that inherits from ElementHandler and at the moment that the control is closed the DisconnectHandler method isn’t called, even if I set the VirtualView.Handler to null.

Steps to Reproduce

  1. Add breakpoints here
  2. Start the sample app
  3. Scroll to the bottom and press the button
  4. See the popup
  5. Click outside the popup to close it
  6. The DisconnectHandler isn’t called

Version with bug

Preview 10 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 11

Did you find any workaround?

No

Relevant log output

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 16 (11 by maintainers)

Most upvoted comments

Thats really surprising : counterintuitive. Isnt that the whole point of connect/disconnect, that I want my resources cleaned up at that point? I dont put anything in those blocks if I dont want that. Especially because ConnectHandler is where you attach touch handlers etc as far as Im aware, I think its a recipe for surprising behavior and memory leaking.

I’m going to close this issue for now.

The current behavior for MAUI is to not automatically call DisconnectHandler as we can’t predict when users might want resources cleaned up.

I suspect we’ll need to eventually add some helpers or possibly lifecycle properties so users can tie Disconnect to being attached/detached from a window

@PureWeen would be good if the .NET MAUI does that for me (lazy developer mode on), but it’s fine if I’ve to call the DisconnectHandler myself.

@pictos you are right. DisconnectHandler isn’t triggered on Android emulator. @kristinx0211 , Could you repro this on IOS emulator?