Consider warning about `IPlatformViewHandler`
This problem came up with MAUI's Frame class, as FrameRenderer is not an NSObject but somehow produced a cycle that I could cause problems with at runtime.
Examples:
- https://github.com/dotnet/maui/pull/18552
- https://github.com/dotnet/maui/pull/18602
- https://github.com/dotnet/maui/pull/18663
- https://github.com/dotnet/maui/pull/18681
Ok, I think I see the pattern that isn't currently caught by the analyzer:
class Foo
{
UIButton bar = new();
public Foo()
{
bar.TouchUpInside += OnTouch;
}
void OnTouch(object sender, EventArgs e) { }
}
Foo is a non-NSObject, but causes a cycle: Foo -> UIButton -> Foo.
I'll need to test in isolation to verify this leaks every time. It definitely leaks if Foo was a .NET MAUI handler class.
No idea how the analyzer could check for this yet... I guess warn on any event? That would warn on all usage of TouchUpInside!
Ok, the simple example above, Foo, does not appear to leak in isolation:
https://github.com/jonathanpeppers/MemoryLeaksOniOS/compare/UIButtonEvents
So, this must only happen with MAUI IPlatformViewHandler types? There must be something that causes a cycle there.