When Controls cleanup happening and how to hook on their "dispose" event? #14908
-
When I create custom controls, I may have some events added, or tasks running, or have some instance saved in property that require to be properly disposed. How can I achieve this? Example from air:
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 5 replies
-
Have you tried implementing IDisposable and write down public void Dispose() in your code and put break point in it see if it's called |
Beta Was this translation helpful? Give feedback.
-
Tried to do it with "behaviour", but "Detatch" is never called when component is recycling.
Any help is appreciated. |
Beta Was this translation helpful? Give feedback.
-
Are there any plans for MAUI to actually call Dispose or add some other method that gets called on I tried what you suggested above and created a Update |
Beta Was this translation helpful? Give feedback.
-
With using PlatformBehavior, found some unexpected thing. Behavior detaches even when component is not being recycled, but just lost visibility. In my case I want to detect exactly when the control is due for recycling, not in dormant state. Any help? Upd: |
Beta Was this translation helpful? Give feedback.
-
Thank you very much. Using PlatformBehavior is great.
|
Beta Was this translation helpful? Give feedback.
Yeap, from docs you will see the
OnDetach
method isn't called all the time. You can change youBehavior
toPlatformBehavior
, the usage is the same but it should callOnDetach