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
- Add breakpoints here
- Start the sample app
- Scroll to the bottom and press the button
- See the popup
- Click outside the popup to close it
- The
DisconnectHandlerisn’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)
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.
@pictos yea this is definitely going to become a thing 😃
An issue and some design docs around current recommendations will definitely be in order.
I’m going to close this issue for now.
The current behavior for MAUI is to not automatically call
DisconnectHandleras 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
DisconnectHandlermyself.@pictos you are right.
DisconnectHandlerisn’t triggered on Android emulator. @kristinx0211 , Could you repro this on IOS emulator?