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] Dispose of the RunnableImplementor on error #8907

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions src/Mono.Android/Android.OS/Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,52 @@ public Handler (Action<Message> handler)

public bool Post (Action action)
{
return Post (new Java.Lang.Thread.RunnableImplementor (action, true));
var runnable = new Java.Lang.Thread.RunnableImplementor (action, removable: true);
if (Post (runnable)) {
return true;
}
runnable.Dispose ();
return false;
}

public bool PostAtFrontOfQueue (Action action)
{
return PostAtFrontOfQueue (new Java.Lang.Thread.RunnableImplementor (action, true));
var runnable = new Java.Lang.Thread.RunnableImplementor (action, removable: true);
if (PostAtFrontOfQueue (runnable)) {
return true;
}
runnable.Dispose ();
return false;
}

public bool PostAtTime (Action action, long uptimeMillis)
{
return PostAtTime (new Java.Lang.Thread.RunnableImplementor (action, true), uptimeMillis);
var runnable = new Java.Lang.Thread.RunnableImplementor (action, removable: true);
if (PostAtTime (runnable, uptimeMillis)) {
return true;
}
runnable.Dispose ();
return false;
}

public bool PostAtTime (Action action, Java.Lang.Object token, long uptimeMillis)
{
return PostAtTime (new Java.Lang.Thread.RunnableImplementor (action, true), token, uptimeMillis);
var runnable = new Java.Lang.Thread.RunnableImplementor (action, removable: true);
if (PostAtTime (runnable, token, uptimeMillis)) {
return true;
}
runnable.Dispose ();
return false;
}

public bool PostDelayed (Action action, long delayMillis)
{
return PostDelayed (new Java.Lang.Thread.RunnableImplementor (action, true), delayMillis);
var runnable = new Java.Lang.Thread.RunnableImplementor (action, removable: true);
if (PostDelayed (runnable, delayMillis)) {
return true;
}
runnable.Dispose ();
return false;
}

public void RemoveCallbacks (Action action)
Expand Down
14 changes: 12 additions & 2 deletions src/Mono.Android/Android.Views/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,22 @@ public T RequireViewById<

public bool Post (Action action)
{
return Post (new Java.Lang.Thread.RunnableImplementor (action, true));
var runnable = new Java.Lang.Thread.RunnableImplementor (action, removable: true);
if (Post (runnable)) {
return true;
}
runnable.Dispose ();
return false;
}

public bool PostDelayed (Action action, long delayMillis)
{
return PostDelayed (new Java.Lang.Thread.RunnableImplementor (action, true), delayMillis);
var runnable = new Java.Lang.Thread.RunnableImplementor (action, removable: true);
if (PostDelayed (runnable, delayMillis)) {
return true;
}
runnable.Dispose ();
return false;
}

public bool RemoveCallbacks (Action action)
Expand Down
Loading