File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed
Microsoft.Toolkit.Mvvm/Messaging Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,13 @@ public sealed class WeakReferenceMessenger : IMessenger
61
61
/// </summary>
62
62
public WeakReferenceMessenger ( )
63
63
{
64
+ // Proxy function for the GC callback. This needs to be static and to take the target instance as
65
+ // an input parameter in order to avoid rooting it from the Gen2GcCallback object invoking it.
66
+ static void Gen2GcCallbackProxy ( object target )
67
+ {
68
+ ( ( WeakReferenceMessenger ) target ) . CleanupWithNonBlockingLock ( ) ;
69
+ }
70
+
64
71
// Register an automatic GC callback to trigger a non-blocking cleanup. This will ensure that the
65
72
// current messenger instance is trimmed and without leftover recipient maps that are no longer used.
66
73
// This is necessary (as in, some form of cleanup, either explicit or automatic like in this case)
@@ -69,7 +76,7 @@ public WeakReferenceMessenger()
69
76
// mapping to each conditional table for a pair of message and token types) to potentially remain in the
70
77
// root mapping structure but without any remaining recipients actually registered there, which just
71
78
// adds unnecessary overhead when trying to enumerate recipients during broadcasting operations later on.
72
- Gen2GcCallback . Register ( static obj => ( ( WeakReferenceMessenger ) obj ) . CleanupWithNonBlockingLock ( ) , this ) ;
79
+ Gen2GcCallback . Register ( Gen2GcCallbackProxy , this ) ;
73
80
}
74
81
75
82
/// <summary>
You can’t perform that action at this time.
0 commit comments