-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix ObjectDisposedException issues for renderers OnElementPropertyChanged #9764
Conversation
|
Curses! Forgot to deal with the legacy renderers.... |
|
Okay, added checks for the old renderers. |
|
|
||
| protected override void OnCellPropertyChanged(object sender, PropertyChangedEventArgs args) | ||
| { | ||
| if (View.IsDisposed()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I know when chatting you had mentioned you wanted to make this method call as light as possible because how often PropertyChanged is called.
That being said then should we try only calling this for relevant properties?
I realize the code for that is a bit heavy but it would let us check for a few more things without the performance cost. Maybe the method calls at each line could use an action of sorts to get called
CallPropertyChangedMethod(UpdateMainText, this);And then CallPropertyChangedMethod would check this to see if it should still call UpdateMainText and then at that point the check and any additional behavior could be generalized.
PureWeen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the IsDisposed checks should also be added to the tracker as well.
Done. |
Description of Change
This issue occurs under a very specific set of circumstances:
For garbage collection to occur, the link between the managed and native objects referenced by the renderer needs to be severed. So the object's Handle is set to IntPtr.Zero. However, before the actual collection can occur, the source property changes.
When the source property changes, the weak reference to the element with the bound property is checked, and that creates a strong reference. The property changed handler fires, which ultimately causes the renderer's OnElementPropertyChanged method to run. However, at this point the renderer's native object is no longer eligible for anything; any attempt to reference it throws the ObjectDisposedException.
This change adds a check for a zeroed Handle before running the rest of the OnElementPropertyChanged method, which avoids the exception. The element and renderer can later be succesfully collected by the GC.
This circumstance is rare. It's trivial to recreate it artificially (see the unit tests included with this PR), but in practice it mostly happens when properties are bound to a (relatively) long-lived source; see issue #9431 for an example where CollectionView items have properies bound to the Page itself.
Issues Resolved
API Changes
None
Platforms Affected
Behavioral/Visual Changes
None
Before/After Screenshots
Not applicable
Testing Procedure
Automated tests.
PR Checklist