-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Formalize virtual layout concepts and fix iOS memory leaks #15303
Conversation
Thank you for your pull request. We are auto-formatting your source code to follow our code guidelines. |
@@ -42,6 +41,21 @@ public ContentViewGroup(Context context, IAttributeSet attrs, int defStyleAttr, | |||
_context = context; | |||
} | |||
|
|||
public ICrossPlatformLayout? CrossPlatformLayout | |||
{ | |||
get; set; |
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.
I'm not sure about this but I think the platform view should never have a strong reference to the virtual view.
I think the strong references should flow like this:
VirtualView/VirtualView's Properties (eg. ItemSource) --> Handler/Manager/PlatformView
Handler/Manager --> PlatformView/Native Listeners
but whenever you need the opposite direction it should be a weak reference. It's meaningless to have a platform view that the user have already lost the reference to its VirtualView/Handler.
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.
I don't know how to post a comment without it being a review 😅. Feel free to dismiss this one.
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.
That's the point of this PR, to make that weak reference possible. The old implementation was implicitly keeping a strong reference through the internal CrossPlatformMeasure/CrossPlatformArrange Funcs. This way, we have the option of making the reference a weak one (and still allow handlers to modify the CPM/CPA implementations).
The iOS implementation in this PR already uses a weak reference for this. Since we don't currently have leaks on Windows/Android, I've left this as a strong reference to avoid the extra overhead of the weak reference target check. So we could change those to weak references in the future, if we need to.
That said, I could be convinced to make all 3 platforms use weak references just for the symmetry, assuming the performance impact of the weak reference checks is small.
@jonathanpeppers @PureWeen @mattleibow any thoughts on that?
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.
The above property is Android only, so there isn't an issue there? Really only need to be concerned about cycles on iOS/Catalyst.
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.
This looks like it is on the right track to get rid of the delegates for CrossPlatformArrange/Measure
.
I would also update these tests:
maui/src/Controls/tests/DeviceTests/Elements/NavigationPage/NavigationPageTests.cs
Lines 268 to 273 in 130f788
Content = new VerticalStackLayout | |
{ | |
new Label(), | |
new Button(), | |
new CollectionView(), | |
} |
maui/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs
Lines 981 to 986 in 130f788
Content = new VerticalStackLayout | |
{ | |
new Label(), | |
new Button(), | |
new CollectionView(), | |
} |
To include a ScrollView
& ContentView
. In debugging these issues on iOS, I sometimes found these tests would find further problems...
@@ -42,6 +41,21 @@ public ContentViewGroup(Context context, IAttributeSet attrs, int defStyleAttr, | |||
_context = context; | |||
} | |||
|
|||
public ICrossPlatformLayout? CrossPlatformLayout | |||
{ | |||
get; set; |
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.
The above property is Android only, so there isn't an issue there? Really only need to be concerned about cycles on iOS/Catalyst.
If this "formalizes layout concepts", should there also be a |
src/Controls/src/Core/Compatibility/Handlers/iOS/FrameRenderer.cs
Outdated
Show resolved
Hide resolved
/rebase |
8bd93cc
to
be866e8
Compare
Add proxy to avoid UIScrollView event handlers preventing handler GC;
be866e8
to
1f4cbe0
Compare
Assuming this PR gets merged and the layout docs PR gets merged, I'll update the docs to include the changes here. |
# Conflicts: # src/Controls/src/Core/Frame/Frame.cs # src/Controls/src/Core/HandlerImpl/ScrollView/ScrollView.Impl.cs # src/Controls/src/Core/HandlerImpl/TemplatedView/TemplatedView.Impl.cs # src/Core/src/PublicAPI/net-android/PublicAPI.Unshipped.txt # src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt # src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt # src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt # src/Core/src/PublicAPI/net/PublicAPI.Unshipped.txt # src/Core/src/PublicAPI/netstandard/PublicAPI.Unshipped.txt # src/Core/src/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt
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.
I went through the latest changes, and I like this PR over: #15193
However, I'm probably not qualified to know if the iOS/ScrollView changes are OK. Maybe we have to manually test those?
🚨 API change(s) detected @davidbritch FYI |
Description of Change
Proposed alternative to #15193
Formalizes the concept of the layout backing controls having CrossPlatformMeasure and CrossPlatformArrange methods which they call during the layout process; also allows the handlers to make modifications as necessary to those methods (e.g., normalizing the ScrollView behavior across all the platforms).
This includes the GC tests from #15193 and makes the iOS implementation of ICrossPlatformBacking utilize a weak reference to avoid circular references on that platform.
Issues
Helps #14664, but TBD if it fixes it.