Skip to content
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

[Mono.Android] fix potential leak in Java.Lang.Thread #8900

Merged
merged 1 commit into from
Apr 25, 2024

Commits on Apr 24, 2024

  1. [Mono.Android] fix potential leak in Java.Lang.Thread

    Fixes: dotnet/maui#18757
    Context: dotnet/maui#22007
    Context: https://cs.android.com/android/platform/superproject/+/main:frameworks/base/core/java/android/view/View.java;l=19612
    
    If you do something like:
    
        new View(myContext).Post(() => {
            // do something
        });
    
    If the `View` is never added to the `Window` (`IsAttachedToWindow` is
    false), the `Runnable` will never be executed, with data stored in
    this dictionary:
    
        static Dictionary<Action, RunnableImplementor> instances = new Dictionary<Action, RunnableImplementor> ();
    
    This is a problem if the `Action`:
    
    * Is an instance method, will cause the `Action.Target` to live forever
    
    * Is an anonymous method with captured variables, will cause the
      captured variables to live forever
    
    I could observe this behavior in a MAUI unit test that:
    
    * Creates a `ListView`
    
    * Creates the platform view that implements `ListView`
    
    * Never adds any of these objects to the `Window`
    
    * Makes sure none of the things leak -- *this fails*
    
    This seems less likely to occur in a real application, but it is still
    a bug.
    jonathanpeppers committed Apr 24, 2024
    Configuration menu
    Copy the full SHA
    d7a07e7 View commit details
    Browse the repository at this point in the history